import{a as e,l as t}from"./preact.module-CNakwbc9.js";import{d as n,l as r,t as i}from"./hooks.module-BrXTvcfS.js";import{U as a,a as o,k as s}from"./i18n-BaLR3UdQ.js";import{t as c}from"./jsxRuntime.module-Cao1NCKs.js";import{D as l,X as u,f as d,j as f}from"./hooks-ClTXKdUl.js";import{t as p}from"./ActionButton-DqIfNt93.js";import{n as m}from"./resizer-CYyI_eKA.js";import{n as h}from"./split_editor_mode-DCMayfDL.js";import{t as g}from"./Badge-B9svkCt1.js";import{n as _}from"./Admonition-C4vnc1XO.js";import{n as v,r as y}from"./Code-Czz_43hv.js";n(),t();function b({note:t,noteContext:n,error:o,previewStale:s,splitOptions:u,previewContent:p,previewButtons:g,className:_,editorBefore:b,forceOrientation:S,forceReadOnly:C,editorContent:T,extraContent:E,...D}){let O=i(null),k=w(S),[A]=f(t,`displayMode`),j=d(t,n)||!!C,M=h(A,j),N=i(M!==`preview`),P=i(M!==`source`);M!==`preview`&&(N.current=!0),M!==`source`&&(P.current=!0);let F=N.current&&!j,I=l(F?null:t),L=i(D.onContentChanged);r(()=>{L.current=D.onContentChanged}),r(()=>{!F&&I&&L.current?.(I.content??``)},[I,F]);let R=N.current&&c(`div`,{className:`note-detail-split-editor-col`,children:[b,c(`div`,{className:`note-detail-split-editor`,children:T??(j?c(y,{note:t,noteContext:n,...D}):c(v,{note:t,noteContext:n,lineWrapping:!1,updateInterval:750,debounceUpdate:!0,noBackgroundChange:!0,...D}))}),E]}),z=P.current&&c(x,{error:o,previewStale:s,previewContent:p,previewButtons:g});return r(()=>{if(M!==`split`||!a.isDesktop()||!O.current)return;let e=m(Array.from(O.current.children),{rtl:glob.isRtl,sizes:[50,50],direction:k,gutterSize:5,...u});return()=>e.destroy()},[k,M]),c(`div`,{ref:O,className:`note-detail-split note-detail-printable ${M===`source`?`split-source-only`:M===`preview`?`split-read-only`:`split-${k}`} ${_??``}`,children:k===`horizontal`?c(e,{children:[R,z]}):c(e,{children:[z,R]})})}function x({error:e,previewStale:t,previewContent:n,previewButtons:r}){let{summary:i,details:a}=e?S(e):{};return c(`div`,{className:`note-detail-split-preview-col`,children:[c(`div`,{className:`note-detail-split-preview ${e?`on-error`:``}`,children:n}),e&&c(_,{className:`note-detail-error-card`,type:`caution`,icon:`bx bx-error-circle`,title:o(`split_editor.render_error`),detailsLabel:o(`split_editor.show_details`),details:a&&c(`pre`,{children:a}),children:c(`div`,{className:`note-detail-error-message`,children:i})}),e&&t&&c(g,{className:`note-detail-error-stale-badge`,icon:`bx bx-history`,text:o(`split_editor.last_valid_render`)}),c(`div`,{className:`btn-group btn-group-sm map-type-switcher content-floating-buttons preview-buttons bottom-right`,role:`group`,children:r})]})}function S(e){let t=e.trim(),n=t.indexOf(`
`);return n<0?{summary:t}:{summary:t.slice(0,n).trim(),details:t.slice(n+1).trim()||void 0}}function C(e){return c(p,{...e,className:`tn-tool-button`,noIconActionClass:!0,titlePosition:`top`})}function w(e){let[t]=u(`splitEditorOrientation`);return e||(s()?`vertical`:t||`horizontal`)}export{b as n,C as t};