import{r as i,j as e,l as q,a1 as F,M as H,G as L,N as R,a2 as J,V as D,a3 as T,q as K,a4 as G}from"./index-DTC0Ed21.js";import{N as Q,_ as V,f as Z,E as v,i as $,r as P,k as O,z as U,I as X,q as W,s as Y,x as ee,y as te,a as se,d as ae}from"./TaskPanel-DL-lNNa-.js";import{g as ie,v as le}from"./layers.B6AgvWr7-Bq9IA4iY.js";import"./tasks-ClycqzjK.js";import"./IconUser-Bh9n--nN.js";import"./tasks-R9G1-k7v.js";import"./IconChevronLeft-DwnMQlxZ.js";import"./use-resize-observer-B2T5TxF-.js";import"./useTaskTypesData-DEDxUwkB.js";import"./PillsInput-BQBRVlfT.js";import"./SegmentedControl-CI2D3wRP.js";import"./get-base-value-JqT_q0U7.js";import"./ColorSwatch-DyLoUEeW.js";import"./TypographyStylesProvider-B4wTcLh8.js";import"./clamp-Bw9v46PI.js";import"./IconGripVertical-A4WphpSm.js";import"./Accordion-BmslGzqa.js";const ne=({isCloseModal:t,setCloseModalOpen:n,confirmClose:o})=>{const{t:r}=q();return e.jsx(F,{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(R,{variant:"default",onClick:()=>{n(!1)},fullWidth:!0,children:r("editor.unsavedChanges.cancel")}),e.jsx(R,{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}=q();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 W(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(G,{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]=Q(),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(U,C,O),a.registerCommand(P,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]),_=(s,c,h)=>a.update(()=>{const N=v(t);W(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:z={},appState:A={}}=i.useMemo(()=>JSON.parse(n),[n]),I=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]),B=i.useCallback(()=>{g.current?p(!0):I()},[]);return e.jsxs(e.Fragment,{children:[e.jsx(ne,{isCloseModal:E,confirmClose:I,setCloseModalOpen:p}),e.jsx(ie,{initialElements:j,isEdited:g,initialFiles:z,initialAppState:A,isShown:w,onDelete:k,onClose:B,onSave:(s,c,h)=>{_(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:z,appState:A,width:o,height:r,editor:a,nodeKey:t,alignment:d,setModalOpen:u})})]})}export{Ee as default};
