import{k as e,y as t}from"./utils-BakkG8Vx.js";import{d as n,m as r,t as i,y as a}from"./hooks.module-5xe-uC6c.js";import{t as o}from"./jsxRuntime.module--xb8gfv5.js";import{G as s,T as c,c as l,x as u}from"./hooks-CSTgmcXO.js";import{t as d}from"./ActionButton-CbWZL7Kr.js";import{n as f}from"./resizer-CeDm6w98.js";import{t as p}from"./Admonition-J_fzSnDf.js";import{n as m,r as h}from"./Code-CFHLPUmJ.js";n();function g({note:t,noteContext:n,error:s,splitOptions:d,previewContent:g,previewButtons:v,className:b,editorBefore:x,forceOrientation:S,extraContent:C,...w}){let T=i(null),E=y(S),[D]=c(t,`displayMode`),O=l(t,n),k=D===`source`||D===`split`||D===`preview`?D:O?`preview`:`split`,A=i(k!==`preview`),j=i(k!==`source`);k!==`preview`&&(A.current=!0),k!==`source`&&(j.current=!0);let M=A.current&&!O,N=u(M?null:t),P=i(w.onContentChanged);r(()=>{P.current=w.onContentChanged}),r(()=>{!M&&N&&P.current?.(N.content??``)},[N,M]);let F=A.current&&o(`div`,{className:`note-detail-split-editor-col`,children:[x,o(`div`,{className:`note-detail-split-editor`,children:O?o(h,{note:t,noteContext:n,...w}):o(m,{note:t,noteContext:n,lineWrapping:!1,updateInterval:750,debounceUpdate:!0,noBackgroundChange:!0,...w})}),s&&o(p,{type:`caution`,className:`note-detail-error-container`,children:s}),C]}),I=j.current&&o(_,{error:s,previewContent:g,previewButtons:v});return r(()=>{if(k!==`split`||!e.isDesktop()||!T.current)return;let t=f(Array.from(T.current.children),{rtl:glob.isRtl,sizes:[50,50],direction:E,gutterSize:5,...d});return()=>t.destroy()},[E,k]),o(`div`,{ref:T,className:`note-detail-split note-detail-printable ${k===`source`?`split-source-only`:k===`preview`?`split-read-only`:`split-${E}`} ${b??``}`,children:E===`horizontal`?o(a,{children:[F,I]}):o(a,{children:[I,F]})})}function _({error:e,previewContent:t,previewButtons:n}){return o(`div`,{className:`note-detail-split-preview-col`,children:[o(`div`,{className:`note-detail-split-preview ${e?`on-error`:``}`,children:t}),o(`div`,{className:`btn-group btn-group-sm map-type-switcher content-floating-buttons preview-buttons bottom-right`,role:`group`,children:n})]})}function v(e){return o(d,{...e,className:`tn-tool-button`,noIconActionClass:!0,titlePosition:`top`})}function y(e){let[n]=s(`splitEditorOrientation`);return e||(t()?`vertical`:n||`horizontal`)}export{g as n,v as t};