import{r as i,j as e,u as K,N as q,n as H,F as J,B as I,O as G,x as T,Q as D,A as F,R as Q}from"./index-26FXPGkN.js";import{L as V,T as Y,l as $,_ as v,h as P,i as U,I as A,F as X,a as Z,b as B,s as ee,x as te,S as se,c as L,d as ae,e as ie}from"./TaskPanel-1n1xV0vy.js";import{q as le,m as ne}from"./layers.YoByaZrc-DQ8FBM0v.js";import"./tasks-BMVBejH2.js";import"./index-DlWqcwmX.js";import"./IconUser-CkQmhwMi.js";import"./Textarea-C8aNW3Hx.js";import"./get-env-uyVen0u2.js";import"./IconChevronLeft-FAloe5QL.js";import"./use-resize-observer-6Qm_8hWl.js";import"./useTaskTypesData-CFzDcAWE.js";import"./ColorSwatch-CtoYH4Cn.js";import"./Typography-PKUzf06x.js";import"./clamp-CUTWWzXs.js";import"./Select-C1WMqk5R.js";import"./SegmentedControl-BeEuUkOb.js";import"./IconGripVertical-COCN8Vqa.js";import"./IconAt-Bca7mi74.js";import"./IconTableOff-DmQNoB2C.js";import"./Accordion-z2XcZ0M6.js";const re=({isCloseModal:t,setCloseModalOpen:n,confirmClose:o})=>{const{t:r}=K();return e.jsx(q,{opened:t,onClose:()=>{n(!1)},centered:!0,title:r("editor.unsavedChanges.title"),closeOnClickOutside:!0,closeOnEscape:!0,size:"500",zIndex:999,children:e.jsxs("div",{children:[e.jsx(H,{mb:"md",children:r("editor.unsavedChanges.message")}),e.jsxs(J,{justify:"flex-end",gap:"sm",children:[e.jsx(I,{variant:"default",onClick:()=>{n(!1)},fullWidth:!0,children:r("editor.unsavedChanges.cancel")}),e.jsx(I,{color:"red",onClick:o,fullWidth:!0,children:r("editor.unsavedChanges.closeWithoutSaving")})]})]})})},oe=t=>{var n;const o=(n=t==null?void 0:t.firstElementChild)==null?void 0:n.firstElementChild,r=t.getAttribute("viewBox");if(r!=null){const d=r.split(" ");t.setAttribute("width",d[2]),t.setAttribute("height",d[3])}o&&o.tagName==="style"&&o.remove()};function de({elements:t,files:n,imageContainerRef:o,appState:r,editor:d,rootClassName:a=null,width:b="inherit",height:w="inherit",nodeKey:u,alignment:O,setModalOpen:f}){const[S,E]=i.useState(null),[g,m]=i.useState(!1);G();const{t:h}=K();i.useEffect(()=>{(async()=>{const l=await ne({appState:r,elements:t,files:n});oe(l),l.setAttribute("width","100%"),l.setAttribute("height","100%"),l.setAttribute("display","block"),l.classList.add("excalidraw-svg"),E(l)})()},[t,n,r]);const x=(l,C)=>{d.update(()=>{ae(null);const k=v(u);return B(k)&&k.setWidthAndHeight(l,C),!0})},y=l=>{ie(d,u)};return e.jsx(ee,{editor:d,isIcon:!1,isEmbed:!0,width:L(b),height:L(w),onResizeEnd:x,alignment:O,children:e.jsxs(T,{className:"media-wrapper excaildraw",children:[e.jsxs("div",{className:"media-actions",children:[e.jsx(D,{label:h("editor.link.edit"),children:e.jsx(F,{color:"gray","aria-label":"Settings",className:"media-action",variant:"default",size:24,onClick:()=>{f(!0)},children:e.jsx(Q,{size:14})})}),e.jsx(te,{opened:g,setOpened:m,t:h,editor:d,nodeKey:u}),e.jsx(D,{label:h("editor.actions.delete"),children:e.jsx(F,{color:"gray","aria-label":"Settings",className:"media-action",variant:"default",size:24,onClick:y,children:e.jsx(se,{name:"trash",size:"14"})})})]}),e.jsx(T,{w:"100%",ref:l=>{l&&o&&(o.current=l)},className:a??"",dangerouslySetInnerHTML:{__html:(S==null?void 0:S.outerHTML)??""}})]})})}function Ne({nodeKey:t,data:n,width:o,height:r,alignment:d}){const[a]=V(),b=Y(),[w,u]=i.useState(n==="[]"&&a.isEditable()),[O,f]=i.useState(!1),S=i.useRef(null),E=i.useRef(null),g=i.useRef(null),[m,h,x]=$(t),[y,l]=i.useState(!1),C=i.useCallback(s=>(m&&(s.preventDefault(),a.update(()=>{const c=v(t);c&&c.remove()})),!1),[a,m,t]);i.useEffect(()=>{if(!b){m&&x();return}return P(a.registerCommand(Z,s=>{const c=E.current,p=s.target;return y?!0:c!==null&&c.contains(p)?(s.shiftKey||x(),h(!m),s.detail>1&&u(!0),!0):!1},A),a.registerCommand(X,C,A),a.registerCommand(U,C,A))},[x,a,m,y,C,h,b]);const k=i.useCallback(()=>(u(!1),a.update(()=>{const s=v(t);s&&s.remove()})),[a,t]),W=(s,c,p)=>a.update(()=>{const M=v(t);B(M)&&(s&&s.length>0||Object.keys(p).length>0?M.setData(JSON.stringify({appState:c,elements:s,files:p})):M.remove())}),{elements:j=[],files:N={},appState:z={}}=i.useMemo(()=>JSON.parse(n),[n]),R=i.useCallback(()=>{u(!1),f(!1),g.current=!1,j.length===0&&a.update(()=>{const s=v(t);s&&s.remove()})},[a,t,j.length]),_=i.useCallback(()=>{g.current?f(!0):R()},[]);return e.jsxs(e.Fragment,{children:[e.jsx(re,{isCloseModal:O,confirmClose:R,setCloseModalOpen:f}),e.jsx(le,{initialElements:j,isEdited:g,initialFiles:N,initialAppState:z,isShown:w,onDelete:k,onClose:_,onSave:(s,c,p)=>{W(s,c,p),u(!1)},closeOnClickOutside:!1}),j.length>0&&e.jsx("div",{style:{display:"flex",justifyContent:d},children:e.jsx(de,{imageContainerRef:S,className:"image",elements:j,files:N,appState:z,width:o,height:r,editor:a,nodeKey:t,alignment:d,setModalOpen:u})})]})}export{Ne as default};
