import{r as i,j as e,b as W,R as _,q as H,F as L,B as I,U as J,C as D,V as T,A as K,W as Q}from"./index-n-59FgrC.js";import{N as U,_ as V,f as Z,E as v,i as $,r as G,k as O,z as P,I as X,q,s as Y,x as ee,y as te,a as se,d as ae}from"./TaskPanel-FSBo9x0f.js";import{g as ie,v as le}from"./layers.B6AgvWr7-CmrKHMSF.js";import"./useTaskTypesData-CgG6u01U.js";import"./IconUser-BvK8eLe8.js";import"./tasks-CZQGFm5u.js";import"./get-env-uyVen0u2.js";import"./IconChevronLeft-CyT72r93.js";import"./use-resize-observer-Bh8oaK16.js";import"./SegmentedControl-D05EYfFd.js";import"./SimpleGrid-DzebcIbT.js";import"./get-base-value-JqT_q0U7.js";import"./TypographyStylesProvider-D2Jq4B6Y.js";import"./clamp--03mf-JJ.js";import"./IconSortDescending-DCVZ-bvF.js";import"./IconGripVertical-Ce_4nROx.js";import"./Accordion-DVbX6gPb.js";const ne=({isCloseModal:t,setCloseModalOpen:n,confirmClose:o})=>{const{t:r}=W();return e.jsx(_,{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(L,{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")})]})]})})},re=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 oe({elements:t,files:n,imageContainerRef:o,appState:r,editor:d,rootClassName:a=null,width:b="inherit",height:w="inherit",nodeKey:u,alignment:E,setModalOpen:p}){const[y,M]=i.useState(null),[g,m]=i.useState(!1);J();const{t:f}=W();i.useEffect(()=>{(async()=>{const l=await le({appState:r,elements:t,files:n});re(l),l.setAttribute("width","100%"),l.setAttribute("height","100%"),l.setAttribute("display","block"),l.classList.add("excalidraw-svg"),M(l)})()},[t,n,r]);const x=(l,C)=>{d.update(()=>{se(null);const k=v(u);return q(k)&&k.setWidthAndHeight(l,C),!0})},S=l=>{ae(d,u)};return e.jsx(Y,{editor:d,isIcon:!1,isEmbed:!0,width:b,height:w,onResizeEnd:x,alignment:E,children:e.jsxs(D,{className:"media-wrapper excaildraw",children:[e.jsxs("div",{className:"media-actions",children:[e.jsx(T,{label:f("editor.link.edit"),children:e.jsx(K,{color:"gray","aria-label":"Settings",className:"media-action",variant:"default",size:24,onClick:()=>{p(!0)},children:e.jsx(Q,{size:14})})}),e.jsx(ee,{opened:g,setOpened:m,t:f,editor:d,nodeKey:u}),e.jsx(T,{label:f("editor.actions.delete"),children:e.jsx(K,{color:"gray","aria-label":"Settings",className:"media-action",variant:"default",size:24,onClick:S,children:e.jsx(te,{name:"trash",size:"14"})})})]}),e.jsx(D,{w:"100%",ref:l=>{l&&o&&(o.current=l)},className:a??"",dangerouslySetInnerHTML:{__html:(y==null?void 0:y.outerHTML)??""}})]})})}function Ee({nodeKey:t,data:n,width:o,height:r,alignment:d}){const[a]=U(),b=V(),[w,u]=i.useState(n==="[]"&&a.isEditable()),[E,p]=i.useState(!1),y=i.useRef(null),M=i.useRef(null),g=i.useRef(null),[m,f,x]=Z(t),[S,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 $(a.registerCommand(X,s=>{const c=M.current,h=s.target;return S?!0:c!==null&&c.contains(h)?(s.shiftKey||x(),f(!m),s.detail>1&&u(!0),!0):!1},O),a.registerCommand(P,C,O),a.registerCommand(G,C,O))},[x,a,m,S,C,f,b]);const k=i.useCallback(()=>(u(!1),a.update(()=>{const s=v(t);s&&s.remove()})),[a,t]),B=(s,c,h)=>a.update(()=>{const N=v(t);q(N)&&(s&&s.length>0||Object.keys(h).length>0?N.setData(JSON.stringify({appState:c,elements:s,files:h})):N.remove())}),{elements:j=[],files:A={},appState:z={}}=i.useMemo(()=>JSON.parse(n),[n]),R=i.useCallback(()=>{u(!1),p(!1),g.current=!1,j.length===0&&a.update(()=>{const s=v(t);s&&s.remove()})},[a,t,j.length]),F=i.useCallback(()=>{g.current?p(!0):R()},[]);return e.jsxs(e.Fragment,{children:[e.jsx(ne,{isCloseModal:E,confirmClose:R,setCloseModalOpen:p}),e.jsx(ie,{initialElements:j,isEdited:g,initialFiles:A,initialAppState:z,isShown:w,onDelete:k,onClose:F,onSave:(s,c,h)=>{B(s,c,h),u(!1)},closeOnClickOutside:!1}),j.length>0&&e.jsx("div",{style:{display:"flex",justifyContent:d},children:e.jsx(oe,{imageContainerRef:y,className:"image",elements:j,files:A,appState:z,width:o,height:r,editor:a,nodeKey:t,alignment:d,setModalOpen:u})})]})}export{Ee as default};
