1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[59970],{8586:(e,t,r)=>{r.d(t,{BY:()=>eZ,AD:()=>tr,bR:()=>te,KT:()=>e7,D:()=>tt,wO:()=>e6});var n=r(78542),a=r(18558),s=r(13946),l=r(72409),o=r(50453),i=r(96307),c=r(91216),d=r(5431),u=r(4203),h=r(67811),m=r(18434),x=r(81551),p=r(60890),f=r(18022),g=r(18154),b=r(4854),v=r(21026),w=r(4143),j=r(17672),y=r(66393),N=r(83838),_=r(36982),E=r(34086),k=r(62958),C=r(38458),S=r(91978),D=r(29292),A=r(62949),L=r(89318),I=r(92700),R=r(93222),P=r(83042),T=r(59725);r(46411);var M=r(4308),z=r(16956),U=r(75971),B=r(72842),F=r(92919),O=r(34298),W=r(7808),H=r(40570),G=r(36987),V=r(73511),X=r(47358),$=r(18906),Y=r(26835),K=r(63505),q=r(32904),Z=r(40018),Q=r(99870),J=r(73305),ee=r(93431),et=r(42061),er=r(6875),en=r(68989),ea=r(76788),es=r(40711),el=r(56884),eo=r(9003),ei=r(93609),ec=r(206),ed=r(61390),eu=r(2391),eh=r(61019),em=r(7614),ex=r(10313),ep=r(92857),ef=r(95935),eg=r(92888),eb=r(14905),ev=r(7481),ew=r(30230),ej=r(17215),ey=r(34556),eN=r(19549),e_=r(9398),eE=r(61983),ek=r(27496),eC=r(21856),eS=r(64951),eD=r(12081),eA=r(99998),eL=r(53232),eI=r(29798),eR=r(23652),eP=r(2863),eT=r(17807);function eM(e){let{editor:t,saveState:r="idle",onSave:s,onDiscard:i,fileName:c="document",hideActions:d=!1,isBubbleMenu:u=!1,isFloatingMenu:h=!1,hasChanges:m=!1,sandboxId:x,projectId:p}=e,[f,g]=(0,a.useState)(!1),[b,v]=(0,a.useState)(!1),[w,j]=(0,a.useState)(""),[y,N]=(0,a.useState)(null),[_,E]=(0,a.useState)(null),[k,C]=(0,a.useState)(!1),S=(0,a.useRef)(null),{ensureSandboxActive:D}=(0,eP.TW)({projectId:p,sandboxId:x,onActivating:()=>{G.o.info("Starting your computerâ¦")},onError:e=>{G.o.error("Couldn't start your computer â please try again.")}}),A=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.can().undo()}}),L=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.can().redo()}}),I=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("bold")}}),R=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("italic")}}),P=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("underline")}}),T=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("strike")}}),M=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("code")}}),z=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("bulletList")}}),U=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("orderedList")}}),eM=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("taskList")}}),ez=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("blockquote")}}),eU=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("codeBlock")}}),eB=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("link")}}),eF=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return!!t&&t.isActive("table")}}),eO=(0,o.er)({editor:t,selector:e=>{let{editor:t}=e;return t?t.isActive("heading",{level:1})?"Heading 1":t.isActive("heading",{level:2})?"Heading 2":t.isActive("heading",{level:3})?"Heading 3":"Normal":"Normal"}}),eW=(0,o.er)({editor:t,selector:e=>{var t;let{editor:r}=e;return r&&(null==(t=r.storage.characterCount)?void 0:t.words())||0}}),eH=(0,a.useCallback)(async e=>{if(t){g(!0);try{let r=t.getHTML();await (0,eR.U)({content:r,fileName:c.replace(/\.(md|markdown)$/i,""),format:e}),(0,eT.$A)({format:e})}catch(e){console.error("Export error:",e)}finally{g(!1)}}},[t,c]),eG=e=>{let{onClick:t,isActive:r=!1,disabled:a=!1,icon:s,tooltip:o,shortcut:i}=e;return(0,n.jsxs)(Y.m_,{children:[(0,n.jsx)(Y.k$,{asChild:!0,children:(0,n.jsx)(B.$,{onClick:t,disabled:a,variant:"ghost",size:"sm",className:(0,l.cn)("h-8 w-8 p-0",r&&"bg-accent text-accent-foreground"),children:(0,n.jsx)(s,{className:"h-4 w-4"})})}),(0,n.jsxs)(Y.ZI,{side:"bottom",className:"flex items-center gap-2",children:[(0,n.jsx)("span",{children:o}),i&&(0,n.jsx)("kbd",{className:"px-1.5 py-0.5 text-[10px] bg-muted rounded font-mono",children:i})]})]})},eV=(0,a.useCallback)(()=>{let e=t.getAttributes("link").href,r=window.prompt("Enter URL:",e);if(null!==r){if(""===r)return void t.chain().focus().extendMarkRange("link").unsetLink().run();t.chain().focus().extendMarkRange("link").setLink({href:r}).run()}},[t]),eX=(0,a.useCallback)(()=>{j(""),N(null),E(null),v(!0)},[]),e$=(0,a.useCallback)(e=>{var t;let r=null==(t=e.target.files)?void 0:t[0];if(r&&r.type.startsWith("image/")){E(r),j("");let e=new FileReader;e.onload=e=>{var t;N(null==(t=e.target)?void 0:t.result)}
1,e.readAsDataURL(r)}},[]),eY=(0,a.useCallback)(async e=>{if(!x)return G.o.error("No sandbox available for upload. Using base64 instead."),null;let t="https://api.rationalgo.ai/v1",r=async()=>{let r=await (0,H.getAccessTokenAsync)();if(!r)throw Error("Authentication required for upload");let n="/workspace/uploads/".concat(e.name),a=new FormData;a.append("file",e,e.name),a.append("path",n);let s=await fetch("".concat(t,"/sandboxes/").concat(x,"/files"),{method:"POST",headers:{Authorization:"Bearer ".concat(r)},body:a});if(!s.ok)throw Error("Upload failed: ".concat(s.statusText));let l=(await s.json()).path||n,o="".concat(t,"/sandboxes/").concat(x,"/files/content?path=").concat(encodeURIComponent(l)),i=await fetch(o,{headers:{Authorization:"Bearer ".concat(r)}});if(!i.ok)throw Error("Failed to fetch uploaded image: ".concat(i.statusText));let c=await i.blob(),d=URL.createObjectURL(c);return console.log("Image uploaded and blob URL created:",d),d};try{return await r()}catch(e){if((0,eP.pU)(e)&&p&&(console.log("[MarkdownToolbar] Sandbox stopped, attempting activation for upload..."),await D())){await new Promise(e=>setTimeout(e,eP.pp));try{return await r()}catch(e){console.error("[MarkdownToolbar] Upload retry failed:",e)}}return console.error("[MarkdownToolbar] Image upload error:",e),G.o.error("Failed to upload image"),null}},[x,p,D]),eK=(0,a.useCallback)(async()=>{if(_&&x){C(!0);try{let e=await eY(_);e?(t.chain().focus().setImage({src:e}).run(),v(!1),j(""),N(null),E(null),G.o.success("Image uploaded and inserted")):y&&(t.chain().focus().setImage({src:y}).run(),v(!1),j(""),N(null),E(null))}finally{C(!1)}}else w?(t.chain().focus().setImage({src:w}).run(),v(!1),j(""),N(null),E(null)):y&&!x&&(t.chain().focus().setImage({src:y}).run(),v(!1),j(""),N(null),E(null))},[t,w,y,_,x,eY]),eq=(0,a.useCallback)(()=>{t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},[t]),eZ=(0,a.useCallback)(()=>{t.chain().focus().addRowBefore().run()},[t]),eQ=(0,a.useCallback)(()=>{t.chain().focus().addRowAfter().run()},[t]),eJ=(0,a.useCallback)(()=>{t.chain().focus().addColumnBefore().run()},[t]),e0=(0,a.useCallback)(()=>{t.chain().focus().addColumnAfter().run()},[t]),e1=(0,a.useCallback)(()=>{t.chain().focus().deleteRow().run()},[t]),e2=(0,a.useCallback)(()=>{t.chain().focus().deleteColumn().run()},[t]),e5=(0,a.useCallback)(()=>{t.chain().focus().deleteTable().run()},[t]),e4=(0,n.jsxs)(n.Fragment,{children:[!u&&!h&&!d&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,n.jsx)(()=>{if(!s)return null;switch(r){case"saving":return(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",disabled:!0,className:"gap-1.5 h-8 px-2",children:[(0,n.jsx)(eI.RgoLoader,{customSize:26}),(0,n.jsx)("span",{className:"text-xs",children:"Saving"})]});case"saved":return(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",disabled:!0,className:"gap-1.5 h-8 px-2 text-green-600",children:[(0,n.jsx)(K.default,{className:"h-4 w-4"}),(0,n.jsx)("span",{className:"text-xs",children:"Saved"})]});case"error":return(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",onClick:s,className:"gap-1.5 h-8 px-2 text-red-500 hover:bg-red-50 hover:text-red-600",children:[(0,n.jsx)(q.default,{className:"h-4 w-4"}),(0,n.jsx)("span",{className:"text-xs",children:"Retry"})]});default:return(0,n.jsxs)(Y.m_,{children:[(0,n.jsx)(Y.k$,{asChild:!0,children:(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",onClick:s,disabled:!m,className:"gap-1.5 h-8 px-2",children:[(0,n.jsx)(Z.default,{className:"h-4 w-4"}),(0,n.jsx)("span",{className:"text-xs",children:"Save"})]})}),(0,n.jsx)(Y.ZI,{side:"bottom",children:m?(0,n.jsxs)(n.Fragment,{children:["Save changes ",(0,n.jsx)("kbd",{className:"ml-1.5 px-1 py-0.5 text-[10px] bg-muted rounded font-mono",children:"âS"})]}):"No changes to save"})]})}},{}),m&&i&&(0,n.jsxs)(Y.m_,{children:[(0,n.jsx)(Y.k$,{asChild:!0,children:(0,n.jsx)(B.$,{variant:"ghost",size:"sm",onClick:i,className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",children:(0,n.jsx)(Q.default,{className:"h-4 w-4"})})}),(0,n.jsx)(Y.ZI,{side:"bottom",children:"Discard changes"})]})]}),(0,n.jsx)(F.w,{orientation:"vertical",className:"h-6 mx-1 shrink-0"})]}),!u&&!h&&m&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-amber-600 dar
1k:text-amber-500 px-2 py-1 bg-amber-50 dark:bg-amber-900/20 rounded-md shrink-0",children:[(0,n.jsxs)("span",{className:"relative flex h-2 w-2",children:[(0,n.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),(0,n.jsx)("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-amber-500"})]}),(0,n.jsx)("span",{className:"font-semibold",children:"Unsaved"})]}),(0,n.jsx)(F.w,{orientation:"vertical",className:"h-6 mx-1 shrink-0"})]}),!u&&!h&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center shrink-0",children:[(0,n.jsx)(eG,{onClick:()=>t.chain().focus().undo().run(),disabled:!A,icon:J.default,tooltip:"Undo",shortcut:"âZ"}),(0,n.jsx)(eG,{onClick:()=>t.chain().focus().redo().run(),disabled:!L,icon:ee.default,tooltip:"Redo",shortcut:"ââ§Z"})]}),(0,n.jsx)(F.w,{orientation:"vertical",className:"h-6 mx-1 shrink-0"})]}),!u&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(V.rI,{children:[(0,n.jsx)(V.ty,{asChild:!0,children:(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",className:"gap-1 h-8 px-2 min-w-[70px] justify-between shrink-0",children:[(0,n.jsx)("span",{className:"text-xs truncate",children:eO}),(0,n.jsx)(et.default,{className:"h-3 w-3 opacity-50 shrink-0"})]})}),(0,n.jsxs)(V.SQ,{align:"start",className:"w-40",children:[(0,n.jsxs)(V._2,{onClick:()=>t.chain().focus().setParagraph().run(),children:[(0,n.jsx)(er.default,{className:"mr-2 h-4 w-4"}),"Normal"]}),(0,n.jsx)(V.mB,{}),(0,n.jsxs)(V._2,{onClick:()=>t.chain().focus().toggleHeading({level:1}).run(),children:[(0,n.jsx)(en.default,{className:"mr-2 h-4 w-4"}),"Heading 1"]}),(0,n.jsxs)(V._2,{onClick:()=>t.chain().focus().toggleHeading({level:2}).run(),children:[(0,n.jsx)(ea.default,{className:"mr-2 h-4 w-4"}),"Heading 2"]}),(0,n.jsxs)(V._2,{onClick:()=>t.chain().focus().toggleHeading({level:3}).run(),children:[(0,n.jsx)(es.default,{className:"mr-2 h-4 w-4"}),"Heading 3"]})]})]}),(0,n.jsx)(F.w,{orientation:"vertical",className:"h-6 mx-1 shrink-0"})]}),(0,n.jsxs)("div",{className:"flex items-center shrink-0",children:[(0,n.jsx)(eG,{onClick:()=>t.chain().focus().toggleBold().run(),isActive:I,icon:el.default,tooltip:"Bold",shortcut:"âB"}),(0,n.jsx)(eG,{onClick:()=>t.chain().focus().toggleItalic().run(),isActive:R,icon:eo.default,tooltip:"Italic",shortcut:"âI"}),(0,n.jsx)(eG,{onClick:()=>t.chain().focus().toggleUnderline().run(),isActive:P,icon:ei.default,tooltip:"Underline",shortcut:"âU"}),!u&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(eG,{onClick:()=>t.chain().focus().toggleStrike().run(),isActive:T,icon:ec.default,tooltip:"Strikethrough"}),(0,n.jsx)(eG,{onClick:()=>t.chain().focus().toggleCode().run(),isActive:M,icon:ed.default,tooltip:"Inline Code"})]})]}),!u&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(F.w,{orientation:"vertical",className:"h-6 mx-1 shrink-0"}),(0,n.jsxs)("div",{className:"flex items-center shrink-0",children:[(0,n.jsx)(eG,{onClick:()=>t.chain().focus().toggleBulletList().run(),isActive:z,icon:eu.default,tooltip:"Bullet List"}),(0,n.jsx)(eG,{onClick:()=>t.chain().focus().toggleOrderedList().run(),isActive:U,icon:eh.default,tooltip:"Numbered List"}),(0,n.jsx)(eG,{onClick:()=>t.chain().focus().toggleTaskList().run(),isActive:eM,icon:em.default,tooltip:"Task List"})]})]}),!u&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(F.w,{orientation:"vertical",className:"h-6 mx-1 shrink-0"}),(0,n.jsxs)("div",{className:"flex items-center shrink-0",children:[(0,n.jsx)(eG,{onClick:()=>t.chain().focus().toggleBlockquote().run(),isActive:ez,icon:ex.default,tooltip:"Quote"}),(0,n.jsx)(eG,{onClick:()=>t.chain().focus().toggleCodeBlock().run(),isActive:eU,icon:ed.default,tooltip:"Code Block"}),(0,n.jsx)(eG,{onClick:()=>t.chain().focus().setHorizontalRule().run(),icon:ep.default,tooltip:"Divider"})]})]}),!u&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(F.w,{orientation:"vertical",className:"h-6 mx-1 shrink-0"}),(0,n.jsxs)("div",{className:"flex items-center shrink-0",children:[(0,n.jsx)(eG,{onClick:eV,isActive:eB,icon:ef.default,tooltip:"Link",shortcut:"âK"}),(0,n.jsx)(eG,{onClick:eX,icon:eg.default,tooltip:"Image"}),(0,n.jsx)(eG,{onClick:eq,icon:eb.default,tooltip:"Table"})]})]}),!u&&!h&&eF&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(F.w,{orientation:"vertical",className:"h-6 mx-1 shrink-0"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0 bg-muted/50 rounded-md px-1 py-0.5",children:[(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-medium px-1",children:"Table"}),(0,n.jsxs)(V.rI,{children:[(0,n.jsx)(V.ty,{asChild:!0,children:(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",className:"h-7 px-1.5 gap-1",children:[(0,n.jsx)(ev.default,{className:"h-3.5 w-3.5"}),(0,n.jsx)(et.default,{className:"h-3 w-3 opacity-50"})]})}),(0,n.jsxs)(V.SQ,{align:"start",className:"w-40",children:[(0,n.jsxs)(V._2,{onClick:eZ,children:[(0,n.jsx)(ew.default,{className:"mr-2 h-4 w-4"}),"Add row above"]}),(0,n.jsxs)(V._2,{onClick:eQ,children:[(0,n.jsx)(ej.default,{className:"mr-2 h-4 w-4"}),"Add row below"]}),(0,n.jsx)(V.mB,{}),(0,n.jsxs)(V._2,{onClick:e1,className:"text-destructive focus:text-destructive hover:text-destructive hover:bg-destructive/10",children:[(0,n.jsx)(ey.default,{className:"mr-2 h-4 w-4"}),"Delete row"]})]})]}),(0,n.jsxs)(V.rI,{children:[(0,n.jsx)(V.ty,{asChild:!0,children:(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",className:"h-7 px-1.5 gap-1",children:[(0,n.jsx)(eN.default,{className:"h-3.5 w-3.5"}),(0,n.jsx)(et.default,{className:"h-3 w-3 opacity-50"})]})}),(0,n.jsxs)(V.SQ,{align:"start",className:"w-40",children:[(0,n.jsxs)(V._2,{onClick:eJ,children:[(0,n.jsx)(e_.default,{className:"mr-2 h-4 w-4"}),"Add column left"]}),(0,n.jsxs)(V._2,{onClick:e0,children:[(0,n.jsx)(eE.default,{className:"mr-2 h-4 w-4"}),"Add column right"]}),(0,n.jsx)(V.mB,{}),(0,n.jsxs)(V._2,{onClick:e2,className:"text-destructive focus:text-destructive hover:text-destructive hover:bg-destructive/10",children:[(0,n.jsx)(ey.default,{className:"mr-2 h-4 w-4"}),"Delete column"]})]})]}),(0,n.jsxs)(Y.m_,{children:[(0,n.jsx)(Y.k$,{asChild:!0,children:(0,n.jsx)(B.$,{variant:"ghost",size:"sm",onClick:e5,className:"h-7 w-7 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:(0,n.jsx)(ey.default,{className:"h-3.5 w-3.5"})})}),(0,n.jsx)(Y.ZI,{side:"bottom",children:"Delete table"})]})]})]}),!u&&!h&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1.5 shrink-0",children:[(0,n.jsxs)("span",{className:"hidden md:inline text-xs text-muted-foreground tabular-nums",children:[eW," words"]}),!d&&(0,n.jsxs)(V.rI,{children:[(0,n.jsx)(V.ty,{asChild:!0,children:(0,n.jsx)(B.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",disabled:f,children:f?(0,n.jsx)(eI.RgoLoader,{customSize:26}):(0,n.jsx)(ek.default,{className:"h-4 w-4"})})}),(0,n.jsxs)(V.SQ,{align:"end",children:[(0,n.jsxs)(V._2,{onClick:()=>eH("pdf"),children:[(0,n.jsx)(eC.default,{className:"h-4 w-4 text-muted-foreground"}),"PDF"]}),(0,n.jsxs)(V._2,{onClick:()=>eH("docx"),children:[(0,n.jsx)(eS.default,{className:"h-4 w-4 text-muted-foreground"}),"Word"]}),(0,n.jsxs)(V._2,{onClick:()=>eH("html"),children:[(0,n.jsx)(eD.default,{className:"h-4 w-4 text-muted-foreground"}),"HTML"]}),(0,n.jsxs)(V._2,{onClick:()=>eH("markdown"),children:[(0,n.jsx)(eD.default,{className:"h-4 w-4 text-muted-foreground"}),"Markdown"]})]})]})]})]}),e3=(0,n.jsx)(X.lG,{open:b,onOpenChange:v,children:(0,n.jsxs)(X.Cf,{className:"sm:max-w-md p-0 gap-0",children:[(0,n.jsx)(X.c7,{className:"px-4 pt-4 pb-3 border-b border-border",children:(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)("div",{className:"h-8 w-8 rounded-lg bg-muted border border-border flex items-center justify-center",children:(0,n.jsx)(eg.default,{className:"h-4 w-4 text-muted-foreground"})}),(0,n.jsxs)("div",{children:[(0,n.jsx)(X.L3,{className:"text-base font-medium",children:"Insert Image"}),(0,n.jsx)(X.rr,{className:"text-xs mt-0.5",children:"Upload an image or paste a URL"})]})]})}),(0,n.jsxs)($.tU,{defaultValue:"url",className:"w-full p-4",children:[(0,n.jsxs)($.j7,{className:"grid w-full grid-cols-2",children:[(0,n.jsxs)($.Xi,{value:"upload",className:"gap-1.5 opacity-50 cursor-not-allowed",disabled:!0,children:[(0,n.jsx)(eA.default,{className:"h-4 w-4"}),"Upload",(0,n.jsx)("span",{className:"text-[10px] ml-1",children:"(Soon)"})]}),(0,n.jsxs)($.Xi,{value:"url",className:"gap-1.5",children:[(0,n.jsx)(eL.default,{className:"h-4 w-4"}),"URL"]})]}),(0,n.jsx)($.av,{value:"upload",className:"space-y-4 pt-4",children:(0,n.jsxs)("div",{className:(0,l.cn)("border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors","hover:border-primary hover:bg-muted/50",y&&"border-primary bg-muted/50"),onClick:()=>{var e;return null==(e=S.current)?void 0:e.click()},children:[(0,n.jsx)("input",{ref:S,type:"file",accept:"image/*",className:"hidden",onChange:e$}),y?(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsx)("img",{src:y,alt:"Preview",className:"max-h-40 mx-auto rounded-lg object-contain"}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:"Click to change image"}),x&&(0,n.jsx)("p",{className:"text-xs text-green-600 dark:text-green-400",children:"Will be uploaded to workspace"})]}):(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)(eA.default,{className:"h-8 w-8 mx-auto text-muted-foreground"}),(0,n.jsx)("p",{className:"text-sm font-medium",children:"Click to upload an image"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground",children:"PNG, JPG, GIF up to 50MB"}),x&&(0,n.jsx)("p",{className:"text-xs text-green-600 dark:text-green-400",children:"Image will be uploaded to workspace"})]})]})}),(0,n.jsxs)($.av,{value:"url",className:"space-y-4 pt-4",children:[(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)(W.J,{htmlFor:"image-url",children:"Image URL"}),(0,n.jsx)(O.p,{id:"image-url",placeholder:"https://example.com/image.png",value:w,onChange:e=>{j(e.target.value),N(null)}})]}),w&&(0,n.jsx)("div",{className:"border rounded-lg p-2",children:(0,n.jsx)("img",{src:w,alt:"Preview",className:"max-h-40 mx-auto rounded object-contain",onError:e=>{e.target.style.display="none"}})})]})]}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 px-4 py-3 border-t border-border bg-muted/30",children:[(0,n.jsx)(B.$,{variant:"outline",size:"sm",onClick:()=>v(!1),disabled:k,children:"Cancel"}),(0,n.jsxs)(B.$,{size:"sm",onClick:eK,disabled:!w&&!y||k,className:"gap-1.5",children:[k&&(0,n.jsx)(eI.RgoLoader,{customSize:22}),k?"Uploading...":"Insert"]})]})]})});return u||h?(0,n.jsx)(Y.Bc,{delayDuration:300,children:(0,n.jsx)("div",{className:"flex items-center gap-1",children:e4})}):(0,n.jsxs)(Y.Bc,{delayDuration:300,children:[(0,n.jsx)("div",{className:"border-b bg-background sticky top-0 z-10",children:(0,n.jsx)("div",{className:"px-2 py-1.5 flex items-center gap-0.5 overflow-x-auto scrollbar-none",children:e4})}),e3]})}var ez=r(43835);M.xI.setOptions({gfm:!0,breaks:!0});let eU=new z.A({headingStyle:"atx",hr:"---",bulletListMarker:"-",codeBlockStyle:"fenced",fence:"```",emDelimiter:"*",strongDelimiter:"**",linkStyle:"inlined"});
1function eB(e){let{content:t,originalContent:r,hasUnsavedChanges:s,onUnsavedChange:z,onChange:U,onSave:B,onDiscard:F,readOnly:O=!1,className:W,placeholder:H="Start writing...",showToolbar:G=!0,fileName:V="document",hideToolbarActions:X=!1,onEditorReady:$,sandboxId:Y,projectId:K}=e,[q,Z]=(0,a.useState)("idle"),[Q,J]=(0,a.useState)(null),ee=(0,a.useRef)(null!=r?r:t),et=(0,a.useRef)(null),[er,en]=(0,a.useState)(!1),ea=(0,a.useRef)(!0),es=(0,a.useRef)(null),el=(0,a.useRef)(z);el.current=z;let eo=(0,a.useRef)(er);(0,a.useEffect)(()=>{if(eo.current!==er){var e;eo.current=er,null==(e=el.current)||e.call(el,er)}},[er]);let ei=(0,a.useMemo)(()=>{if(null!==et.current)return et.current;try{let e=M.xI.parse(t||"",{async:!1});return et.current=e,e}catch(e){return console.error("Failed to parse markdown:",e),et.current="<p>".concat(t,"</p>"),et.current}},[t]),ec=(0,a.useCallback)(e=>{try{return eU.turndown(e)}catch(e){return console.error("Failed to convert HTML to markdown:",e),""}},[]);(0,a.useEffect)(()=>{void 0!==r&&(ee.current=r)},[r]);let ed=(0,a.useCallback)(async()=>{if(!B||!Q)return;let e=ec(Q.getHTML());if(e!==ee.current)try{Z("saving"),await B(e),ee.current=e,es.current=e,en(!1),Z("saved"),setTimeout(()=>Z("idle"),2e3)}catch(e){console.error("Save error:",e),Z("error"),setTimeout(()=>Z("idle"),3e3)}},[B,Q,ec]),eu=(0,a.useCallback)(()=>{if(!Q)return;let e=M.xI.parse(ee.current||"",{async:!1});Q.commands.setContent(e),es.current=ec(e),en(!1),U&&U(ee.current),F&&F()},[Q,U,F,ec]),eh=(0,a.useMemo)(()=>[p.A,g.A.extend({addAttributes(){var e;return{...null==(e=this.parent)?void 0:e.call(this),class:{default:"text-foreground leading-relaxed my-4 first:mt-0 last:mb-0"}}}}),b.A,c.A.configure({document:!1,paragraph:!1,text:!1,heading:!1,bulletList:!1,orderedList:!1,listItem:!1,blockquote:!1,
1codeBlock:!1,horizontalRule:!1,hardBreak:!1,strike:!1}),d.Rg.extend({addAttributes(){var e;return{...null==(e=this.parent)?void 0:e.call(this),class:{default:"my-4 ml-6 list-disc space-y-2 first:mt-0 last:mb-0"}}}}),d._J.extend({addAttributes(){var e;return{...null==(e=this.parent)?void 0:e.call(this),class:{default:"my-4 ml-6 list-decimal space-y-2 first:mt-0 last:mb-0"}}}}),d.ck.extend({addAttributes(){var e;return{...null==(e=this.parent)?void 0:e.call(this),class:{default:"text-foreground leading-relaxed pl-1"}}}}),u.A,h.A.configure({nested:!0}),m.Ay.configure({HTMLAttributes:{class:"my-5 pl-4 py-1 border-l-2 border-border text-muted-foreground"}}),x.Ay.configure({HTMLAttributes:{class:"my-5 p-4 rounded-xl overflow-x-auto bg-zinc-100 dark:bg-zinc-900 border border-zinc-200 dark:border-zinc-800 text-[13px] font-mono leading-relaxed text-zinc-800 dark:text-zinc-200"}}),f.A,v.A.configure({levels:[1,2,3,4,5,6]}),w.A.configure({HTMLAttributes:{class:"my-8 border-0 h-px bg-border/60"}}),j.Ay.configure({inline:!0,allowBase64:!0,HTMLAttributes:{class:"max-w-full h-auto rounded-xl border border-border/40 shadow-sm my-5"}}),y.R0.configure({table:{resizable:!0,HTMLAttributes:{class:"w-full text-sm my-5 rounded-xl border border-border/60 overflow-hidden"}},tableHeader:{HTMLAttributes:{class:"px-4 py-3 text-left text-xs font-semibold text-foreground uppercase tracking-wider bg-muted/50 dark:bg-muted/30"}},tableCell:{HTMLAttributes:{class:"px-4 py-3 text-foreground border-t border-border/40"}}}),N.A,P.Ay,_.Ay.configure({openOnClick:!1,autolink:!0,defaultProtocol:"https",HTMLAttributes:{class:"font-medium text-foreground underline decoration-foreground/30 underline-offset-[3px] decoration-[1px] hover:decoration-foreground/60 transition-colors duration-150"}}),E.xJ,k.Q,C.Ay.configure({multicolor:!0}),S.A.configure({types:["heading","paragraph"],alignments:["left","center","right"]}),D.A.configure({placeholder:H,showOnlyWhenEditable:!0}),A.A,L.A.configure({color:"var(--primary)",width:2}),I.A,R.Ay,T.Rs],[H]),em=(0,o.hG)({extensions:eh,content:ei,editable:!O,immediatelyRender:!1,onCreate(e){let{editor:t}=e;J(t),es.current=ec(t.getHTML()),ea.current=!1,en(!1)},onUpdate(e){let{editor:t,transaction:r}=e;J(t);let n=ec(t.getHTML());ea.current||null===es.current||en(n!==es.current),U&&U(n)},editorProps:{attributes:{class:(0,l.cn)("focus:outline-none min-h-[200px]"),spellcheck:"true"},handleDrop:(e,t,r,n)=>{if(!n&&t.dataTransfer&&t.dataTransfer.files.length>0){let r=t.dataTransfer.files[0];if(r.type.startsWith("image/")){let n=new FileReader;return n.onload=r=>{var n;let a=null==(n=r.target)?void 0:n.result,{schema:s}=e.state,l=e.posAtCoords({left:t.clientX,top:t.clientY});if(l){let t=s.nodes.image.create({src:a}),r=e.state.tr.insert(l.pos,t);e.dispatch(r)}},n.readAsDataURL(r),!0}}return!1}}});return((0,a.useEffect)(()=>{if(em&&!er){let e=M.xI.parse(t||"",{async:!1});e!==em.getHTML()&&em.commands.setContent(e)}},[t,em,er]),(0,a.useEffect)(()=>{em&&em.setEditable(!O)},[O,em]),(0,a.useEffect)(()=>{if(!em||O)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),ed())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[em,O,ed]),(0,a.useEffect)(()=>{$&&(Q?$({getHtml:()=>Q.getHTML(),save:ed,saveState:q,hasChanges:er}):$(null))},[Q,ed,q,er,$]),O)?(0,n.jsx)("div",{className:(0,l.cn)("flex flex-col h-full overflow-hidden bg-background",W),children:(0,n.jsx)("div",{className:"flex-1 overflow-auto p-6",children:(0,n.jsx)(ez.C,{content:t})})}):(0,n.jsxs)("div",{className:(0,l.cn)("flex flex-col h-full overflow-hidden bg-background",W),children:[G&&Q&&(0,n.jsx)(eM,{editor:Q,saveState:q,onSave:ed,onDiscard:eu,fileName:V,hideActions:X,hasChanges:er,sandboxId:Y,projectId:K}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("div",{className:"mx-auto px-6 pb-12 max-w-4xl",children:[em&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(i.m,{editor:em,shouldShow:e=>{let{editor:t,view:r,state:n,oldState:a,from:s,to:l}=e,{selection:o}=n;return o&&!o.empty&&o.from!==o.to},children:(0,n.jsx)("div",{className:"flex items-center gap-1 bg-background border border-border rounded-lg shadow-lg p-1",children:(0,n.jsx)(eM,{editor:em,saveState:q,onSave:ed,fileName:V,hideActions:!0,isBubbleMenu:!0,sandboxId:Y,projectId:K})})}),(0,n.jsx)(i.y,{editor:em,shouldShow:e=>{let{editor:t,view:r,state:n,oldState:a,from:s,to:l}=e,{selection:o}=n,{$anchor:i}=o,c=1===i.depth;
1return 0===t.state.doc.content.size&&c},children:(0,n.jsx)("div",{className:"flex items-center gap-1 bg-background border border-border rounded-lg shadow-lg p-1",children:(0,n.jsx)(eM,{editor:em,saveState:q,onSave:ed,fileName:V,hideActions:!0,isFloatingMenu:!0,sandboxId:Y,projectId:K})})})]}),(0,n.jsx)("style",{dangerouslySetInnerHTML:{__html:'\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n RGO TIPTAP EDITOR STYLES\n Matches UnifiedMarkdown for consistent rendering\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n \n /* Headings - Clean hierarchy with proper weight */\n .tiptap-editor h1 {\n font-size: 1.5rem;\n line-height: 2rem;\n font-weight: 600;\n letter-spacing: -0.025em;\n color: var(--foreground);\n margin-top: 2rem;\n margin-bottom: 1rem;\n padding-bottom: 0.5rem;\n border-bottom: 1px solid color-mix(in srgb, var(--border) 40%, transparent);\n }\n .tiptap-editor h1:first-child { margin-top: 0; }\n \n .tiptap-editor h2 {\n font-size: 1.25rem;\n line-height: 1.75rem;\n font-weight: 600;\n letter-spacing: -0.025em;\n color: var(--foreground);\n margin-top: 2rem;\n margin-bottom: 0.75rem;\n }\n .tiptap-editor h2:first-child { margin-top: 0; }\n \n .tiptap-editor h3 {\n font-size: 1.125rem;\n line-height: 1.75rem;\n font-weight: 600;\n color: var(--foreground);\n margin-top: 1.5rem;\n margin-bottom: 0.5rem;\n }\n .tiptap-editor h3:first-child { margin-top: 0; }\n \n .tiptap-editor h4 {\n font-size: 1rem;\n line-height: 1.5rem;\n font-weight: 600;\n color: var(--foreground);\n margin-top: 1.25rem;\n margin-bottom: 0.5rem;\n }\n .tiptap-editor h4:first-child { margin-top: 0; }\n \n .tiptap-editor h5 {\n font-size: 0.875rem;\n line-height: 1.25rem;\n font-weight: 600;\n color: var(--foreground);\n margin-top: 1rem;\n margin-bottom: 0.25rem;\n }\n .tiptap-editor h5:first-child { margin-top: 0; }\n \n .tiptap-editor h6 {\n font-size: 0.875rem;\n line-height: 1.25rem;\n font-weight: 500;\n color: var(--muted-foreground);\n text-transform: uppercase;\n letter-spacing: 0.05em;\n margin-top: 1rem;\n margin-bottom: 0.25rem;\n }\n .tiptap-editor h6:first-child { margin-top: 0; }\n \n /* Text formatting */\n .tiptap-editor strong {\n font-weight: 600;\n color: var(--foreground);\n }\n .tiptap-editor em {\n font-style: italic;\n color: color-mix(in srgb, var(--foreground) 90%, transparent);\n }\n .tiptap-editor del {\n text-decoration: line-through;\n color: var(--muted-foreground);\n text-decoration-color: color-mix(in srgb, var(--muted-foreground) 50%, transparent);\n }\n \n /* Inline code - subtle pill style */\n .tiptap-editor code {\n padding: 0.125rem 0.375rem;\n border-radius: 0.375rem;\n font-size: 13px;\n font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;\n background-color: var(--muted);\n color: var(--foreground);\n }\n \n /* Pre block - code container (light mode default) */\n .tiptap-editor pre {\n background-color: #f4f4f5;\n color: #27272a;\n border-radius: 0.75rem;\n padding: 1rem;\n margin-top: 1.25rem;\n margin-bottom: 1.25rem;\n overflow-x: auto;\n font-size: 13px;\n line-height: 1.625;\n font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;\n border: 1px solid #e4e4e7;\n }\n .dark .tiptap-editor pre {\n background-color: #18181b;\n color: #e4e4e7;\n border-color: #27272a;\n }\n .tiptap-editor pre code {\n background-color: transparent;\n color: inherit;\n padding: 0;\n border-radius: 0;\n font-size: inherit;\n }\n \n /* Placeholder styling */\n .tiptap-editor .is-editor-empty:first-child::before {\n color: color-mix(in srgb, var(--muted-foreground) 50%, transparent);\n content: attr(data-placeholder);\n float: left;\n height: 0;\n pointer-events: none;\n }\n \n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n TASK LIST STYLES - Checkbox and text on same line\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n .tiptap-editor ul[data-type="taskList"] {\n list-style: none;\n padding-left: 0;\n margin: 1rem 0;\n }
1\n .tiptap-editor ul[data-type="taskList"] li {\n display: flex;\n align-items: flex-start;\n gap: 0.5rem;\n margin: 0.25rem 0;\n }\n .tiptap-editor ul[data-type="taskList"] li > label {\n flex-shrink: 0;\n margin-top: 0.125rem;\n user-select: none;\n }\n .tiptap-editor ul[data-type="taskList"] li > label input[type="checkbox"] {\n width: 1rem;\n height: 1rem;\n cursor: pointer;\n accent-color: var(--primary);\n }\n .tiptap-editor ul[data-type="taskList"] li > div {\n flex: 1;\n min-width: 0;\n }\n .tiptap-editor ul[data-type="taskList"] li > div > p {\n margin: 0;\n }\n /* Nested task lists */\n .tiptap-editor ul[data-type="taskList"] ul[data-type="taskList"] {\n margin: 0.25rem 0 0.25rem 1.5rem;\n }\n \n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n TABLE STYLES - Clean, minimal table editing\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n .tiptap-editor table {\n border-collapse: collapse;\n width: 100%;\n margin: 1.5rem 0;\n border-radius: 0.5rem;\n overflow: hidden;\n border: 1px solid var(--border);\n }\n .tiptap-editor th,\n .tiptap-editor td {\n border: 1px solid var(--border);\n padding: 0.5rem 0.75rem;\n text-align: left;\n vertical-align: top;\n position: relative;\n min-width: 80px;\n }\n .tiptap-editor th {\n background-color: color-mix(in srgb, var(--muted) 50%, transparent);\n font-weight: 600;\n font-size: 0.875rem;\n }\n .tiptap-editor td {\n background-color: transparent;\n }\n /* Selected cell highlight */\n .tiptap-editor .selectedCell {\n background-color: color-mix(in srgb, var(--primary) 10%, transparent) !important;\n }\n .tiptap-editor .selectedCell::after {\n content: "";\n position: absolute;\n inset: 0;\n border: 2px solid var(--primary);\n pointer-events: none;\n }\n /* Column resize handle */\n .tiptap-editor .column-resize-handle {\n position: absolute;\n right: -2px;\n top: 0;\n bottom: 0;\n width: 4px;\n background-color: var(--primary);\n cursor: col-resize;\n opacity: 0;\n transition: opacity 0.15s;\n }\n .tiptap-editor th:hover .column-resize-handle,\n .tiptap-editor td:hover .column-resize-handle {\n opacity: 1;\n }\n /* Table wrapper for horizontal scroll */\n .tiptap-editor .tableWrapper {\n overflow-x: auto;\n margin: 1.5rem 0;\n }\n '}}),(0,n.jsx)("div",{className:"tiptap-editor pt-6",children:(0,n.jsx)(o.$Z,{editor:em,className:"min-h-[300px]"})})]})})]})}eU.use(U.Te),eU.addRule("fencedCodeBlock",{filter:e=>"PRE"===e.nodeName&&e.firstChild&&"CODE"===e.firstChild.nodeName,replacement:(e,t)=>{let r=t.firstChild,n=(r.getAttribute("class")||"").match(/language-(\w+)/),a=n?n[1]:"",s=r.textContent||"";return"\n```".concat(a,"\n").concat(s,"\n```\n")}});var eF=r(8566),eO=r(14536),eW=r(42346),eH=r(26467),eG=r(28732),eV=r(45317),eX=r(58061),e$=r(77475);let eY=eH.cg,eK=e=>{try{let t=eY[e];if(t&&"function"==typeof t){let e=t();if(e)return e}return null}catch(t){return console.error('[CodeEditor] Error loading language extension "'.concat(e,'":'),t),null}},eq={js:()=>eK("javascript"),javascript:()=>eK("javascript"),jsx:()=>eK("jsx"),ts:()=>eK("typescript"),typescript:()=>eK("typescript"),tsx:()=>eK("tsx"),mjs:()=>eK("javascript"),cjs:()=>eK("javascript"),html:()=>eK("html"),htm:()=>eK("html"),css:()=>eK("css"),scss:()=>eK("scss"),sass:()=>eK("sass"),less:()=>eK("less"),json:()=>eK("json"),jsonc:()=>eK("json"),json5:()=>eK("json"),md:()=>eK("markdown"),markdown:()=>eK("markdown"),mdx:()=>eK("markdown"),python:()=>eK("python"),py:()=>eK("python"),pyi:()=>eK("python"),pyw:()=>eK("python"),rust:()=>eK("rust"),rs:()=>eK("rust"),go:()=>eK("go"),golang:()=>eK("go"),c:()=>eK("c"),h:()=>eK("c"),cpp:()=>eK("cpp"),cxx:()=>eK("cpp"),cc:()=>eK("cpp"),hpp:()=>eK("cpp"),hxx:()=>eK("cpp"),java:()=>eK("java"),cs:()=>eK("csharp"),csharp:()=>eK("csharp"),kotlin:()=>eK("kotlin"),kt:()=>eK("kotlin"),scala:()=>eK("scala"),php:()=>eK("php"),ruby:()=>eK("ruby"),rb:()=>eK("ruby"),rbx:()=>eK("ruby"),rjs:()=>eK("ruby"),perl:()=>eK("perl"),pl:()=>eK("perl"),pm:()=>eK("perl"),lua:()=>eK("lua"),r:()=>eK("r"),sh:()=>eK("shell"),bash:()=>eK("shell"),zsh:()=>eK("shell"),fish:()=>eK("shell"),shell:()=>eK("shell"),sql:()=>eK("sql"),yaml:()=>eK("yaml"),yml:()=>eK("yaml"),xml:()=>eK("xml"),toml:()=>eK("toml"),swift:()=>
1eK("swift"),vue:()=>eK("vue"),svelte:()=>eK("svelte"),nix:()=>eK("nix")};function eZ(e){let{content:t,originalContent:r,hasUnsavedChanges:s,onUnsavedChange:o,fileName:i,language:c,onChange:d,onSave:u,onDiscard:h,readOnly:m=!1,className:x,showLineNumbers:p=!0,compact:f=!1}=e,{resolvedTheme:g}=(0,eX.D)(),[b,v]=(0,a.useState)(!1),[w,j]=(0,a.useState)("idle"),[y,N]=(0,a.useState)(t),_=(0,a.useRef)(null!=r?r:t),E=(0,a.useRef)(null),[k,C]=(0,a.useState)("100%"),[S,D]=(0,a.useState)(!1),A=(0,a.useRef)(o);A.current=o;let L=S&&y!==_.current,I=(0,a.useRef)(!1);(0,a.useEffect)(()=>{if(I.current!==L){var e;I.current=L,null==(e=A.current)||e.call(A,L)}},[L]),(0,a.useEffect)(()=>{void 0!==r&&(_.current=r)},[r]),(0,a.useEffect)(()=>{v(!0)},[]),(0,a.useEffect)(()=>{if(m)return void C("auto");let e=()=>{if(E.current){let e=E.current.getBoundingClientRect(),t=e.height>0?e.height:400;C("".concat(t,"px"))}else C("100%")};e();let t=new ResizeObserver(e);return E.current&&t.observe(E.current),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("resize",e)}},[m]);let R=c||function(e){var t;let r=(null==(t=e.split(".").pop())?void 0:t.toLowerCase())||"",n=e.toLowerCase();return n.includes(".env")||n.startsWith(".env")||n.includes("gitignore")||n.includes("editorconfig")||n.includes("dockerignore")||n.includes("npmignore")||n.includes("prettierignore")||n.includes("eslintignore")?"text":({js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",ts:"typescript",tsx:"tsx",html:"html",htm:"html",css:"css",scss:"scss",sass:"sass",less:"less",json:"json",jsonc:"json",json5:"json",md:"markdown",markdown:"markdown",mdx:"markdown",py:"python",python:"python",pyi:"python",pyw:"python",rs:"rust",go:"go",c:"c",h:"c",cpp:"cpp",cxx:"cpp",cc:"cpp",hpp:"cpp",hxx:"cpp",java:"java",cs:"csharp",kt:"kotlin",scala:"scala",php:"php",rb:"ruby",rbx:"ruby",rjs:"ruby",pl:"perl",pm:"perl",lua:"lua",r:"r",sh:"shell",bash:"shell",zsh:"shell",fish:"shell",sql:"sql",yml:"yaml",yaml:"yaml",xml:"xml",toml:"toml",swift:"swift",vue:"vue",svelte:"svelte",nix:"nix",txt:"text",log:"text",env:"text",ini:"text",gitignore:"text",editorconfig:"text",dockerignore:"text",npmignore:"text",prettierignore:"text",eslintignore:"text"})[r]||"text"}(i),P=(0,a.useMemo)(()=>{try{if("text"===R)return[];let e=eq[R];if(!e||"function"!=typeof e)return[];let t=e();if(t)return[t];return[]}catch(e){return console.error('[CodeEditor] Failed to load language extension for "'.concat(R,'":'),e),[]}},[R]),T=(0,a.useCallback)(async()=>{if(u&&y!==_.current)try{j("saving"),await u(y),_.current=y,j("saved"),setTimeout(()=>j("idle"),2e3)}catch(e){console.error("Save error:",e),j("error"),setTimeout(()=>j("idle"),3e3)}},[u,y]),M=(0,a.useCallback)(()=>{N(_.current),d&&d(_.current),h&&h()},[d,h]),z=(0,a.useCallback)(e=>{N(e),d&&d(e)},[d]);(0,a.useEffect)(()=>{let e=m||y===_.current||!y;t!==y&&e&&(N(t),!S&&t&&(_.current=null!=r?r:t,D(!0)))},[t,y,r,S,m]);let U=(0,a.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),m||T())},[m,T]);(0,a.useEffect)(()=>(document.addEventListener("keydown",U),()=>document.removeEventListener("keydown",U)),[U]);let F=b&&"dark"===g?eO.Ts:eW._x,O=(0,a.useMemo)(()=>{let e=[];
1if(P&&P.length>0){let t=P.filter(e=>null!=e);t.length>0&&e.push(...t)}return e.push(eG.Lz.lineWrapping,eG.w4.of([eV.Yc])),e},[P]);return(0,n.jsxs)("div",{className:(0,l.cn)("flex flex-col max-w-full",m?"":"h-full max-h-full overflow-hidden",x),style:m?void 0:{contain:"strict"},children:[!m&&(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 border-b bg-muted/30 flex-shrink-0 max-w-full min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)(()=>{if(m||!u)return null;switch(w){case"saving":return(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",disabled:!0,className:"gap-1.5 h-7 px-2 text-xs",children:[(0,n.jsx)(eI.RgoLoader,{customSize:22}),(0,n.jsx)("span",{className:"hidden sm:inline",children:"Saving"})]});case"saved":return(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",disabled:!0,className:"gap-1.5 h-7 px-2 text-xs text-green-600",children:[(0,n.jsx)(K.default,{className:"h-3.5 w-3.5"}),(0,n.jsx)("span",{className:"hidden sm:inline",children:"Saved"})]});case"error":return(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",onClick:T,className:"gap-1.5 h-7 px-2 text-xs text-red-500 hover:bg-red-50 hover:text-red-600",children:[(0,n.jsx)(q.default,{className:"h-3.5 w-3.5"}),(0,n.jsx)("span",{className:"hidden sm:inline",children:"Retry"})]});default:return(0,n.jsx)(Y.Bc,{delayDuration:300,children:(0,n.jsxs)(Y.m_,{children:[(0,n.jsx)(Y.k$,{asChild:!0,children:(0,n.jsxs)(B.$,{variant:"ghost",size:"sm",onClick:T,disabled:!L,className:"gap-1.5 h-7 px-2 text-xs",children:[(0,n.jsx)(Z.default,{className:"h-3.5 w-3.5"}),(0,n.jsx)("span",{className:"hidden sm:inline",children:"Save"})]})}),(0,n.jsx)(Y.ZI,{side:"bottom",children:L?(0,n.jsxs)(n.Fragment,{children:["Save changes ",(0,n.jsx)("kbd",{className:"ml-1.5 px-1 py-0.5 text-[10px] bg-muted rounded font-mono",children:"âS"})]}):"No changes to save"})]})})}},{}),L&&(0,n.jsx)(Y.Bc,{delayDuration:300,children:(0,n.jsxs)(Y.m_,{children:[(0,n.jsx)(Y.k$,{asChild:!0,children:(0,n.jsx)(B.$,{variant:"ghost",size:"sm",onClick:M,className:"h-7 w-7 p-0 text-muted-foreground hover:text-destructive",children:(0,n.jsx)(Q.default,{className:"h-3.5 w-3.5"})})}),(0,n.jsx)(Y.ZI,{side:"bottom",children:"Discard changes"})]})}),L&&(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-amber-600 dark:text-amber-500 px-2 py-1 bg-amber-50 dark:bg-amber-900/20 rounded-md",children:[(0,n.jsxs)("span",{className:"relative flex h-2 w-2",children:[(0,n.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),(0,n.jsx)("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-amber-500"})]}),(0,n.jsx)("span",{className:"font-semibold",children:"Unsaved"})]})]}),(0,n.jsx)(e$.E,{variant:"outline",className:"text-xs font-mono",children:R})]}),(0,n.jsx)("div",{ref:E,className:(0,l.cn)("w-full max-w-full bg-white dark:bg-zinc-900",m?"overflow-visible":"flex-1 overflow-hidden min-h-0 max-h-full"),style:m?void 0:{contain:"strict"},children:b&&(0,n.jsx)(eF.Ay,{value:y,onChange:z,theme:F,extensions:O,basicSetup:{lineNumbers:p,highlightActiveLine:!m,highlightActiveLineGutter:!m,foldGutter:!0,dropCursor:!0,allowMultipleSelections:!0,indentOnInput:!0,bracketMatching:!0,closeBrackets:!0,autocompletion:!m,rectangularSelection:!0,crosshairCursor:!1,highlightSelectionMatches:!0,searchKeymap:!0,tabSize:2},editable:!m,className:(0,l.cn)("w-full max-w-full",f?"text-xs":"text-sm",m?"[&_.cm-scroller]:!overflow-visible":"[&_.cm-editor]:max-h-full [&_.cm-scroller]:overflow-auto"),height:k})})]})}var eQ=r(19497),eJ=r(79634),e0=r(54848),e1=r(27434),e2=r(82117),e5=r(25643),e4=r(84192),e3=r(34141),e8=r(2803);let e6=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e)return"";if("object"==typeof e)try{let r=JSON.stringify(e,null,2);if(t)return r;return"```json\n"+r+"\n```"}catch(t){return console.warn("Failed to stringify object:",t),String(e)}return"string"!=typeof e?String(e):e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))).replace(/\\u([0-9a-fA-F]{8})/g,(e,t)=>String.fromCharCode(parseInt(t.substring(0,4),16),parseInt(t.substring(4,8),16)))};function e7(e){var t;let r=(null==(t=e.split(".").pop())?void 0:t.toLowerCase())||"";return["md","markdown"].includes(r)?"markdown":["js","jsx","ts","tsx","html","css","json","doc","py","python","java","c","cpp","h","cs","go","rs","php","rb","sh","bash","xml","yml","yaml","toml","sql","graphql","swift","kotlin","dart","r","lua","scala","perl","haskell","rust"].includes(r)?"code":["png","jpg","jpeg","gif","webp","svg","bmp","ico"].includes(r)?"image":["pdf"].includes(r)?"pdf":["csv","tsv"].includes(r)?"csv":["xl
1sx","xls"].includes(r)?"xlsx":["pptx","ppt"].includes(r)?"pptx":["txt","log","env","ini"].includes(r)?"text":"binary"}let e9=(0,s.default)(()=>Promise.all([r.e(73386),r.e(84750),r.e(15131),r.e(91751)]).then(r.bind(r,15131)).then(e=>e.SpreadsheetViewer),{loadableGenerated:{webpack:()=>[15131]},ssr:!1,loading:()=>(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:"Loading spreadsheet..."})});function te(e){var t;let r=(null==(t=e.split(".").pop())?void 0:t.toLowerCase())||"",n=e.toLowerCase();return["md","markdown"].includes(r)?"markdown":["html","htm"].includes(r)?"html":["js","jsx","ts","tsx","css","json","py","python","java","c","cpp","h","hpp","cs","go","rs","php","rb","sh","bash","zsh","xml","yml","yaml","toml","sql","graphql","swift","kotlin","kt","dart","r","lua","scala","perl","pl","haskell","hs","rust","dockerfile","makefile","cmake"].includes(r)?"code":["txt","log","env","ini","conf","cfg","gitignore","editorconfig"].includes(r)?"text":["rgocanvas"].includes(r)?"canvas":n.includes(".env")||n.startsWith(".env")||n.includes("gitignore")||n.includes("editorconfig")||n.includes("dockerignore")||n.includes("npmignore")||n.includes("prettierignore")||n.includes("eslintignore")?"text":["png","jpg","jpeg","gif","webp","svg","bmp","ico"].includes(r)?"image":["mp4","webm","mov","avi","mkv","m4v","ogg"].includes(r)?"video":["pdf"].includes(r)?"pdf":["csv","tsv"].includes(r)?"csv":["xlsx","xls"].includes(r)?"xlsx":["pptx","ppt"].includes(r)?"pptx":["docx","doc"].includes(r)?"docx":"binary"}function tt(e){return["markdown","code","text","html","canvas"].includes(e)}function tr(e){var t,r,s,o;let{content:i,originalContent:c,hasUnsavedChanges:d,onUnsavedChange:u,binaryUrl:h,fileName:m,filePath:x,className:p,project:f,readOnly:g=!1,onChange:b,onSave:v,onDiscard:w,onDownload:j,isDownloading:y,onFullScreen:N,hideMarkdownToolbarActions:_=!1,onMarkdownEditorReady:E}=e,k=te(m),C=m.toLowerCase().endsWith(".html")||m.toLowerCase().endsWith(".htm"),S=a.useMemo(()=>{var e,t;if(C&&i&&!(null==f||null==(e=f.sandbox)?void 0:e.sandbox_url)){let e=new Blob([i],{type:"text/html"});return URL.createObjectURL(e)}if(C&&(null==f||null==(t=f.sandbox)?void 0:t.sandbox_url)&&(x||m))return(0,e8.i)(f.sandbox.sandbox_url,x||m)},[C,i,null==f||null==(t=f.sandbox)?void 0:t.sandbox_url,x,m]);a.useEffect(()=>()=>{S&&S.startsWith("blob:")&&URL.revokeObjectURL(S)},[S]);let D="binary"===k&&null!==i&&!h;return(0,n.jsx)("div",{className:(0,l.cn)("w-full h-full max-w-full max-h-full overflow-hidden min-w-0",p),style:{contain:"strict"},children:"binary"!==k||D?D?(0,n.jsx)(eZ,{content:i||"",originalContent:c,hasUnsavedChanges:d,onUnsavedChange:u,fileName:m,language:"text",onChange:b,onSave:v,onDiscard:w,readOnly:g,className:"h-full"}):"image"===k&&h?(0,n.jsx)(eJ.d,{url:h}):"video"===k&&h?(0,n.jsx)(e0.R,{url:h}):"pdf"===k&&h?(0,n.jsx)(eQ.S,{url:h}):"csv"===k||"xlsx"===k?(0,n.jsx)(e9,{filePath:x,fileName:m,sandboxId:null==f||null==(r=f.sandbox)?void 0:r.id,projectId:null==f?void 0:f.id,project:f,allowEditing:!g}):"pptx"===k?(0,n.jsx)(e2.K,{content:i,binaryUrl:h,filePath:x,fileName:m,project:f,onDownload:j,isDownloading:y,onFullScreen:N}):"docx"===k?(0,n.jsx)(e5._,{content:i,binaryUrl:h,filePath:x,fileName:m,project:f,onDownload:j,isDownloading:y,onFullScreen:N}):"canvas"===k?(0,n.jsx)(e3.K,{content:i,filePath:x,fileName:m,sandboxId:null==f||null==(s=f.sandbox)?void 0:s.id,className:"h-full w-full",onSave:v}):"html"===k&&S?(0,n.jsx)(e4.j,{content:i||"",previewUrl:S,className:"w-full h-full",project:f}):"markdown"===k?g?(0,n.jsx)("div",{className:"h-full overflow-auto p-6",children:(0,n.jsx)(ez.C,{content:i||""})}):(0,n.jsx)(eB,{content:i||"",originalContent:c,hasUnsavedChanges:d,onUnsavedChange:u,onChange:b,onSave:v,onDiscard:w,readOnly:!1,className:"h-full",fileName:m,hideToolbarActions:_,onEditorReady:E,sandboxId:null==f||null==(o=f.sandbox)?void 0:o.id,projectId:null==f?void 0:f.id}):"code"===k||"text"===k?(0,n.jsx)(eZ,{content:i||"",originalContent:c,hasUnsavedChanges:d,onUnsavedChange:u,fileName:m,onChange:b,onSave:v,onDiscard:w,readOnly:g,className:"h-full"}):(0,n.jsx)(eZ,{content:i||"",originalContent:c,hasUnsavedChanges:d,onUnsavedChange:u,fileName:m,language:"text",onCh
1ange:b,onSave:v,onDiscard:w,readOnly:g,className:"h-full"}):(0,n.jsx)(e1.h,{url:h||"",fileName:m,onDownload:j,isDownloading:y})})}},17807:(e,t,r)=>{r.d(t,{$9:()=>es,$A:()=>en,AA:()=>ev,AP:()=>O,Aq:()=>eD,CM:()=>S,Dp:()=>J,Ec:()=>E,Fg:()=>s,Fq:()=>z,GN:()=>ei,Gu:()=>Q,H2:()=>eR,Is:()=>et,Jv:()=>Y,Kw:()=>V,LF:()=>ey,Le:()=>eg,M1:()=>y,N9:()=>eA,O8:()=>c,Oc:()=>G,Om:()=>Z,PC:()=>ej,QH:()=>eu,Qc:()=>ep,Qr:()=>w,Ri:()=>ef,SC:()=>ec,SV:()=>m,Tq:()=>I,Ts:()=>eS,Tv:()=>W,V7:()=>F,VT:()=>N,Wc:()=>j,X3:()=>v,XM:()=>ee,Y:()=>ew,Y$:()=>ek,Y1:()=>l,Yt:()=>eh,_d:()=>H,ap:()=>h,b0:()=>T,e6:()=>i,e7:()=>B,eh:()=>f,fT:()=>M,fb:()=>ed,fi:()=>eN,gD:()=>er,hl:()=>eI,kp:()=>p,lE:()=>eC,lZ:()=>D,lv:()=>A,n1:()=>ex,nK:()=>eb,nt:()=>q,q1:()=>g,qY:()=>a,rN:()=>d,rd:()=>_,rg:()=>C,rs:()=>L,tF:()=>eo,tG:()=>u,tN:()=>P,tU:()=>eL,tv:()=>ea,uS:()=>x,ui:()=>e_,vJ:()=>o,vO:()=>k,vW:()=>$,vo:()=>X,wS:()=>eE,xZ:()=>R,xj:()=>em,y$:()=>b,y3:()=>K,zD:()=>U,zz:()=>el});var n=r(91631);let a={USER_SIGNED_UP:"user_signed_up",USER_LOGGED_IN:"user_logged_in",PROJECT_CREATED:"project_created",PROJECT_DELETED:"project_deleted",AGENT_RUN_STARTED:"agent_run_started",TASK_PROMPT_SUBMITTED:"task_prompt_submitted",TASK_ABANDONED:"task_abandoned",PLAN_UPGRADE_ATTEMPTED:"plan_upgrade_attempted",PLAN_UPGRADED:"plan_upgraded",PLAN_DOWNGRADED:"plan_downgraded",PLAN_DOWNGRADE_SCHEDULED:"plan_downgrade_scheduled",TRIGGER_CREATED:"trigger_created",TRIGGER_TOGGLED:"trigger_toggled",TRIGGER_DELETED:"trigger_deleted",KB_FILE_UPLOADED:"kb_file_uploaded",KB_TEXT_CREATED:"kb_text_created",KB_GIT_CLONED:"kb_git_cloned",EXPORT_GENERATED:"export_generated",FILE_DOWNLOADED:"file_downloaded",THREAD_DELETED:"thread_deleted",THREAD_SHARE_TOGGLED:"thread_share_toggled",THREAD_SHARE_COPIED:"thread_share_copied",THREAD_SHARED_SOCIAL:"thread_shared_social",TWIN_SETUP_COMPLETED:"twin_setup_completed",TWIN_ACTIVATED:"twin_activated",TWIN_DEACTIVATED:"twin_deactivated",TWIN_PAUSED:"twin_paused",TWIN_RESUMED:"twin_resumed",TWIN_PERSONA_UPDATED:"twin_persona_updated",TWIN_HEARTBEAT_CONFIGURED:"twin_heartbeat_configured",TWIN_CHANNEL_ADDED:"twin_channel_added",TWIN_CHANNEL_REMOVED:"twin_channel_removed",TWIN_SKILL_INSTALLED:"twin_skill_installed",TWIN_SKILL_UNINSTALLED:"twin_skill_uninstalled",TWIN_CRON_CREATED:"twin_cron_created",TWIN_CRON_DELETED:"twin_cron_deleted",TWIN_MEMORY_DELETED:"twin_memory_deleted",AGENT_DELETED:"agent_deleted",API_KEY_CREATED:"api_key_created",API_KEY_REVOKED:"api_key_revoked",API_KEY_DELETED:"api_key_deleted",ONBOARDING_COMPLETED:"onboarding_completed",NEW_PROJECT_CLICKED:"new_project_clicked",NEW_TASK_CLICKED:"new_task_clicked",APP_BUILDER_LANDING_VIEWED:"app_builder_landing_viewed",APP_BUILDER_MODE_SWITCHED:"app_builder_mode_switched",APP_BUILDER_STARTER_SELECTED:"app_builder_starter_selected",HERO_TAB_SWITCHED:"hero_tab_switched",APP_BUILDER_PROMPT_SUBMITTED:"app_builder_prompt_submitted",APP_BUILDER_FIRST_PREVIEW_RENDERED:"app_builder_first_preview_rendered",APP_BUILDER_PUBLISH_CLICKED:"app_builder_publish_clicked",APP_BUILDER_PUBLISH_SUCCEEDED:"app_builder_publish_succeeded",APP_BUILDER_PUBLISH_FAILED:"app_builder_publish_failed",APP_BUILDER_PUBLISH_CAP_HIT:"app_builder_publish_cap_hit",APP_BUILDER_CREDIT_EXHAUSTED:"app_builder_credit_exhausted",APP_BUILDER_UPGRADE_FROM_EXHAUSTION:"app_builder_upgrade_from_exhaustion",APP_BUILDER_GITHUB_CONNECTED:"app_builder_github_connected",APP_BUILDER_GITHUB_PUSHED:"app_builder_github_pushed",APP_BUILDER_GITHUB_PUSH_FAILED:"app_builder_github_push_failed",APP_BUILDER_QUESTION_SHOWN:"app_builder_question_shown",APP_BUILDER_QUESTION_ANSWERED:"app_builder_question_answered",APP_BUILDER_VISUAL_EDIT_CLICKED:"app_builder_visual_edit_clicked",APP_BUILDER_VISUAL_EDIT_SUBMITTED:"app_builder_visual_edit_submitted",APP_BUILDER_VERCEL_CONNECTED:"app_builder_vercel_connected",APP_BUILDER_VERCEL_DEPLOY_CLICKED:"app_builder_vercel_deploy_clicked",APP_BUILDER_VERCEL_DEPLOY_SUCCEEDED:"app_builder_vercel_deploy_succeeded",APP_BUILDER_VERCEL_DEPLOY_FAILED:"app_builder_vercel_deploy_failed",APP_BUILDER_CODE_VIEWED:"app_builder_code_viewed",APP_BUILDER_TURSO_CONNECTED:"app_builder_turso_connected",APP_BUILDER_VERSIONS_VIEWED:"app_builder_versions_viewed",APP_BUILDER_VERSION_ROLLBACK_CLICKED:"app_builder_version_rollback_clicked",APP_BUILDER_VERSION_ROLLBACK_SUCCEEDED:"app_builder_version_rollback_succeeded",APP_BUILDER_VERSION_ROLLBACK_FAILED:"app_builder_version_rollback_failed",APP_BUILDER_UNPUBLISH_CLICKED:"app_builder_unpublish_clicked",APP_BUILDER_UNPUBLISH_SUCCEEDED:"app_builder_unpublish_succeeded",APP_BUILDER_UNPUBLISH_FAILED:"app_builder_unpublish_failed",APP_BUILDER_EDIT_SETTINGS_OPENED:"app_builder_edit_settings_opened",APP_BUILDER_COMING_SOON_CLICKED:"app_builder_coming_soon_clicked",APP_BUILDER_URL_VIEW_OPENED:"app_builder_url_view_opened",APP_BUILDER_SLUG_RENAME_CLICKED:"app_builder_slug_rename_clicked",APP_BUILDER_SLUG_RENAMED:"app_builder_slug_renamed",APP_BUILDER_SLUG_RENAME_FAILED:"app_builder_slug_rename_failed",APP_BUILDER_SECURITY_FINDINGS_DETECTED:"app_builder_security_findings_detected",APP_BUILDER_LLM_HANDOFF_TRIGGERED:"app_builder_llm_handoff_triggered",AGENT_LLM_HANDOFF_TO_APP_BUILDER:"agent_llm_handoff_to_app_builder",COMPANY_INTRO_SHOWN:"c
1ompany_intro_shown",COMPANY_INTRO_ACTION:"company_intro_action",COMPANY_TAB_OPENED:"company_tab_opened",COMPANY_PLAN_ACTION:"company_plan_action",COMPANY_AWAY_ACTION:"company_away_action",CONTINUE_COMPANY_CLICKED:"continue_company_clicked",COMPANY_FIRST_BUILD_ENDED:"company_first_build_ended",COMPANY_SITE_UPDATED:"company_site_updated"};function s(e,t){try{n.Ay.capture(e,{platform:"web",...t})}catch(e){}}function l(e){s(a.NEW_TASK_CLICKED,e?{source:e}:void 0)}function o(){s(a.APP_BUILDER_LANDING_VIEWED)}function i(e,t){s(a.APP_BUILDER_MODE_SWITCHED,{to:e,from:t})}function c(e,t){s(a.APP_BUILDER_STARTER_SELECTED,{group:e,starter:t})}function d(e){s(a.APP_BUILDER_PROMPT_SUBMITTED,e)}function u(e){s(a.APP_BUILDER_FIRST_PREVIEW_RENDERED,e)}function h(e){s(a.APP_BUILDER_PUBLISH_CLICKED,e)}function m(e){s(a.APP_BUILDER_PUBLISH_SUCCEEDED,e)}function x(e){s(a.APP_BUILDER_PUBLISH_FAILED,e)}function p(e){s(a.APP_BUILDER_PUBLISH_CAP_HIT,e)}function f(e){s(a.APP_BUILDER_CREDIT_EXHAUSTED,e)}function g(e){s(a.APP_BUILDER_UPGRADE_FROM_EXHAUSTION,e)}function b(e){s(a.APP_BUILDER_LLM_HANDOFF_TRIGGERED,e)}function v(e){s(a.AGENT_LLM_HANDOFF_TO_APP_BUILDER,e)}function w(e){s(a.APP_BUILDER_GITHUB_CONNECTED,e)}function j(e){s(a.APP_BUILDER_GITHUB_PUSHED,e)}function y(e){s(a.APP_BUILDER_GITHUB_PUSH_FAILED,e)}function N(e){s(a.APP_BUILDER_QUESTION_SHOWN,e)}function _(e){s(a.APP_BUILDER_QUESTION_ANSWERED,e)}function E(e){s(a.APP_BUILDER_TURSO_CONNECTED,e)}function k(e){s(a.APP_BUILDER_VISUAL_EDIT_CLICKED,e)}function C(e){s(a.APP_BUILDER_VISUAL_EDIT_SUBMITTED,e)}function S(e){s(a.APP_BUILDER_VERCEL_CONNECTED,e)}function D(e){s(a.APP_BUILDER_VERCEL_DEPLOY_CLICKED,e)}function A(e){s(a.APP_BUILDER_VERCEL_DEPLOY_SUCCEEDED,e)}function L(e){s(a.APP_BUILDER_VERCEL_DEPLOY_FAILED,e)}function I(e){s(a.APP_BUILDER_VERSIONS_VIEWED,e)}function R(e){s(a.APP_BUILDER_VERSION_ROLLBACK_CLICKED,e)}function P(e){s(a.APP_BUILDER_VERSION_ROLLBACK_SUCCEEDED,e)}function T(e){s(a.APP_BUILDER_VERSION_ROLLBACK_FAILED,e)}function M(e){s(a.APP_BUILDER_UNPUBLISH_CLICKED,e)}function z(e){s(a.APP_BUILDER_UNPUBLISH_SUCCEEDED,e)}function U(e){s(a.APP_BUILDER_UNPUBLISH_FAILED,e)}function B(e){s(a.APP_BUILDER_EDIT_SETTINGS_OPENED,e)}function F(e){s(a.APP_BUILDER_URL_VIEW_OPENED,e)}function O(e){s(a.APP_BUILDER_SLUG_RENAME_CLICKED,e)}function W(e){s(a.APP_BUILDER_SLUG_RENAMED,e)}function H(e){s(a.APP_BUILDER_SLUG_RENAME_FAILED,e)}function G(e){s(a.APP_BUILDER_SECURITY_FINDINGS_DETECTED,e)}function V(e){s(a.TASK_PROMPT_SUBMITTED,e)}function X(e){s(a.TASK_ABANDONED,{agent_run_id:e})}function $(){s(a.PLAN_UPGRADE_ATTEMPTED)}function Y(e){s(a.PLAN_UPGRADED,e)}function K(e){s(a.PLAN_DOWNGRADED,e)}function q(){s(a.PLAN_DOWNGRADE_SCHEDULED)}function Z(e){s(a.TRIGGER_CREATED,e)}function Q(e){s(a.TRIGGER_TOGGLED,e)}function J(e){s(a.TRIGGER_DELETED,e)}function ee(e){s(a.KB_FILE_UPLOADED,e)}function et(){s(a.KB_TEXT_CREATED)}function er(){s(a.KB_GIT_CLONED)}function en(e){s(a.EXPORT_GENERATED,e)}function ea(e){s(a.FILE_DOWNLOADED,e)}function es(){s(a.THREAD_DELETED)}function el(e){s(a.THREAD_SHARE_TOGGLED,e)}function eo(){s(a.THREAD_SHARE_COPIED)}function ei(e){s(a.THREAD_SHARED_SOCIAL,e)}function ec(e){s(a.TWIN_SETUP_COMPLETED,e)}function ed(){s(a.TWIN_ACTIVATED)}function eu(){s(a.TWIN_DEACTIVATED)}function eh(){s(a.TWIN_PAUSED)}function em(){s(a.TWIN_RESUMED)}function ex(){s(a.TWIN_PERSONA_UPDATED)}function ep(e){s(a.TWIN_HEARTBEAT_CONFIGURED,e)}function ef(e){s(a.TWIN_CHANNEL_ADDED,e)}function eg(e){s(a.TWIN_CHANNEL_REMOVED,e)}function eb(e){s(a.TWIN_SKILL_INSTALLED,e)}function ev(e){s(a.TWIN_SKILL_UNINSTALLED,e)}function ew(){s(a.TWIN_CRON_CREATED)}function ej(){s(a.TWIN_CRON_DELETED)}function ey(){s(a.API_KEY_CREATED)}function eN(){s(a.API_KEY_REVOKED)}function e_(){s(a.API_KEY_DELETED)}function eE(){s(a.ONBOARDING_COMPLETED)}function ek(e){s(a.COMPANY_INTRO_SHOWN,e)}function eC(e){s(a.COMPANY_INTRO_ACTION,e)}function eS(e){s(a.COMPANY_TAB_OPENED,e)}function eD(e){s(a.COMPANY_PLAN_ACTION,e)}function eA(e){s(a.COMPANY_AWAY_ACTION,e)}function eL(e){s(a.CONTINUE_COMPANY_CLICKED,e)}function eI(e){s(a.COMPANY_FIRST_BUILD_ENDED,e)}function eR(e){s(a.COMPANY_SITE_UPDATED,e)}},18906:(e,t,r)=>{r.d(t,{Xi:()=>i,av:()=>c,j7:()=>o,tU:()=>l});var n=r(78542);r(18558);var a=r(58636),s=r(72409);function l(e){let{className:t,...r}=e;return(0,n.jsx)(a.bL,{"data-slot":"tabs",className:(0,s.cn)("flex flex-col gap-2",t),...r})}function o(e){let{className:t,...r}=e;return(0,n.jsx)(a.B8,{"data-slot":"tabs-list",className:(0,s.cn)("bg-muted text-muted-foreground inline-flex h-8 w-fit items-center justify-center rounded-xl p-0.5",t),...r})}function i(e){let{className:t,...r}=e;return(0,n.jsx)(a.l9,{"data-slot":"tabs-trigger",className:(0,s.cn)("cursor-pointer data-[state=active]:bg-card data-[state=active]:text-foreground dark:data-[state=active]:bg-card dark:data-[state=active]:text-foreground focus-visible:ring-ring focus-visible:outline-ring text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-lg border border-transparent px-2 py-0.5 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focu
1s-visible:ring-[1.5px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-[inset_0_-2px_0_var(--gold),0_1px_2px_rgba(45,41,38,0.06)] [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",t),...r})}function c(e){let{className:t,...r}=e;return(0,n.jsx)(a.UC,{"data-slot":"tabs-content",className:(0,s.cn)("flex-1 outline-none",t),...r})}},19497:(e,t,r)=>{r.d(t,{S:()=>m});var n=r(78542),a=r(18558),s=r(72409),l=r(15545),o=r(38433),i=r(31938),c=r(68580),d=r(236),u=r(24437),h=r(29798);function m(e){let{url:t,className:r,compact:l=!1}=e,[m,x]=(0,a.useState)(null),[p,f]=(0,a.useState)(1),[g,b]=(0,a.useState)(0),[v,w]=(0,a.useState)(!0),[j,y]=(0,a.useState)(null),N=(0,a.useRef)(null),_=(0,a.useRef)(null);(0,a.useEffect)(()=>{if(!N.current)return;let e=N.current,t=()=>{let t=Math.floor(e.getBoundingClientRect().width);t>0&&b(t)};t();let r=new ResizeObserver(()=>{t()});return r.observe(e),window.addEventListener("resize",t),()=>{r.disconnect(),window.removeEventListener("resize",t)}},[]);let E=(0,a.useCallback)(e=>{e>=1&&e<=(m||1)&&(f(e),_.current&&(_.current.scrollTop=0))},[m]),k=(0,a.useCallback)(()=>{E(p-1)},[p,E]),C=(0,a.useCallback)(()=>{E(p+1)},[p,E]);(0,a.useEffect)(()=>{if(l)return;let e=e=>{if(!(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement))switch(e.key){case"ArrowLeft":e.preventDefault(),k();break;case"ArrowRight":e.preventDefault(),C()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l,k,C]);let S=g>0?Math.max(g-48,100):void 0;return t?l?(0,n.jsx)("div",{ref:N,className:(0,s.cn)("w-full h-full overflow-hidden bg-muted/10",r),style:{contain:"strict"},children:(0,n.jsx)("div",{className:"flex items-center justify-center p-2 overflow-auto h-full",children:(0,n.jsx)(o.A,{file:t,loading:(0,n.jsx)("div",{className:"flex items-center justify-center h-40",children:(0,n.jsx)(h.RgoLoader,{size:"medium"})}),error:(0,n.jsx)("div",{className:"flex items-center justify-center h-40 text-sm text-muted-foreground",children:"Failed to load PDF"}),children:(0,n.jsx)(i.A,{pageNumber:1,width:S,renderTextLayer:!1,renderAnnotationLayer:!1,className:"shadow-sm rounded-lg overflow-hidden"})})})}):(0,n.jsxs)("div",{ref:N,className:(0,s.cn)("flex flex-col w-full h-full bg-muted/20 overflow-hidden",r),style:{contain:"strict"},children:[(0,n.jsx)("div",{ref:_,className:"flex-1 overflow-auto min-h-0",children:j?(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 p-8",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-full bg-destructive/10 flex items-center justify-center",children:(0,n.jsx)(c.default,{className:"h-6 w-6 text-destructive"})}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Failed to load PDF"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"The file may be corrupted or inaccessible"})]})]}):(0,n.jsx)("div",{className:"flex items-center justify-center min-h-full p-4",children:(0,n.jsx)(o.A,{file:t,onLoadSuccess:function(e){let{numPages:t}=e;x(t),w(!1),y(null)},onLoadError:function(e){console.error("PDF load error:",e),y("Failed to load PDF"),w(!1)},loading:(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-64 gap-3",children:[(0,n.jsx)(h.RgoLoader,{size:"medium"}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading PDF..."})]}),className:"flex flex-col items-center max-w-full",children:(0,n.jsx)(i.A,{pageNumber:p,width:S,renderTextLayer:!0,renderAnnotationLayer:!0,loading:(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)(h.RgoLoader,{size:"medium"})}),className:"shadow-lg rounded-lg overflow-hidden bg-white max-w-full"})})})}),m&&m>1&&(0,n.jsx)("div",{className:"flex items-center justify-center px-3 py-1.5 border-t border-hairline flex-shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:k,disabled:p<=1,title:"Previous page (â)",className:"flex h-6 w-6 items-center justify-center rounded-[6px] border border-border text-muted-foreground transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50 disabled:text-text-subtle disabled:hover:bg-transparent",children:(0,n.jsx)(d.default,{className:"h-[13px] w-[13px]",strokeWidth:2.5})}),(0,n.jsxs)("span",{className:"min-w-[56px] text-center text-[11.5px] font-semibold text-muted-foreground tabular-nums",children:[p," / ",m]}),(0,n.jsx)("button",{type:"button",onClick:C,disabled:p>=m,title:"Next page (â)",className:"flex h-6 w-6 items-center justify-center rounded-[6px] border border-border text-muted-foreground transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50 disabled:text-text-subtle disabled:hover:bg-transparent",children:(0,n.jsx)(u.default,{className:"h-[13px] w-[13px]",strokeWidth:2.5})})]})})]}):(0,n.jsx)("div",{className:(0,s.cn)("w-full h-full flex items-center justify-center bg-muted/20",r),children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:"No PDF URL provided"})})}r(68536),r(42374),l.EA.workerSrc=new r.U(r(92537)).toString()},19726:(e,t,r)=>{r.d(t,{BR:()=>c,YK:()=>d,sS:()=>u});var n=r(14333),a=r(68432),s=r(87107),l=r(88003),o=r(93434);r(36987),r(25251);var i=r(18558);let c=(e,t)=>{var r,s,c;let d=(0,n.jE)(),u=[...l.X.lists(),"paginated",1,50,"all"],h=d.getQueryData(u),m=(0,i.useMemo)(()=>{let t=(null==h?void 0:h.threads)||[];
1if(!e||!t.length)return;let r=t.find(t=>t.project_id===e&&t.project);if(!(null==r?void 0:r.project))return;let n=r.project,a=n.sandbox&&"object"==typeof n.sandbox&&n.sandbox.id;return{id:n.project_id,name:n.name||"",description:n.description||"",is_public:n.is_public||!1,created_at:n.created_at,updated_at:n.updated_at,sandbox:a?n.sandbox:{id:"",pass:"",vnc_preview:"",sandbox_url:""},icon_name:n.icon_name,metadata:n.metadata}},[e,h]);return(0,a.I)({queryKey:l.X.project(e||""),queryFn:async()=>await (0,o.U1)(e),enabled:!!e&&(null==t?void 0:t.enabled)!==!1,retry:1,initialData:(null==m||null==(r=m.sandbox)?void 0:r.id)?m:void 0,refetchOnWindowFocus:!1,refetchOnMount:null!=(s=null==t?void 0:t.refetchOnMount)&&s,staleTime:null!=(c=null==t?void 0:t.staleTime)?c:6e4,...t})},d=e=>{let{data:t,isLoading:r,isError:n,isFetching:s,error:c,refetch:d}=(0,a.I)({queryKey:[...l.X.lists(),"paginated",1,50,"all"],queryFn:()=>(0,o.getThreadsPaginated)(void 0,1,50),staleTime:3e5,gcTime:6e5,refetchOnWindowFocus:e=>"error"===e.state.status});return{data:(0,i.useMemo)(()=>{let e=(null==t?void 0:t.threads)||[];if(!e.length)return[];let r=new Map;return e.forEach(e=>{if(e.project&&e.project_id){let t=e.project;if(!r.has(t.project_id)){let e=t.sandbox&&"object"==typeof t.sandbox&&t.sandbox.id;r.set(t.project_id,{id:t.project_id,name:t.name||"",description:t.description||"",created_at:t.created_at,updated_at:t.updated_at,sandbox:e?t.sandbox:{id:"",pass:"",vnc_preview:"",sandbox_url:""},icon_name:t.icon_name,metadata:t.metadata})}}}),Array.from(r.values())},[t]),isLoading:r,error:c,isLoaded:void 0!==t,isError:n,isFetching:s,refetch:d}},u=()=>{let e=(0,n.jE)();return(0,s.n)({mutationFn:e=>{let{projectId:t,data:r}=e;return(0,o.vr)(t,r)},onSuccess:(t,r)=>{e.invalidateQueries({queryKey:l.g.lists()}),e.invalidateQueries({queryKey:l.g.details(r.projectId)}),e.invalidateQueries({queryKey:l.X.projects()}),e.invalidateQueries({queryKey:l.X.project(r.projectId)})}})}},21528:(e,t,r)=>{r.d(t,{B8:()=>f,IF:()=>c,NA:()=>d,XU:()=>p,cH:()=>h,gI:()=>m,lc:()=>o,lk:()=>u,u:()=>i,uQ:()=>l,w8:()=>x});let n=["html","htm","md","markdown","json","csv","tsv","xlsx","xls","pdf","txt"],a=["jpg","jpeg","png","gif","webp","svg","bmp","ico","heic","heif"],s=["mp4","webm","mov","avi","mkv","m4v"];function l(e){var t;return(null==(t=e.split(".").pop())?void 0:t.toLowerCase())||""}function o(e){var t;return t=l(e),n.includes(t.toLowerCase())}function i(e){var t;return t=l(e),a.includes(t.toLowerCase())}function c(e){return"json"===e.toLowerCase()}function d(e){let t=e.toLowerCase();return"md"===t||"markdown"===t}function u(e){let t=e.toLowerCase();return"html"===t||"htm"===t}function h(e){let t=e.toLowerCase();return"csv"===t||"tsv"===t}function m(e){let t=e.toLowerCase();return"xlsx"===t||"xls"===t}function x(e){return"pdf"===e.toLowerCase()}function p(e){return"txt"===e.toLowerCase()}function f(e){return s.includes(e.toLowerCase())}},23652:(e,t,r)=>{r.d(t,{U:()=>c});var n=r(36987),a=r(64573),s=r(16956),l=r(75971),o=r(40570);let i="https://api.rationalgo.ai/v1";async function c(e){let{content:t,fileName:r,format:c}=e,d="string"==typeof t&&t.trim()?t.includes("<")?t:t.split("\n").map(e=>e.trim()?"<p>".concat(e,"</p>"):"").filter(Boolean).join("\n"):"<p></p>",u=r.replace(/[^a-zA-Z0-9-_. ]/g,"").trim()||"document";console.log("[Document Export] Format: ".concat(c)),console.log("[Document Export] File name: ".concat(u)),console.log("[Document Export] Content length: ".concat((null==t?void 0:t.length)||0)),console.log("[Document Export] HTML content preview:",d.substring(0,300));try{switch(c){case"pdf":{console.log("[Document Export] Sending to backend PDF API...");let e=n.o.loading("Exporting to PDF...");try{if(!i)throw Error("Backend API URL not configured");let t=await (0,o.getAccessTokenAsync)();if(!t)throw Error("Authentication required");let r=await fetch("".concat(i,"/export/pdf"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(t)},body:JSON.stringify({content:d,fileName:u})});if(console.log("[Document Export] Backend PDF API response status:",r.status),!r.ok){let e=await r.text(),t="Export failed: ".concat(r.status);try{let r=JSON.parse(e);t=r.detail||r.error||t}catch(r){e.length<200&&(t=e)}throw Error(t)}let s=await r.blob();console.log("[Document Export] PDF blob size:",s.size,"bytes"),(0,a.saveAs)(s,"".concat(u,".pdf")),n.o.success("PDF exp
1orted",{id:e})}catch(t){console.error("[Document Export] PDF export error:",t),n.o.error("PDF export failed: ".concat(t instanceof Error?t.message:"Unknown error"),{id:e})}break}case"docx":{console.log("[Document Export] Sending to backend DOCX API...");let e=n.o.loading("Exporting to Word...");try{if(!i)throw Error("Backend API URL not configured");let t=await (0,o.getAccessTokenAsync)();if(!t)throw Error("Authentication required");let r=await fetch("".concat(i,"/export/docx"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(t)},body:JSON.stringify({content:d,fileName:u})});if(console.log("[Document Export] Backend DOCX API response status:",r.status),!r.ok){let e=await r.text(),t="Export failed: ".concat(r.status);try{let r=JSON.parse(e);t=r.detail||r.error||t}catch(r){e.length<200&&(t=e)}throw Error(t)}let s=await r.blob();console.log("[Document Export] DOCX blob size:",s.size,"bytes"),(0,a.saveAs)(s,"".concat(u,".docx")),n.o.success("Word document exported",{id:e})}catch(t){console.error("[Document Export] DOCX export error:",t),n.o.error("Word export failed: ".concat(t instanceof Error?t.message:"Unknown error"),{id:e})}break}case"html":{console.log("[Document Export] Creating HTML file...");let e='<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <title>'.concat(u,"</title>\n <style>").concat("\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n BASE RESET & DOCUMENT STYLES\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n * { \n margin: 0; \n padding: 0; \n box-sizing: border-box; \n }\n \n body { \n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n font-size: 16px;\n line-height: 1.65;\n color: #1a1a1a;\n max-width: 720px;\n margin: 0 auto;\n padding: 48px 24px;\n background: #fff;\n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n HEADINGS - Clean hierarchy matching UnifiedMarkdown\n H1: Large with bottom border (like web version)\n H2-H6: Decreasing sizes with proper margins\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n h1, h2, h3, h4, h5, h6 {\n font-weight: 600;\n line-height: 1.3;\n color: #111;\n letter-spacing: -0.02em;\n }\n \n h1 { \n font-size: 2em; \n margin: 1.5em 0 0.75em 0;\n padding-bottom: 0.4em;\n border-bottom: 1px solid #e0e0e0;\n }\n h1:first-child { margin-top: 0; }\n \n h2 { \n font-size: 1.5em; \n margin: 1.5em 0 0.6em 0;\n }\n h2:first-child { margin-top: 0; }\n \n h3 { \n font-size: 1.25em; \n margin: 1.25em 0 0.5em 0;\n }\n h3:first-child { margin-top: 0; }\n \n h4 { \n font-size: 1.1em; \n margin: 1.1em 0 0.4em 0;\n }\n h4:first-child { margin-top: 0; }\n \n h5 { \n font-size: 1em; \n margin: 1em 0 0.3em 0;\n }\n h5:first-child { margin-top: 0; }\n \n h6 { \n font-size: 0.9em; \n margin: 1em 0 0.3em 0;\n color: #555;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n }\n h6:first-child { margin-top: 0; }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n PARAGRAPHS & TEXT\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n p { \n margin: 1em 0; \n line-height: 1.7;\n }\n p:first-child { margin-top: 0; }\n p:last-child { margin-bottom: 0; }\n \n /* Text formatting */\n strong, b { font-weight: 600; }\n em, i { font-style: italic; }\n u { text-decoration: underline; }
1\n s, strike, del { \n text-decoration: line-through;\n color: #666;\n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n LINKS - Professional blue styling\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n a { \n color: #0066cc; \n text-decoration: underline;\n text-decoration-color: rgba(0, 102, 204, 0.4);\n text-underline-offset: 2px;\n }\n a:hover { \n text-decoration-color: rgba(0, 102, 204, 0.8);\n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n LISTS - Proper indentation and spacing\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n ul, ol { \n margin: 1em 0; \n padding-left: 2em; \n }\n ul:first-child, ol:first-child { margin-top: 0; }\n ul:last-child, ol:last-child { margin-bottom: 0; }\n \n li { \n margin: 0.4em 0; \n line-height: 1.6;\n }\n \n /* Nested lists */\n li > ul, li > ol { \n margin: 0.4em 0; \n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n BLOCKQUOTES - Left border with muted styling\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n blockquote { \n margin: 1.5em 0;\n padding: 0.75em 1em;\n border-left: 4px solid #e0e0e0;\n background: #fafafa;\n color: #555;\n font-style: italic;\n border-radius: 0 4px 4px 0;\n }\n blockquote p { \n margin: 0.5em 0; \n }\n blockquote p:first-child { margin-top: 0; }\n blockquote p:last-child { margin-bottom: 0; }\n blockquote:first-child { margin-top: 0; }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n CODE - Monospace with subtle background\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n /* Inline code */\n code {\n font-family: 'SF Mono', Monaco, 'Cascadia Code', Consolas, 'Courier New', monospace;\n font-size: 0.9em;\n background: #f4f4f5;\n padding: 0.15em 0.4em;\n border-radius: 4px;\n color: #1a1a1a;\n }\n \n /* Code blocks */\n pre {\n margin: 1.5em 0;\n padding: 1em;\n background: #f4f4f5;\n border: 1px solid #e4e4e7;\n border-radius: 8px;\n overflow-x: auto;\n font-size: 0.9em;\n line-height: 1.5;\n }\n pre:first-child { margin-top: 0; }\n \n pre code {\n background: none;\n padding: 0;\n border-radius: 0;\n font-size: inherit;\n color: inherit;\n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n TABLES - Clean borders with header styling\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n table { \n width: 100%;\n margin: 1.5em 0;\n border-collapse: collapse; \n font-size: 0.95em;\n }\n table:first-child { margin-top: 0; }\n \n thead {\n background: #f8f9fa;\n }\n \n th { \n padding: 0.75em 1em;\n border: 1px solid #e0e0e0;\n text-align: left;\n font-weight: 600;\n font-size: 0.85em;\n text-transform: uppercase;\n letter-spacing: 0.03em;\n color: #333;\n background: #f8f9fa;\n }\n \n td { \n padding: 0.75em 1em;\n border: 1px solid #e0e0e0;\n text-align: left;\n vertical-align: top;\n }\n \n tr:nth-child(even) td { \n background: #fafafa; \n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n HORIZONTAL RULE - Subtle divider\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n hr {\n border: none;\n border-top: 2px solid #e0e0e0;\n margin: 2em 0;\n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n IMAGES - Responsive with spacing\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n img {\n max-width: 100%;\n height: auto;\n display: block;\n margin: 1.5em 0;\n border-radius: 4px;\n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n TASK LISTS (checkboxes)\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n ul.task-list,\n ul.contains-task-list { \n list-style: none; \n padding-left: 0; \n }\n \n li.task-list-item { \n display: flex;
1 \n align-items: flex-start; \n gap: 0.5em;\n padding-left: 0;\n }\n \n li.task-list-item input { \n margin-top: 0.35em; \n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n DEFINITION LISTS\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n dl {\n margin: 1em 0;\n }\n \n dt {\n font-weight: 600;\n margin-top: 1em;\n }\n dt:first-child { margin-top: 0; }\n \n dd {\n margin-left: 1.5em;\n margin-bottom: 0.5em;\n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n KEYBOARD SHORTCUTS\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n kbd {\n font-family: 'SF Mono', Monaco, Consolas, 'Courier New', monospace;\n font-size: 0.85em;\n background: #f4f4f5;\n border: 1px solid #d0d0d0;\n border-radius: 3px;\n padding: 0.1em 0.4em;\n box-shadow: 0 1px 0 #d0d0d0;\n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n MARK / HIGHLIGHT\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n mark {\n background-color: #fef08a;\n padding: 0 0.2em;\n border-radius: 2px;\n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n FIGURE & FIGCAPTION\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n figure {\n margin: 1.5em 0;\n }\n \n figcaption {\n font-size: 0.9em;\n color: #666;\n text-align: center;\n margin-top: 0.5em;\n font-style: italic;\n }\n\n /* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n PRINT STYLES - Optimize for PDF export\n âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */\n @media print {\n body { \n max-width: none; \n padding: 0;\n font-size: 11pt;\n }\n pre { \n white-space: pre-wrap; \n word-wrap: break-word;\n page-break-inside: avoid;\n }\n h1, h2, h3, h4, h5, h6 {\n page-break-after: avoid;\n }\n table {\n page-break-inside: avoid;\n }\n img {\n page-break-inside: avoid;\n }\n }\n","</style>\n</head>\n<body>\n").concat(d,"\n</body>\n</html>"),t=new Blob([e],{type:"text/html;charset=utf-8"});console.log("[Document Export] HTML blob size:",t.size,"bytes"),(0,a.saveAs)(t,"".concat(u,".html")),n.o.success("HTML exported");break}case"markdown":{console.log("[Document Export] Converting to Markdown...");let e=new s.A({headingStyle:"atx",hr:"---",bulletListMarker:"-",codeBlockStyle:"fenced",fence:"```",emDelimiter:"*",strongDelimiter:"**",linkStyle:"inlined"});e.use(l.Te),e.addRule("fencedCodeBlock",{filter:e=>{var t;return"PRE"===e.nodeName&&(null==(t=e.firstChild)?void 0:t.nodeName)==="CODE"},replacement:(e,t)=>{let r=t.firstChild,n=(r.getAttribute("class")||"").match(/language-(\w+)/),a=n?n[1]:"",s=r.textContent||"";return"\n```".concat(a,"\n").concat(s,"\n```\n")}});
1let t=e.turndown(d);t=t.replace(/\n{3,}/g,"\n\n").trim(),console.log("[Document Export] Markdown length:",t.length);let r=new Blob([t],{type:"text/markdown;charset=utf-8"});(0,a.saveAs)(r,"".concat(u,".md")),n.o.success("Markdown exported");break}default:console.error("[Document Export] Unknown format:",c),n.o.error("Unknown format: ".concat(c))}}catch(e){console.error("[Document Export] Error (".concat(c,"):"),e),n.o.error("Export failed: ".concat(e instanceof Error?e.message:"Unknown error"))}}},25643:(e,t,r)=>{r.d(t,{_:()=>d});var n=r(78542),a=r(18558),s=r(72409),l=r(72842),o=r(68580),i=r(27496),c=r(29798);function d(e){let{binaryUrl:t,fileName:d,className:u,onDownload:h,isDownloading:m}=e,x=(0,a.useRef)(null),[p,f]=(0,a.useState)(!0),[g,b]=(0,a.useState)(null),v=(0,a.useRef)(null),w=(0,a.useCallback)(async e=>{if(x.current){f(!0),b(null);try{let{renderAsync:t}=await Promise.all([r.e(5168),r.e(82753)]).then(r.bind(r,82753)),n=await fetch(e);if(!n.ok)throw Error("Failed to load document");let a=await n.arrayBuffer();x.current.innerHTML="",await t(a,x.current,void 0,{inWrapper:!0,ignoreWidth:!1,ignoreHeight:!0,ignoreFonts:!1,breakPages:!0,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,renderEndnotes:!0}),v.current=e}catch(e){console.error("[DocxRenderer] Render error:",e),b(e instanceof Error?e.message:"Failed to render document")}finally{f(!1)}}},[]);return((0,a.useEffect)(()=>{t&&t!==v.current?w(t):t||(f(!1),b("No document available"))},[t,w]),g&&!t)?(0,n.jsx)("div",{className:(0,s.cn)("w-full h-full flex items-center justify-center",u),children:(0,n.jsxs)("div",{className:"text-center space-y-3 p-6",children:[(0,n.jsx)(o.default,{className:"h-8 w-8 text-amber-500 mx-auto"}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:g}),h&&(0,n.jsxs)(l.$,{size:"sm",onClick:h,disabled:m,children:[m?(0,n.jsx)(c.RgoLoader,{customSize:22}):(0,n.jsx)(i.default,{className:"h-4 w-4 mr-2"}),"Download"]})]})}):(0,n.jsxs)("div",{className:(0,s.cn)("w-full h-full flex flex-col",u),children:[p&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-background/80",children:(0,n.jsx)(c.RgoLoader,{size:"medium"})}),g&&t&&(0,n.jsxs)("div",{className:"flex items-center justify-center p-4 gap-2 border-b bg-muted/30",children:[(0,n.jsx)(o.default,{className:"h-4 w-4 text-amber-500"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground",children:g}),h&&(0,n.jsxs)(l.$,{size:"sm",variant:"outline",onClick:h,disabled:m,children:[(0,n.jsx)(i.default,{className:"h-3 w-3 mr-1"}),"Download instead"]})]}),(0,n.jsx)("div",{ref:x,className:"flex-1 overflow-auto",style:{minHeight:0}}),(0,n.jsx)("style",{children:"\n .docx-wrapper {\n background: var(--background, #fff) !important;\n padding: 16px !important;\n }\n .docx-wrapper > section.docx {\n box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1) !important;\n margin-bottom: 16px !important;\n border-radius: 4px;\n }\n "})]})}},26608:(e,t,r)=>{r.d(t,{XY:()=>l,nn:()=>o});var n=r(25251),a=r(76524);function s(e){try{return e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16)))}catch(t){return console.error("Error processing Unicode escapes in path:",t),e}}let l=async(e,t)=>{if(!e||""===e.trim())return[];try{var r;let n=s(t),l=await a.H.get("/sandboxes/".concat(e,"/files?path=").concat(encodeURIComponent(n)),{showErrors:!0});if(l.error)throw Error("Error listing sandbox files: ".concat(l.error.message," (").concat(l.error.status,")"));return(null==(r=l.data)?void 0:r.files)||[]}catch(e){throw console.error("Failed to list sandbox files:",e),e}},o=async(e,t)=>{if(!e||""===e.trim())throw Error("Sandbox ID is required");try{let r=s(t),n=await a.H.get("/sandboxes/".concat(e,"/files/content?path=").concat(encodeURIComponent(r)),{showErrors:!0});if(n.error)throw Error("Error getting sandbox file content: ".concat(n.error.message," (").concat(n.error.status,")"));return n.data}catch(e){throw console.error("Failed to get sandbox file content:",e),(0,n.hS)(e,{operation:"load file content",resource:"file ".concat(t)}),e}}},27434:(e,t,r)=>{r.d(t,{h:()=>y});var n=r(78542);r(18558);var a=r(72409),s=r(72842),l=r(27496),o=r(29798),i=r(57570);let c=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsxs)("defs",{children:[(0,n.jsxs)("linearGradient",{id:"folderMainBrowser",x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#C5A381"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#B8946F"})]}),(0,n.jsxs)("linearGradient",{id:"folderTopBrowser",x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#D8C4A8"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#C5A381"})]})]}),(0,n.jsx)("rect",{x:"4",y:"18",width:"56",height:"40",rx:"6",fill:"url(#folderMainBrowser)"}),(0,n.jsx)("path",{d:"M4 24 Q4 18 10 18 L24 18 L28 14 Q30 12 34 12 L54 12 Q60 12 60 18 L60 22 L4 22 Z",fill:"url(#folderTopBrowser)"}),(0,n.jsx)("rect",{x:"4",y:"22",width:"56",height:"4",fill:"rgba(255,255,255,0.15)"})]}),d=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"codeModernBrowser",x1:"0%",y1:"0%",x2:"100%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#D8C4A8"}),(0,n.jsx)("stop",{offset:"50%",stopColor:"#C5A381"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#8A6A47"})]})}
1),(0,n.jsx)("rect",{x:"6",y:"6",width:"52",height:"52",rx:"12",fill:"url(#codeModernBrowser)"}),(0,n.jsx)("path",{d:"M22 22 L12 32 L22 42",stroke:"white",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M42 22 L52 32 L42 42",stroke:"white",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("line",{x1:"36",y1:"18",x2:"28",y2:"46",stroke:"rgba(255,255,255,0.6)",strokeWidth:"3",strokeLinecap:"round"})]}),u=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"imgModernBrowser",x1:"0%",y1:"0%",x2:"100%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#C2925F"}),(0,n.jsx)("stop",{offset:"50%",stopColor:"#A8754F"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#8A6A47"})]})}),(0,n.jsx)("rect",{x:"6",y:"10",width:"52",height:"44",rx:"8",fill:"url(#imgModernBrowser)"}),(0,n.jsx)("circle",{cx:"22",cy:"26",r:"7",fill:"rgba(255,255,255,0.85)"}),(0,n.jsx)("path",{d:"M10 46 L22 32 L32 42 L42 30 L54 46 Q54 52 50 54 L14 54 Q10 54 10 50 Z",fill:"rgba(255,255,255,0.25)"})]}),h=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"docModernBrowser",x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#FAF9F6"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#EFEEEB"})]})}),(0,n.jsx)("rect",{x:"10",y:"4",width:"44",height:"56",rx:"6",fill:"url(#docModernBrowser)",stroke:"#E4E0D9",strokeWidth:"1"}),(0,n.jsx)("rect",{x:"18",y:"16",width:"28",height:"2.5",rx:"1",fill:"#7E756F"}),(0,n.jsx)("rect",{x:"18",y:"23",width:"22",height:"2.5",rx:"1",fill:"#A39A92"}),(0,n.jsx)("rect",{x:"18",y:"30",width:"26",height:"2.5",rx:"1",fill:"#A39A92"}),(0,n.jsx)("rect",{x:"18",y:"37",width:"20",height:"2.5",rx:"1",fill:"#A39A92"}),(0,n.jsx)("rect",{x:"18",y:"44",width:"24",height:"2.5",rx:"1",fill:"#A39A92"})]}),m=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"genModernBrowser",x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#EFEEEB"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#E4E0D9"})]})}),(0,n.jsx)("rect",{x:"10",y:"4",width:"44",height:"56",rx:"6",fill:"url(#genModernBrowser)"}),(0,n.jsx)("rect",{x:"18",y:"20",width:"28",height:"3",rx:"1.5",fill:"#A39A92"}),(0,n.jsx)("rect",{x:"18",y:"28",width:"22",height:"3",rx:"1.5",fill:"#A39A92"}),(0,n.jsx)("rect",{x:"18",y:"36",width:"26",height:"3",rx:"1.5",fill:"#A39A92"}),(0,n.jsx)("rect",{x:"18",y:"44",width:"18",height:"3",rx:"1.5",fill:"#A39A92"})]}),x=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"videoModern",x1:"0%",y1:"0%",x2:"100%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#A8754F"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#75593C"})]})}),(0,n.jsx)("rect",{x:"6",y:"10",width:"52",height:"44",rx:"8",fill:"url(#videoModern)"}),(0,n.jsx)("path",{d:"M26 22 L26 42 L44 32 Z",fill:"rgba(255,255,255,0.9)"})]}),p=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"audioModern",x1:"0%",y1:"0%",x2:"100%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#87965E"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#6F7D4F"})]})}),(0,n.jsx)("rect",{x:"6",y:"6",width:"52",height:"52",rx:"12",fill:"url(#audioModern)"}),(0,n.jsx)("circle",{cx:"32",cy:"32",r:"14",fill:"none",stroke:"rgba(255,255,255,0.3)",strokeWidth:"3"}),(0,n.jsx)("circle",{cx:"32",cy:"32",r:"8",fill:"rgba(255,255,255,0.9)"}),(0,n.jsx)("rect",{x:"20",y:"14",width:"3",height:"12",rx:"1.5",fill:"rgba(255,255,255,0.6)"}),(0,n.jsx)("rect",{x:"26",y:"10",width:"3",height:"16",rx:"1.5",fill:"rgba(255,255,255,0.6)"}),(0,n.jsx)("rect",{x:"35",y:"12",width:"3",height:"14",rx:"1.5",fill:"rgba(255,255,255,0.6)"}),(0,n.jsx)("rect",{x:"41",y:"16",width:"3",height:"10",rx:"1.5",fill:"rgba(255,255,255,0.6)"})]}),f=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"archiveModern",x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#D3B591"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#C5A381"})]})}),(0,n.jsx)("rect",{x:"10",y:"4",width:"44",height:"56",rx:"6",fill:"url(#archiveModern)"}),(0,n.jsx)("rect",{x:"26",y:"8",width:"12",height:"4",rx:"1",fill:"rgba(0,0,0,0.2)"}),(0,n.jsx)("rect",{x:"26",y:"14",width:"12",height:"4",rx:"1",fill:"rgba(0,0,0,0.2)"}),(0,n.jsx)("rect",{x:"26",y:"20",width:"12",height:"4",rx:"1",fill:"rgba(0,0,0,0.2)"}),(0,n.jsx)("rect",{x:"26",y:"26",width:"12",height:"4",rx:"1",fill:"rgba(0,0,0,0.2)"}),(0,n.jsx)("rect",{x:"24",y:"34",width:"16",height:"20",rx:"2",fill:"rgba(0,0,0,0.15)"}),(0,n.jsx)("circle",{cx:"32",cy:"40",r:"3",fill:"rgba(0,0,0,0.3)"})]}),g=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"mdModern",x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#2D2926"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#211E1B"})]})}),(0,n.jsx)("rect",{x:"6",y:"10",width:"52",height:"44",rx:"6",fill:"url(#mdModern)"}),(0,n.jsx)("text",{x:"32",y:"40",textAnchor:"middle",fill:"white",fontSize:"14",fontWeight:"bold",fontFamily:"system-ui",children:"MD"})]}),b=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"jsonModern",x1:"0%",y1:"0%",x2:"100%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#D8C4A8"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#C5A381"})]})}
1),(0,n.jsx)("rect",{x:"6",y:"6",width:"52",height:"52",rx:"12",fill:"url(#jsonModern)"}),(0,n.jsx)("text",{x:"32",y:"40",textAnchor:"middle",fill:"#5E472F",fontSize:"16",fontWeight:"bold",fontFamily:"monospace"})]}),v=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"pdfModern",x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#CF4537"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#BA1A1A"})]})}),(0,n.jsx)("rect",{x:"10",y:"4",width:"44",height:"56",rx:"6",fill:"url(#pdfModern)"}),(0,n.jsx)("text",{x:"32",y:"40",textAnchor:"middle",fill:"white",fontSize:"12",fontWeight:"bold",fontFamily:"system-ui",children:"PDF"})]}),w=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"sheetModern",x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#87965E"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#6F7D4F"})]})}),(0,n.jsx)("rect",{x:"6",y:"6",width:"52",height:"52",rx:"8",fill:"url(#sheetModern)"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"36",height:"36",rx:"2",fill:"rgba(255,255,255,0.2)"}),(0,n.jsx)("line",{x1:"14",y1:"26",x2:"50",y2:"26",stroke:"rgba(255,255,255,0.5)",strokeWidth:"1"}),(0,n.jsx)("line",{x1:"14",y1:"38",x2:"50",y2:"38",stroke:"rgba(255,255,255,0.5)",strokeWidth:"1"}),(0,n.jsx)("line",{x1:"26",y1:"14",x2:"26",y2:"50",stroke:"rgba(255,255,255,0.5)",strokeWidth:"1"}),(0,n.jsx)("line",{x1:"38",y1:"14",x2:"38",y2:"50",stroke:"rgba(255,255,255,0.5)",strokeWidth:"1"})]}),j=()=>(0,n.jsxs)("svg",{viewBox:"0 0 64 64",className:"w-full h-full",children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"configModern",x1:"0%",y1:"0%",x2:"100%",y2:"100%",children:[(0,n.jsx)("stop",{offset:"0%",stopColor:"#7E756F"}),(0,n.jsx)("stop",{offset:"100%",stopColor:"#5F574F"})]})}),(0,n.jsx)("rect",{x:"6",y:"6",width:"52",height:"52",rx:"12",fill:"url(#configModern)"}),(0,n.jsx)("circle",{cx:"32",cy:"32",r:"12",fill:"none",stroke:"rgba(255,255,255,0.8)",strokeWidth:"3"}),(0,n.jsx)("circle",{cx:"32",cy:"32",r:"5",fill:"rgba(255,255,255,0.8)"}),(0,n.jsx)("rect",{x:"30",y:"8",width:"4",height:"10",rx:"2",fill:"rgba(255,255,255,0.8)"}),(0,n.jsx)("rect",{x:"30",y:"46",width:"4",height:"10",rx:"2",fill:"rgba(255,255,255,0.8)"}),(0,n.jsx)("rect",{x:"8",y:"30",width:"10",height:"4",rx:"2",fill:"rgba(255,255,255,0.8)"}),(0,n.jsx)("rect",{x:"46",y:"30",width:"10",height:"4",rx:"2",fill:"rgba(255,255,255,0.8)"})]});function y(e){var t;let{url:r,fileName:y,className:N,onDownload:_,isDownloading:E=!1}=e,k=(null==(t=y.split(".").pop())?void 0:t.toLowerCase())||"",{isRestricted:C,openUpgradeModal:S}=(0,i.Qg)({featureName:"files"});return(0,n.jsx)("div",{className:(0,a.cn)("flex flex-col items-center justify-center p-6",N),children:(0,n.jsxs)("div",{className:"flex flex-col items-center text-center max-w-md",children:[(0,n.jsxs)("div",{className:"relative mb-4",children:[(0,n.jsx)("div",{className:"w-12 h-12",children:function(e){var t;let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(r)return(0,n.jsx)(c,{});let a=e.includes(".")&&(null==(t=e.split(".").pop())?void 0:t.toLowerCase())||"";return["jpg","jpeg","png","gif","svg","webp","ico","bmp","tiff"].includes(a)?(0,n.jsx)(u,{}):["mp4","webm","mov","avi","mkv","flv","wmv"].includes(a)?(0,n.jsx)(x,{}):["mp3","wav","ogg","flac","aac","m4a","wma"].includes(a)?(0,n.jsx)(p,{}):["zip","tar","gz","rar","7z","bz2","xz","tgz"].includes(a)?(0,n.jsx)(f,{}):["md","mdx","markdown"].includes(a)?(0,n.jsx)(g,{}):["json","jsonc","json5"].includes(a)?(0,n.jsx)(b,{}):["pdf"].includes(a)?(0,n.jsx)(v,{}):["csv","xls","xlsx","ods"].includes(a)?(0,n.jsx)(w,{}):["yaml","yml","toml","ini","cfg","conf","env","properties"].includes(a)?(0,n.jsx)(j,{}):["js","ts","jsx","tsx","py","rb","go","rs","java","c","cpp","h","hpp","css","scss","sass","less","html","htm","vue","svelte","php","swift","kt","kts","scala","clj","ex","exs","erl","hs","lua","r","sh","bash","zsh","fish","ps1","sql","graphql","gql"].includes(a)?(0,n.jsx)(d,{}):["txt","log","rtf","doc","docx","odt"].includes(a)?(0,n.jsx)(h,{}):["rgocanvas"].includes(a)?(0,n.jsx)(u,{}):(0,n.jsx)(m,{})}(y,!1)}),(0,n.jsx)("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 bg-background rounded px-1 py-0.5 text-[10px] font-medium text-muted-foreground border shadow-sm",children:k.toUpperCase()})]}),(0,n.jsx)("h3",{className:"text-sm font-medium mb-1 mt-1",children:y.split("/").pop()}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mb-4",children:"This binary file cannot be previewed in the browser"}),(0,n.jsxs)(s.$,{variant:"default",size:"sm",className:"min-w-[120px]",onClick:()=>
1{if(C)return void S();if(_)_();else if(r){let e=document.createElement("a");e.href=r,e.download=y.split("/").pop()||"file",document.body.appendChild(e),e.click(),document.body.removeChild(e)}else console.error("[BINARY RENDERER] No download URL or handler available")},disabled:E,children:[E?(0,n.jsx)(o.RgoLoader,{size:"small"}):(0,n.jsx)(l.default,{className:"h-3.5 w-3.5"}),"Download"]})]})})}},29328:(e,t,r)=>{r.d(t,{G:()=>o});var n=r(18558),a=r(75152),s=r(76804),l=r(21528);function o(e,t){var r;let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{enabled:i=!0,showPreview:c=!0}=o,d=t&&t.split("/").pop()||"",u=(null==(r=d.split(".").pop())?void 0:r.toLowerCase())||"";t&&(0,s.ti)(d);let h=(0,l.u)(t||""),m=(0,l.w8)(u),x=(0,l.gI)(u),p=(0,l.B8)(u),f=(0,l.cH)(u),g=(0,l.lk)(u),b=(0,l.NA)(u),v=(0,l.IF)(u),w=(0,l.XU)(u),j=g||b||v||f||w,y=h||m||x||p,N=(0,a.x2)(y&&c?e:void 0,y&&c?t:void 0,{contentType:"blob",enabled:i&&y&&c}),_=(0,a.x2)(j&&c?e:void 0,j&&c?t:void 0,{contentType:"text",enabled:i&&j&&c}),[E,k]=n.useState(null);n.useEffect(()=>{if(N.data instanceof Blob){let e=URL.createObjectURL(N.data);return k(e),()=>{URL.revokeObjectURL(e),k(null)}}k(null)},[N.data]);let C=y?N:_;return{data:y?E:_.data,isLoading:C.isLoading,error:C.error,retryCount:C.failureCount||0,isImage:h,isPdf:m,isSpreadsheet:x,isVideo:p,isText:j}}},29453:(e,t,r)=>{r.d(t,{Dj:()=>m,NR:()=>p,Rb:()=>i,WT:()=>c,YY:()=>h,kl:()=>x,tf:()=>f,xV:()=>o});var n=r(67211),a=r(16699),s=r(99749);let l=["plan","brief","leads","outreach","follow-ups","schedules","social-calendar","social-posts","social-inbox","social-ideas","social-performance","social-brand","social-setup","integrations","documents"];function o(e){return!!e&&l.includes(e)}let i=!0,c="brief";function d(e){return e?"workspace"===e||e.startsWith("workspace/")?"/"+e:e.startsWith("/workspace")?e:"/workspace/".concat(e.replace(/^\//,"")):"/workspace"}let u={activeView:"tools",activeViewRequestedAt:0,activeViewRequestedFor:null,viewThreadId:null,filesSubView:"browser",currentPath:"/workspace",selectedFilePath:null,filePathList:void 0,currentFileIndex:-1,selectedVersion:null,selectedVersionDate:null,shouldOpenPanel:!1,isSidePanelOpen:!1,mobileAppBuilderTab:"chat",companySection:c,followUpsFocus:null,followUpsNav:{stack:[{kind:"calendar"}],mode:null,cursor:null},companyEditing:!1,companyEditors:{},pendingToolNavIndex:null,unsavedFileContent:{},unsavedFileState:{},deliverableAttachments:null},h=(0,n.v)()((0,a.lt)((e,t)=>({...u,setActiveView:(r,n)=>{let a=s.eT&&"browser"===r?"tools":r,l=(null==n?void 0:n.automatic)?{}:{activeViewRequestedAt:Date.now(),activeViewRequestedFor:t().viewThreadId};"files"!==a?e({activeView:a,selectedFilePath:null,filePathList:void 0,currentFileIndex:-1,...l}):e({activeView:a,...l})},openFile:(t,r)=>{let n=d(t),a=n.lastIndexOf("/"),s=a>0?n.substring(0,a):"/workspace",l=-1;r&&r.length>0&&(l=r.findIndex(e=>d(e)===n)),e({filesSubView:"viewer",selectedFilePath:n,currentPath:s,filePathList:r,currentFileIndex:l>=0?l:0})},goBackToBrowser:()=>{e({filesSubView:"browser",selectedFilePath:null,filePathList:void 0,currentFileIndex:-1})},navigateToPath:t=>{e({currentPath:d(t),filesSubView:"browser",selectedFilePath:null,filePathList:void 0,currentFileIndex:-1})},setCurrentFileIndex:r=>{let{filePathList:n}=t();if(n&&r>=0&&r<n.length){let t=d(n[r]);e({currentFileIndex:r,selectedFilePath:t})}},setSelectedVersion:(t,r)=>{e({selectedVersion:t,selectedVersionDate:null!=r?r:null})},clearSelectedVersion:()=>{e({selectedVersion:null,selectedVersionDate:null})},openFileInComputer:(r,n)=>{let a=d(r),s=a.lastIndexOf("/"),l=s>0?a.substring(0,s):"/workspace",o=-1;n&&n.length>0&&(o=n.findIndex(e=>d(e)===a)),e({activeView:"files",activeViewRequestedAt:Date.now(),activeViewRequestedFor:t().viewThreadId,filesSubView:"viewer",selectedFilePath:a,currentPath:l,filePathList:n,currentFileIndex:o>=0?o:0,shouldOpenPanel:!0})},openFileBrowser:()=>{e({activeView:"files",activeViewRequestedAt:Date.now(),activeViewRequestedFor:t().viewThreadId,filesSubView:"browser",currentPath:"/workspace",selectedFilePath:null,filePathList:void 0,currentFileIndex:-1,shouldOpenPanel:!0})},navigateToToolCall:r=>{e({activeView:"tools",activeViewRequestedAt:Date.now(),activeViewRequestedFor:t().viewThreadId,pe
1ndingToolNavIndex:r,shouldOpenPanel:!0})},clearPendingToolNav:()=>{e({pendingToolNavIndex:null})},clearShouldOpenPanel:()=>{e({shouldOpenPanel:!1})},setIsSidePanelOpen:t=>{e({isSidePanelOpen:t})},openSidePanel:()=>{e({isSidePanelOpen:!0})},closeSidePanel:()=>{e({isSidePanelOpen:!1})},setMobileAppBuilderTab:t=>{e({mobileAppBuilderTab:t})},setCompanySection:t=>{let r=i&&"plan"===t?"brief":t;r!==t&&console.debug("[RgoComputerStore] Plan is hidden â opening Brief instead"),e({companySection:r})},setFollowUpsFocus:t=>{e({followUpsFocus:t})},setFollowUpsNav:t=>{e(e=>({followUpsNav:{...e.followUpsNav,...t}}))},setViewThread:r=>{t().viewThreadId!==r&&e({viewThreadId:r})},setCompanyEditing:function(r){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default",a=t().companyEditors;if(!!a[n]===r)return;let s={...a};r?s[n]=!0:delete s[n];let l=Object.keys(s).length>0;console.debug("[RgoComputerStore] Company editor",r?"opened":"closed",{editorId:n,companyEditing:l}),e({companyEditors:s,companyEditing:l})},setUnsavedContent:(t,r)=>{let n=d(t);e(e=>({unsavedFileContent:{...e.unsavedFileContent,[n]:r}}))},getUnsavedContent:e=>{let r=d(e);return t().unsavedFileContent[r]},clearUnsavedContent:t=>{let r=d(t);e(e=>{let{[r]:t,...n}=e.unsavedFileContent,{[r]:a,...s}=e.unsavedFileState;return{unsavedFileContent:n,unsavedFileState:s}})},setUnsavedState:(t,r)=>{let n=d(t);e(e=>({unsavedFileState:{...e.unsavedFileState,[n]:r}}))},getUnsavedState:e=>{var r;let n=d(e);return null!=(r=t().unsavedFileState[n])&&r},setDeliverableAttachments:r=>{let n=t().deliverableAttachments;(null!==n||null!==r)&&(null===n||null===r||n.join("\n")!==r.join("\n"))&&e({deliverableAttachments:r})},reset:()=>{let{companyEditing:r,companyEditors:n,viewThreadId:a}=t();e({...u,companyEditing:r,companyEditors:n,viewThreadId:a})}}),{name:"rgo-computer-store"})),m=()=>h(e=>e.pendingToolNavIndex),x=()=>h(e=>e.clearPendingToolNav),p=()=>h(e=>e.isSidePanelOpen),f=()=>h(e=>e.setIsSidePanelOpen)},30094:(e,t,r)=>{r.d(t,{X:()=>y});var n=r(78542),a=r(18558),s=r(72409),l=r(83797),o=r(34298),i=r(72842),c=r(77475),d=r(35284),u=r(73511),h=r(69534),m=r(42061),x=r(78001),p=r(33591),f=r(236),g=r(24437);function b(e){return null==e?"":e instanceof Date?e.toLocaleDateString():"object"!=typeof e||Array.isArray(e)?e:"string"==typeof e.text?e.text:"string"==typeof e.url?e.url:"string"==typeof e.hyperlink?e.hyperlink:"string"==typeof e.Target?e.Target:void 0!==e.v?String(e.v):JSON.stringify(e)}async function v(e){let t=await Promise.all([r.e(6237),r.e(63170)]).then(r.bind(r,74140)),n=t.read(e,{type:"array",cellText:!1,cellDates:!0}),a=n.SheetNames||[];if(!a||0===a.length)return console.warn("[XlsxRenderer] No sheets found in XLSX file (xlsx lib)"),{sheets:[],sheetNames:[]};let s=a.map(e=>{try{let r=n.Sheets[e],a=t.utils.sheet_to_json(r,{header:1,defval:null,raw:!1});if(console.log('[XlsxRenderer] Parsing XLSX sheet "'.concat(e,'" (xlsx lib): ').concat((null==a?void 0:a.length)||0," rows")),!a||0===a.length)return console.warn('[XlsxRenderer] XLSX sheet "'.concat(e,'" has no rows')),{headers:[],data:[]};let s=(a[0]||[]).map((e,t)=>{let r=b(e);return null==r||""===r?"Column ".concat(t+1):String(r)}),l=a.slice(1).filter(e=>e&&Array.isArray(e)&&e.some(e=>null!=e&&""!==e));console.log('[XlsxRenderer] XLSX sheet "'.concat(e,'" (xlsx lib): ').concat(s.length," headers, ").concat(l.length," data rows"));let o=l.map(e=>{let t={};return s.forEach((r,n)=>{t[r]=b(e[n])}),t});return{headers:s,data:o}}catch(t){return console.error('[XlsxRenderer] Error parsing XLSX sheet "'.concat(e,'" (xlsx lib):'),t),{headers:[],data:[]}}});return console.log("[XlsxRenderer] Parsed XLSX workbook (xlsx lib):",{sheetCount:s.length,sheetsWithData:s.filter(e=>e.headers.length>0||e.data.length>0).length}),{sheets:s,sheetNames:a}}async function w(e,t){let n=(await r.e(77583).then(r.bind(r,77583))).default,a=(await r.e(77583).then(r.bind(r,77583))).readSheetNames;try{let t=await a(e);if(!t||0===t.length)return console.warn("[XlsxRenderer] No sheets found in file"),{sheets:[],sheetNames:[]};let r=await Promise.all(t.map(async t=>{try{let r=await n(e,{sheet:t});if(console.log('[XlsxRenderer] Parsing sheet "'.concat(t,'": ').concat((null==r?void 0:r.length)||0," rows")),!r||0===r.length)return console.warn('[XlsxRenderer] Sheet "'.concat(t,'" has no rows')),{headers:[],data:[]};let a=(r[0]||[]).map((e,t)=>
1{let r=b(e);return null==r||""===r?"Column ".concat(t+1):String(r)}),s=r.slice(1).filter(e=>e&&e.some(e=>null!=e&&""!==e));console.log('[XlsxRenderer] Sheet "'.concat(t,'": ').concat(a.length," headers, ").concat(s.length," data rows"));let l=s.map(e=>{let t={};return a.forEach((r,n)=>{t[r]=b(e[n])}),t});return{headers:a,data:l}}catch(r){let e=(null==r?void 0:r.message)||String(r);if(e.includes("inline string")||e.includes("inlineStr")||e.includes("inline string"))throw console.warn('[XlsxRenderer] Inline string detected in sheet "'.concat(t,'", will fallback to xlsx library')),Error("INLINE_STRING_ERROR");return console.error('[XlsxRenderer] Error parsing sheet "'.concat(t,'":'),r),{headers:[],data:[]}}}));return console.log("[XlsxRenderer] Parsed workbook:",{sheetCount:r.length,sheetsWithData:r.filter(e=>e.headers.length>0||e.data.length>0).length}),{sheets:r,sheetNames:t}}catch(r){let e=(null==r?void 0:r.message)||String(r);if(e.includes("inline string")||e.includes("inlineStr")||"INLINE_STRING_ERROR"===e)return console.warn("[XlsxRenderer] File contains inline strings, falling back to xlsx library"),await v(t);throw r}}async function j(e){let t=await Promise.all([r.e(6237),r.e(63170)]).then(r.bind(r,74140)),n=t.read(e,{type:"array"}),a=n.SheetNames||[];if(!a||0===a.length)return console.warn("[XlsxRenderer] No sheets found in XLS file"),{sheets:[],sheetNames:[]};let s=a.map(e=>{try{let r=n.Sheets[e],a=t.utils.sheet_to_json(r,{header:1,defval:null});if(console.log('[XlsxRenderer] Parsing XLS sheet "'.concat(e,'": ').concat((null==a?void 0:a.length)||0," rows")),!a||0===a.length)return console.warn('[XlsxRenderer] XLS sheet "'.concat(e,'" has no rows')),{headers:[],data:[]};let s=(a[0]||[]).map((e,t)=>{let r=b(e);return null==r||""===r?"Column ".concat(t+1):String(r)}),l=a.slice(1).filter(e=>e&&Array.isArray(e)&&e.some(e=>null!=e&&""!==e));console.log('[XlsxRenderer] XLS sheet "'.concat(e,'": ').concat(s.length," headers, ").concat(l.length," data rows"));let o=l.map(e=>{let t={};return s.forEach((r,n)=>{t[r]=b(e[n])}),t});return{headers:s,data:o}}catch(t){return console.error('[XlsxRenderer] Error parsing XLS sheet "'.concat(e,'":'),t),{headers:[],data:[]}}});return console.log("[XlsxRenderer] Parsed XLS workbook:",{sheetCount:s.length,sheetsWithData:s.filter(e=>e.headers.length>0||e.data.length>0).length}),{sheets:s,sheetNames:a}}function y(e){var t;let{filePath:r,fileName:b,className:v,sandboxId:y,project:N}=e,{session:_}=(0,d.A)(),[E,k]=(0,a.useState)(0),[C,S]=(0,a.useState)(""),[D,A]=(0,a.useState)(new Set),[L,I]=(0,a.useState)(1),[R]=(0,a.useState)(50),[P,T]=(0,a.useState)({column:"",direction:null}),[M,z]=(0,a.useState)(!0),[U,B]=(0,a.useState)(null),[F,O]=(0,a.useState)({sheets:[],sheetNames:[]}),W=r||b,H=y||(null==N||null==(t=N.sandbox)?void 0:t.id);a.useEffect(()=>{let e=!1;return async function(){try{let t,r;if(z(!0),B(null),A(new Set),I(1),T({column:"",direction:null}),k(0),"string"==typeof W&&W.startsWith("blob:")){let e=await fetch(W);if(!e.ok)throw Error("Fetch failed: ".concat(e.status));t=await e.arrayBuffer()}else if(H&&(null==_?void 0:_.accessToken)){let e=W;"workspace"===W||W.startsWith("workspace/")?e="/"+W:W.startsWith("/workspace")||(e="/workspace/".concat(W.startsWith("/")?W.substring(1):W));let r=new URL("".concat("https://api.rationalgo.ai/v1","/sandboxes/").concat(H,"/files/content"));r.searchParams.append("path",e);let n=await fetch(r.toString(),{headers:{Authorization:"Bearer ".concat(_.accessToken)}});if(!n.ok)throw Error("Fetch failed: ".concat(n.status));t=await n.arrayBuffer()}else{let e=await fetch(W);if(!e.ok)throw Error("Fetch failed: ".concat(e.status));t=await e.arrayBuffer()}if(!t||0===t.byteLength)throw Error("Empty file received");let n=function(e){let t=new Uint8Array(e);return t.length>=4&&80===t[0]&&75===t[1]&&3===t[2]&&4===t[3]?"xlsx":t.length>=8&&208===t[0]&&207===t[1]&&17===t[2]&&224===t[3]&&161===t[4]&&177===t[5]&&26===t[6]&&225===t[7]?"xls":"unknown"}(t);if(console.log("[XlsxRenderer] Detected format:",n,"size:",t.byteLength),"xlsx"===n){let e=new File([t],b||"spreadsheet.xlsx",{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});r=await w(e,t)}else if("xls"===n)r=await j(t);else throw Error("Unknown file format. Expected XLS or XLSX file.");e||(console.log("[XlsxRenderer] Parse result:",{sheetCount:r.sheets.length,sheetNames:r.sheetNames,sheetsWithHeaders:r.sheets.filter(e=>e.headers.length>0).length,sheetsWithData:r.sheets.filter(e=>e.data.length>0).length}
1),r.sheets&&0!==r.sheets.length?O(r):(console.warn("[XlsxRenderer] No sheets parsed from file"),B("No sheets found in spreadsheet"),O({sheets:[],sheetNames:[]})),z(!1))}catch(t){console.error("[XlsxRenderer] Parse error:",t),e||(B((null==t?void 0:t.message)||"Failed to load spreadsheet"),O({sheets:[],sheetNames:[]}),z(!1))}}(),()=>{e=!0}},[W,H,null==_?void 0:_.accessToken,b]);let G=F.sheets[E]||{headers:[],data:[]},V=(0,a.useMemo)(()=>{let e=G.data;return C&&(e=e.filter(e=>Object.entries(e).filter(e=>{let[t]=e;return!D.has(t)}).some(e=>{let[,t]=e;return null!=t&&String(t).toLowerCase().includes(C.toLowerCase())}))),P.column&&P.direction&&(e=[...e].sort((e,t)=>{let r=e[P.column],n=t[P.column];if(null==r&&null==n)return 0;if(null==r)return"asc"===P.direction?-1:1;if(null==n)return"asc"===P.direction?1:-1;if("number"==typeof r&&"number"==typeof n)return"asc"===P.direction?r-n:n-r;let a=String(r).toLowerCase(),s=String(n).toLowerCase();return a<s?"asc"===P.direction?-1:1:a>s?"asc"===P.direction?1:-1:0})),e},[G.data,C,P,D]),X=Math.ceil(V.length/R)||1,$=(L-1)*R,Y=V.slice($,$+R),K=G.headers.filter(e=>!D.has(e));if(M)return(0,n.jsx)("div",{className:(0,s.cn)("w-full h-full flex items-center justify-center",v),children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loadingâ¦"})});if(U||0===F.sheets.length||0===F.sheetNames.length)return(0,n.jsx)("div",{className:(0,s.cn)("w-full h-full flex items-center justify-center",v),children:(0,n.jsxs)("div",{className:"text-center space-y-2",children:[(0,n.jsx)("div",{className:"w-12 h-12 mx-auto rounded-full bg-muted flex items-center justify-center",children:(0,n.jsx)(h.default,{className:"h-6 w-6 text-muted-foreground"})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:U?"Failed to load spreadsheet":"No Data"}),!U&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground",children:"This spreadsheet appears to be empty or could not be parsed."}),U&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:U})]})]})});let q=G.headers.length>0,Z=G.data.length>0;return q||Z?(0,n.jsxs)("div",{className:(0,s.cn)("w-full h-full flex flex-col bg-transparent",v),children:[(0,n.jsxs)("div",{className:"shrink-0 border-b bg-muted/30 p-4 space-y-3",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(h.default,{className:"h-5 w-5 text-primary"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"font-medium text-foreground",children:"Spreadsheet"}),(0,n.jsxs)("p",{className:"text-xs text-muted-foreground",children:["- ",V.length.toLocaleString()," rows, ",K.length," columns"]})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[F.sheetNames.length>1&&(0,n.jsxs)(u.rI,{children:[(0,n.jsx)(u.ty,{asChild:!0,children:(0,n.jsxs)(i.$,{variant:"outline",size:"sm",children:[(0,n.jsx)(m.default,{className:"h-4 w-4 mr-1"}),F.sheetNames[E]||"Sheet 1"]})}),(0,n.jsx)(u.SQ,{align:"end",className:"min-w-[160px]",children:F.sheetNames.map((e,t)=>(0,n.jsx)(u._2,{onClick:()=>{k(t),A(new Set),I(1),T({column:"",direction:null})},className:"cursor-pointer",children:e},e+t))})]}),(0,n.jsxs)(c.E,{variant:"outline",className:"text-xs",children:["Page ",L," of ",X]}),(0,n.jsxs)(u.rI,{children:[(0,n.jsx)(u.ty,{asChild:!0,children:(0,n.jsxs)(i.$,{variant:"outline",size:"sm",children:[(0,n.jsx)(x.default,{className:"h-4 w-4 mr-1"}),"Columns"]})}),(0,n.jsxs)(u.SQ,{align:"end",className:"w-48",children:[(0,n.jsx)("div",{className:"px-2 py-1.5 text-sm font-medium",children:"Show/Hide Columns"}),(0,n.jsx)(u.mB,{}),G.headers.map(e=>(0,n.jsx)(u.hO,{checked:!D.has(e),onCheckedChange:()=>{A(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},children:e},e))]})]})]})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(p.default,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,n.jsx)(o.p,{placeholder:"Search data...",value:C,onChange:e=>{S(e.target.value),I(1)},className:"pl-9"})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,n.jsx)("div",{className:"w-full h-full overflow-auto scrollbar-thin scrollbar-thumb-zinc-300 dark:scrollbar-thumb-zinc-700 scrollbar-track-transparent",children:(0,n.jsx)(l.d,{headers:K,data:Y,sortConfig:P,onSort:e=>{T(t=>
1{if(t.column===e){let r="asc"===t.direction?"desc":"desc"===t.direction?null:"asc";return{column:r?e:"",direction:r}}return{column:e,direction:"asc"}})},searchTerm:C,onClearSearch:()=>S("")})})}),X>1&&(0,n.jsxs)("div",{className:"shrink-0 flex items-center justify-between border-t border-hairline px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"text-[11.5px] text-muted-foreground tabular-nums",children:[$+1,"â",Math.min($+R,V.length)," of ",V.length.toLocaleString()," rows"]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:()=>I(e=>Math.max(1,e-1)),disabled:1===L,title:"Previous page",className:"flex h-6 w-6 items-center justify-center rounded-[6px] border border-border text-muted-foreground transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50 disabled:text-text-subtle disabled:hover:bg-transparent",children:(0,n.jsx)(f.default,{className:"h-[13px] w-[13px]",strokeWidth:2.5})}),(0,n.jsxs)("span",{className:"min-w-[56px] text-center text-[11.5px] font-semibold text-muted-foreground tabular-nums",children:[L," / ",X]}),(0,n.jsx)("button",{type:"button",onClick:()=>I(e=>Math.min(X,e+1)),disabled:L===X,title:"Next page",className:"flex h-6 w-6 items-center justify-center rounded-[6px] border border-border text-muted-foreground transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50 disabled:text-text-subtle disabled:hover:bg-transparent",children:(0,n.jsx)(g.default,{className:"h-[13px] w-[13px]",strokeWidth:2.5})})]})]})]}):(0,n.jsx)("div",{className:(0,s.cn)("w-full h-full flex items-center justify-center",v),children:(0,n.jsxs)("div",{className:"text-center space-y-2",children:[(0,n.jsx)("div",{className:"w-12 h-12 mx-auto rounded-full bg-muted flex items-center justify-center",children:(0,n.jsx)(h.default,{className:"h-6 w-6 text-muted-foreground"})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:"No Data"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground",children:"This sheet appears to be empty."})]})]})})}},34141:(e,t,r)=>{r.d(t,{K:()=>V});var n=r(78542),a=r(18558),s=r(32904),l=r(82044),o=r(36217),i=r(6875),c=r(58772),d=r(27496),u=r(54942),h=r(34556),m=r(80195),x=r(47145),p=r(86899),f=r(44289),g=r(59201),b=r(25146),v=r(92857),w=r(6721),j=r(40018),y=r(75527),N=r(29798),_=r(72409),E=r(72842),k=r(26835),C=r(51145),S=r(73511),D=r(47358),A=r(59652),L=r(36987),I=r(35284),R=r(90350);function P(e){let t={id:e.id||"",name:e.name||"",x:Number(e.x)||0,y:Number(e.y)||0,width:Number(e.width)||100,height:Number(e.height)||100,rotation:Number(e.rotation)||0,opacity:void 0!==e.opacity?Number(e.opacity):1,locked:!!e.locked,visible:!1!==e.visible};return"frame"===e.type?{...t,type:"frame",backgroundColor:e.backgroundColor||void 0}:{...t,type:"image",src:e.src||"",scaleX:Number(e.scaleX)||1,scaleY:Number(e.scaleY)||1}}function T(e){return(e||[]).map(P)}function M(e,t){if(!e)return t;let r=t;return r.startsWith("/")&&(r=r.substring(1)),r.startsWith("workspace/")&&(r=r.substring(10)),r="/workspace/".concat(r),"".concat("https://api.rationalgo.ai/v1","/sandboxes/").concat(e,"/files/content?path=").concat(encodeURIComponent(r))}function z(e){let{isVisible:t}=e;return t?(0,n.jsxs)("div",{className:"absolute inset-0 overflow-hidden rounded pointer-events-none z-20",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/30"}),(0,n.jsx)("div",{className:"absolute inset-0",style:{background:"\n linear-gradient(\n 110deg, \n transparent 15%, \n rgba(255,255,255,0.15) 25%,\n rgba(255,255,255,0.5) 45%,\n rgba(255,255,255,0.7) 50%,\n rgba(255,255,255,0.5) 55%,\n rgba(255,255,255,0.15) 75%,\n transparent 85%\n )\n ",backgroundSize:"300% 100%",animation:"shimmer 2.5s infinite linear"}}),(0,n.jsx)("div",{className:"absolute inset-0",style:{background:"\n linear-gradient(\n 110deg, \n transparent 25%, \n rgba(255,255,255,0.25) 40%,\n rgba(255,255,255,0.6) 50%,\n rgba(255,255,255,0.25) 60%,\n transparent 75%\n )\n ",backgroundSize:"250% 100%",animation:"shimmer 2s infinite linear",animationDelay:"0.8s"}}),(0,n.jsx)("style",{children:"\n @keyframes shimmer {\n 0% { background-position: 200% 0; }\n 100% { background-position: -200% 0; }\n }\n "})]}):null}function U(e){let{guides:t,frames:r,scale:a,stagePosition:s}=e;return 0===t.length?null:(0,n.jsx)("div",{className:"absolute inset-0 pointer-events-none",style:{zIndex:50},children:t.map((e,t)=>{let l=r.find(t=>
1t.id===e.frameId);if(!l)return null;if("vertical"===e.type){let r=e.position*a+s.x,o=l.y*a+s.y,i=(l.y+l.height)*a+s.y;return(0,n.jsx)("div",{style:{position:"absolute",left:r,top:o,width:1,height:i-o,backgroundColor:"#ba1a1a",boxShadow:"0 0 4px #ba1a1a"}},"guide-".concat(t))}{let r=e.position*a+s.y,o=l.x*a+s.x,i=(l.x+l.width)*a+s.x;return(0,n.jsx)("div",{style:{position:"absolute",left:o,top:r,width:i-o,height:1,backgroundColor:"#ba1a1a",boxShadow:"0 0 4px #ba1a1a"}},"guide-".concat(t))}})})}function B(e){let{element:t,isSelected:r,onSelect:l,onChange:o,sandboxId:i,scale:c,stagePosition:d,authToken:u,isProcessing:h=!1,clipPath:m,frames:x=[],onSnapChange:p}=e,[f,g]=(0,a.useState)(null),[b,v]=(0,a.useState)(!0),[w,j]=(0,a.useState)(null),[y,N]=(0,a.useState)(null);(0,a.useEffect)(()=>{if(!t.src)return void v(!0);if(t.src.startsWith("data:")){g(t.src),v(!1);return}let e=!1,r=0;return(async()=>{let n=i?M(i,t.src):t.src,a={};for(u&&(a.Authorization="Bearer ".concat(u));r<5&&!e;)try{v(!0),j(null);let t=await fetch(n,{credentials:"include",headers:a});if(!t.ok){if((404===t.status||t.status>=500)&&r<4){r++,await new Promise(e=>setTimeout(e,500*r));continue}throw Error("HTTP ".concat(t.status))}let s=await t.blob();e||(g(URL.createObjectURL(s)),v(!1));return}catch(t){if(r<4&&!e){r++,await new Promise(e=>setTimeout(e,500*r));continue}e||(j(t instanceof Error?t.message:"Failed"),v(!1));return}})(),()=>{e=!0}},[t.src,i,u]);let _=t.x*c+d.x,E=t.y*c+d.y,k=t.width*c,C=t.height*c,S=function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"move",n=arguments.length>2?arguments[2]:void 0;t.locked&&"move"===r||(e.stopPropagation(),e.preventDefault(),l(e),N({type:r,handle:n,startX:e.clientX,startY:e.clientY,startElemX:t.x,startElemY:t.y,startWidth:t.width,startHeight:t.height}))};if((0,a.useEffect)(()=>{if(!y)return;let e=e=>{let r=(e.clientX-y.startX)/c,n=(e.clientY-y.startY)/c;if("move"===y.type){let e=y.startElemX+r,a=y.startElemY+n,{snapX:s,snapY:l,guides:i}=function(e,t,r,n){let a=null,s=null,l=[];for(let n of r){if(void 0===n.id)continue;let r=n.x+n.width/2,o=n.y+n.height/2;12>Math.abs(e-r)&&(a=r,l.push({type:"vertical",position:r,frameId:n.id})),12>Math.abs(t-o)&&(s=o,l.push({type:"horizontal",position:o,frameId:n.id}))}return{snapX:a,snapY:s,guides:l}}(e+t.width/2,a+t.height/2,x);null!==s&&(e=s-t.width/2),null!==l&&(a=l-t.height/2),null==p||p(i),o({x:e,y:a})}else if("resize"===y.type&&y.handle){let e=y.startWidth/y.startHeight,t=y.startElemX,a=y.startElemY,s=y.startWidth,l=y.startHeight;"se"===y.handle?Math.abs(r)>Math.abs(n)?l=(s=Math.max(50,y.startWidth+r))/e:s=(l=Math.max(50,y.startHeight+n))*e:"sw"===y.handle?(Math.abs(r)>Math.abs(n)?l=(s=Math.max(50,y.startWidth-r))/e:s=(l=Math.max(50,y.startHeight+n))*e,t=y.startElemX+(y.startWidth-s)):"ne"===y.handle?(Math.abs(r)>Math.abs(n)?l=(s=Math.max(50,y.startWidth+r))/e:s=(l=Math.max(50,y.startHeight-n))*e,a=y.startElemY+(y.startHeight-l)):"nw"===y.handle?(Math.abs(r)>Math.abs(n)?l=(s=Math.max(50,y.startWidth-r))/e:s=(l=Math.max(50,y.startHeight-n))*e,t=y.startElemX+(y.startWidth-s),a=y.startElemY+(y.startHeight-l)):"e"===y.handle?(l=(s=Math.max(50,y.startWidth+r))/e,a=y.startElemY+(y.startHeight-l)/2):"w"===y.handle?(l=(s=Math.max(50,y.startWidth-r))/e,t=y.startElemX+(y.startWidth-s),a=y.startElemY+(y.startHeight-l)/2):"s"===y.handle?(s=(l=Math.max(50,y.startHeight+n))*e,t=y.startElemX+(y.startWidth-s)/2):"n"===y.handle&&(s=(l=Math.max(50,y.startHeight-n))*e,t=y.startElemX+(y.startWidth-s)/2,a=y.startElemY+(y.startHeight-l)),o({x:t,y:a,width:s,height:l})}},r=()=>{N(null),null==p||p([])};return window.addEventListener("mousemove",e),window.addEventListener("mouseup",r),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",r)}},[y,c,o,x,t.width,t.height,p]),b)return(0,n.jsxs)("div",{style:{position:"absolute",left:_,top:E,width:k,height:C,zIndex:100},className:"rounded overflow-hidden bg-card/50",children:[(0,n.jsxs)("div",{className:"relative w-full h-full",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/30"}),(0,n.jsx)("div",{className:"absolute inset-0",style:{background:"linear-gradient(110deg, transparent 30%, rgba(255,255,255,0.15) 50%, transparent 70%)",backgroundSize:"200% 100%",animation:"shimmer 2s ease-in-out infinite"}})]}),(0,n.jsx)("style",{children:"\n @keyframes shimmer {\n 0% { background-position: 200% 0; }\n 100% { background-position: -200% 0; }\n }\n "})]});if(w||!f)return(0,n.jsxs)("div",{style:{position:"absolute",left:_,top:E,width:k,height:C},className:"flex flex-col items-center justify-center bg-card/30 rounded border border-dashed border-border",children:[(0,n.jsx)(s.default,{className:"h-5 w-5 text-muted-foreground mb-1"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"Failed"})]});let D=(null==y?void 0:y.type)==="move";return null==y||y.type,(0,n.jsxs)("div",{onMouseDown:e=>S(e,"move"),style:{position:"absolute",left:_,top:E,width:k,height:C,cursor:t.locked?"default":D?"grabbing":"grab",opacity:t.opacity||1,transform:"rotate(".concat(t.rotation||0,"deg)"),transformOrigin:"center center",zIndex:2},children:[(0,n.jsx)("div",{className:"w-full h-full rounded overflow-hidden relative",style:{clipPath:m||void 0}
1,children:(0,n.jsx)("img",{src:f,alt:t.name,draggable:!1,className:"w-full h-full object-fill pointer-events-none"})}),r&&(0,n.jsx)("div",{className:"absolute inset-0 rounded ring-2 ring-zinc-400 pointer-events-none",style:{zIndex:5}}),r&&!t.locked&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"absolute -top-1.5 -left-1.5 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-nwse-resize z-10",onMouseDown:e=>S(e,"resize","nw")}),(0,n.jsx)("div",{className:"absolute -top-1.5 -right-1.5 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-nesw-resize z-10",onMouseDown:e=>S(e,"resize","ne")}),(0,n.jsx)("div",{className:"absolute -bottom-1.5 -left-1.5 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-nesw-resize z-10",onMouseDown:e=>S(e,"resize","sw")}),(0,n.jsx)("div",{className:"absolute -bottom-1.5 -right-1.5 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-nwse-resize z-10",onMouseDown:e=>S(e,"resize","se")}),(0,n.jsx)("div",{className:"absolute top-1/2 -left-1.5 -translate-y-1/2 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-ew-resize z-10",onMouseDown:e=>S(e,"resize","w")}),(0,n.jsx)("div",{className:"absolute top-1/2 -right-1.5 -translate-y-1/2 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-ew-resize z-10",onMouseDown:e=>S(e,"resize","e")}),(0,n.jsx)("div",{className:"absolute -top-1.5 left-1/2 -translate-x-1/2 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-ns-resize z-10",onMouseDown:e=>S(e,"resize","n")}),(0,n.jsx)("div",{className:"absolute -bottom-1.5 left-1/2 -translate-x-1/2 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-ns-resize z-10",onMouseDown:e=>S(e,"resize","s")})]})]})}function F(e){let{element:t,isSelected:r,onSelect:s,onChange:o,scale:i,stagePosition:c,allElements:d,onMoveChildren:u}=e,[h,m]=(0,a.useState)(null),x=t.x*i+c.x,p=t.y*i+c.y,f=t.width*i,g=t.height*i,b=function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"move",n=arguments.length>2?arguments[2]:void 0;if(t.locked&&"move"===r)return;e.stopPropagation(),e.preventDefault(),s(e);let a=[],l=[];if("move"===r&&d){let e=t.x+t.width,r=t.y+t.height,n=d.filter(n=>{if(n.id===t.id||"frame"===n.type)return!1;let a=n.x+n.width,s=n.y+n.height;return n.x<e&&a>t.x&&n.y<r&&s>t.y});a=n.map(e=>e.id),l=n.map(e=>({id:e.id,x:e.x,y:e.y}))}m({type:r,handle:n,startX:e.clientX,startY:e.clientY,startElemX:t.x,startElemY:t.y,startWidth:t.width,startHeight:t.height,childIds:a,childStartPositions:l})};(0,a.useEffect)(()=>{if(!h)return;let e=e=>{let t=(e.clientX-h.startX)/i,r=(e.clientY-h.startY)/i;if("move"===h.type)o({x:h.startElemX+t,y:h.startElemY+r}),u&&h.childStartPositions&&h.childStartPositions.length>0&&u(h.childStartPositions,t,r);else if("resize"===h.type&&h.handle){let e=h.startElemX,n=h.startElemY,a=h.startWidth,s=h.startHeight;switch(h.handle){case"se":a=Math.max(100,h.startWidth+t),s=Math.max(100,h.startHeight+r);break;case"sw":a=Math.max(100,h.startWidth-t),s=Math.max(100,h.startHeight+r),e=h.startElemX+(h.startWidth-a);break;case"ne":a=Math.max(100,h.startWidth+t),s=Math.max(100,h.startHeight-r),n=h.startElemY+(h.startHeight-s);break;case"nw":a=Math.max(100,h.startWidth-t),s=Math.max(100,h.startHeight-r),e=h.startElemX+(h.startWidth-a),n=h.startElemY+(h.startHeight-s);break;case"e":a=Math.max(100,h.startWidth+t);break;case"w":a=Math.max(100,h.startWidth-t),e=h.startElemX+(h.startWidth-a);break;case"s":s=Math.max(100,h.startHeight+r);break;case"n":s=Math.max(100,h.startHeight-r),n=h.startElemY+(h.startHeight-s)}o({x:e,y:n,width:a,height:s})}},t=()=>m(null);return window.addEventListener("mousemove",e),window.addEventListener("mouseup",t),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",t)}},[h,i,o]);let v=(null==h?void 0:h.type)==="move";return(0,n.jsxs)("div",{style:{position:"absolute",left:x,top:p,width:f,height:g,opacity:t.opacity||1,transform:"rotate(".concat(t.rotation||0,"deg)"),transformOrigin:"center center",zIndex:10,pointerEvents:"none"},children:[(0,n.jsxs)("div",{className:"w-full h-full relative",style:{border:r?"2px solid #c5a381":"2px dashed #404040",borderRadius:"4px"},children:[(0,n.jsxs)("div",{className:"absolute left-0 flex items-center gap-1 px-1.5 py-0.5 rounded-t-sm",style:{to
1p:"-22px",backgroundColor:r?"#c5a381":"#333333",color:r?"#2d2926":"#fff",fontSize:"10px",cursor:t.locked?"default":v?"grabbing":"grab",pointerEvents:"auto"},onMouseDown:e=>b(e,"move"),children:[(0,n.jsx)(l.default,{className:"h-3 w-3"}),(0,n.jsx)("span",{className:"truncate max-w-[100px]",children:t.name})]}),r&&(0,n.jsxs)("div",{className:"absolute left-1/2 -translate-x-1/2 px-2 py-0.5 rounded-sm pointer-events-none",style:{bottom:"-24px",backgroundColor:"#75593c",color:"#fff",fontSize:"11px",fontFamily:"monospace",whiteSpace:"nowrap"},children:[Math.round(t.width)," \xd7 ",Math.round(t.height)]})]}),r&&!t.locked&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"absolute -top-1.5 -left-1.5 w-3 h-3 rounded-sm cursor-nwse-resize z-10",style:{pointerEvents:"auto",backgroundColor:"#fff",border:"2px solid #c5a381"},onMouseDown:e=>b(e,"resize","nw")}),(0,n.jsx)("div",{className:"absolute -top-1.5 -right-1.5 w-3 h-3 rounded-sm cursor-nesw-resize z-10",style:{pointerEvents:"auto",backgroundColor:"#fff",border:"2px solid #c5a381"},onMouseDown:e=>b(e,"resize","ne")}),(0,n.jsx)("div",{className:"absolute -bottom-1.5 -left-1.5 w-3 h-3 rounded-sm cursor-nesw-resize z-10",style:{pointerEvents:"auto",backgroundColor:"#fff",border:"2px solid #c5a381"},onMouseDown:e=>b(e,"resize","sw")}),(0,n.jsx)("div",{className:"absolute -bottom-1.5 -right-1.5 w-3 h-3 rounded-sm cursor-nwse-resize z-10",style:{pointerEvents:"auto",backgroundColor:"#fff",border:"2px solid #c5a381"},onMouseDown:e=>b(e,"resize","se")}),(0,n.jsx)("div",{className:"absolute top-1/2 -left-1.5 -translate-y-1/2 w-3 h-3 rounded-sm cursor-ew-resize z-10",style:{pointerEvents:"auto",backgroundColor:"#fff",border:"2px solid #c5a381"},onMouseDown:e=>b(e,"resize","w")}),(0,n.jsx)("div",{className:"absolute top-1/2 -right-1.5 -translate-y-1/2 w-3 h-3 rounded-sm cursor-ew-resize z-10",style:{pointerEvents:"auto",backgroundColor:"#fff",border:"2px solid #c5a381"},onMouseDown:e=>b(e,"resize","e")}),(0,n.jsx)("div",{className:"absolute -top-1.5 left-1/2 -translate-x-1/2 w-3 h-3 rounded-sm cursor-ns-resize z-10",style:{pointerEvents:"auto",backgroundColor:"#fff",border:"2px solid #c5a381"},onMouseDown:e=>b(e,"resize","n")}),(0,n.jsx)("div",{className:"absolute -bottom-1.5 left-1/2 -translate-x-1/2 w-3 h-3 rounded-sm cursor-ns-resize z-10",style:{pointerEvents:"auto",backgroundColor:"#fff",border:"2px solid #c5a381"},onMouseDown:e=>b(e,"resize","s")})]})]})}function O(e){let{element:t,scale:r,stagePosition:s,cropRect:l,onCropChange:o}=e,[i,c]=(0,a.useState)(null),d=t.x*r+s.x,u=t.y*r+s.y,h=t.width*r,m=t.height*r,x=d+l.x*h,p=u+l.y*m,f=l.width*h,g=l.height*m,b=(e,t,r)=>{e.stopPropagation(),e.preventDefault(),c({type:t,handle:r,startX:e.clientX,startY:e.clientY,startRect:{...l}})};return(0,a.useEffect)(()=>{if(!i)return;let e=e=>{let t=(e.clientX-i.startX)/h,r=(e.clientY-i.startY)/m;if("move"===i.type){let e=i.startRect.x+t,n=i.startRect.y+r;e=Math.max(0,Math.min(1-i.startRect.width,e)),n=Math.max(0,Math.min(1-i.startRect.height,n)),o({...i.startRect,x:e,y:n})}else if("resize"===i.type&&i.handle){let e=i.startRect.x,n=i.startRect.y,a=i.startRect.width,s=i.startRect.height;switch(i.handle){case"nw":e=Math.max(0,Math.min(i.startRect.x+i.startRect.width-.1,i.startRect.x+t)),n=Math.max(0,Math.min(i.startRect.y+i.startRect.height-.1,i.startRect.y+r)),a=i.startRect.width-(e-i.startRect.x),s=i.startRect.height-(n-i.startRect.y);break;case"ne":n=Math.max(0,Math.min(i.startRect.y+i.startRect.height-.1,i.startRect.y+r)),a=Math.max(.1,Math.min(1-i.startRect.x,i.startRect.width+t)),s=i.startRect.height-(n-i.startRect.y);break;case"sw":e=Math.max(0,Math.min(i.startRect.x+i.startRect.width-.1,i.startRect.x+t)),a=i.startRect.width-(e-i.startRect.x),s=Math.max(.1,Math.min(1-i.startRect.y,i.startRect.height+r));break;case"se":a=Math.max(.1,Math.min(1-i.startRect.x,i.startRect.width+t)),s=Math.max(.1,Math.min(1-i.startRect.y,i.startRect.height+r));break;case"n":n=Math.max(0,Math.min(i.startRect.y+i.startRect.height-.1,i.startRect.y+r)),s=i.startRect.height-(n-i.startRect.y);break;case"s":s=Math.max(.1,Math.min(1-i.startRect.y,i.startRect.height+r));break;case"w":e=Math.max(0,Math.min(i.startRect.x+i.startRect.width-.1,i.startRect.x+t)),a=i.startRect.width-(e-i.startRect.x);break;case"e":a=Math.max(.1,Math.min(1-i.startRect.x,i.startRect.width+t))}o({x:e,y:n,width:a,height:s})}},t=()=>c(null);return window.addEventListener("mousemove",e),window.addEventListener("mouseup",t),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",t)}},[i,h,m,o]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"absolute pointer-events-none z-30",style:{left:d,top:u,width:h,height:m},children:[(0,n.jsx)("div",{className:"absolute bg-black/50",style:{left:0,top:0,width:"100%",height:100*l.y+"%"}}),(0,n.jsx)("div",{className:"absolute bg-black/50",style:{left:0,bottom:0,width:"100%",height:(1-l.y-l.he
1ight)*100+"%"}}),(0,n.jsx)("div",{className:"absolute bg-black/50",style:{left:0,top:100*l.y+"%",width:100*l.x+"%",height:100*l.height+"%"}}),(0,n.jsx)("div",{className:"absolute bg-black/50",style:{right:0,top:100*l.y+"%",width:(1-l.x-l.width)*100+"%",height:100*l.height+"%"}})]}),(0,n.jsxs)("div",{className:"absolute border-2 border-zinc-400 cursor-move z-40",style:{left:x,top:p,width:f,height:g},onMouseDown:e=>b(e,"move"),children:[(0,n.jsx)("div",{className:"absolute -top-1.5 -left-1.5 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-nwse-resize z-10",onMouseDown:e=>b(e,"resize","nw")}),(0,n.jsx)("div",{className:"absolute -top-1.5 -right-1.5 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-nesw-resize z-10",onMouseDown:e=>b(e,"resize","ne")}),(0,n.jsx)("div",{className:"absolute -bottom-1.5 -left-1.5 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-nesw-resize z-10",onMouseDown:e=>b(e,"resize","sw")}),(0,n.jsx)("div",{className:"absolute -bottom-1.5 -right-1.5 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-nwse-resize z-10",onMouseDown:e=>b(e,"resize","se")}),(0,n.jsx)("div",{className:"absolute top-1/2 -left-1.5 -translate-y-1/2 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-ew-resize z-10",onMouseDown:e=>b(e,"resize","w")}),(0,n.jsx)("div",{className:"absolute top-1/2 -right-1.5 -translate-y-1/2 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-ew-resize z-10",onMouseDown:e=>b(e,"resize","e")}),(0,n.jsx)("div",{className:"absolute -top-1.5 left-1/2 -translate-x-1/2 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-ns-resize z-10",onMouseDown:e=>b(e,"resize","n")}),(0,n.jsx)("div",{className:"absolute -bottom-1.5 left-1/2 -translate-x-1/2 w-3 h-3 bg-white border-2 border-zinc-400 rounded-full cursor-ns-resize z-10",onMouseDown:e=>b(e,"resize","s")}),(0,n.jsx)("div",{className:"absolute top-1/3 left-0 right-0 border-t border-zinc-400/30"}),(0,n.jsx)("div",{className:"absolute top-2/3 left-0 right-0 border-t border-zinc-400/30"}),(0,n.jsx)("div",{className:"absolute left-1/3 top-0 bottom-0 border-l border-zinc-400/30"}),(0,n.jsx)("div",{className:"absolute left-2/3 top-0 bottom-0 border-l border-zinc-400/30"})]})]})}function W(e){let{element:t,scale:r,stagePosition:s,onChange:l,onDuplicate:m,onDelete:x,onDownloadPng:p,onDownloadSvg:f,onImageUpdate:g,onProcessingChange:b,onOcrProcessing:v,onTextEditStateChange:w,onTextRegionSelect:j,externalSelectedRegion:y,onCropStateChange:_,externalCropRect:I,onCropCreate:R,authToken:P,sandboxId:T}=e,[z,U]=(0,a.useState)(!1),[B,F]=(0,a.useState)(null),[O,W]=(0,a.useState)(""),[H,G]=(0,a.useState)(!1),[V,X]=(0,a.useState)(!1),[$,Y]=(0,a.useState)([]),[K,q]=(0,a.useState)(null),[Z,Q]=(0,a.useState)(""),[J,ee]=(0,a.useState)(null),[et,er]=(0,a.useState)(!1),[en,ea]=(0,a.useState)(!1),[es,el]=(0,a.useState)(!1),[eo,ei]=(0,a.useState)({x:.1,y:.1,width:.8,height:.8}),[ec,ed]=(0,a.useState)(!1);(0,a.useEffect)(()=>{y&&y.id!==(null==K?void 0:K.id)&&(q(y),Q(y.confidence>.6?y.text:""),er(!0))},[y]),(0,a.useEffect)(()=>{G(!1),X(!1),Y([]),q(null),Q(""),er(!1),ea(!1),w(null),el(!1),ei({x:.1,y:.1,width:.8,height:.8})},[t.id]);let eu=async()=>{X(!0),v(!0);try{let e=await ef(t.src),r=await fetch("".concat("https://api.rationalgo.ai/v1","/canvas-ai/ocr"),{method:"POST",headers:{"Content-Type":"application/json",...P?{Authorization:"Bearer ".concat(P)}:{}},body:JSON.stringify({image_base64:e})});if(!r.ok){let e=await r.text();throw Error(e||"OCR request failed")}let n=await r.json();if(!n.success)throw Error(n.error||"OCR failed");let[a,s]=n.image_size||[1024,1024];ee({width:a,height:s});let l=(n.text_lines||[]).map(e=>({id:e.id,text:e.text,confidence:e.confidence,bbox:e.bbox,polygon:e.polygon})),o=l.length>0?l.reduce((e,t)=>e+t.confidence,0)/l.length:0,i=l.filter(e=>e.confidence<.4).length,c=o<.35||l.length>0&&i/l.length>.7;0===l.length?(n.text||"").trim().length>0?(ea(!0),q(null),Q(""),er(!0),L.o.info("Opening text editor - describe the text you want to replace")):(L.o.warning("No text detected in this image"),G(!1)):c?(ea(!0),Y([]),w(null),q(null),Q(""),er(!0),L.o.info("Low OCR quality - describe the text you want to replace")):(ea(!1),Y(l),w({regions:l,ocrImageSize:{width:a,height:s}}),L.o.success("Found ".concat(l.length," text region").concat(l.length>
11?"s":"")))}catch(e){console.error("OCR error:",e),L.o.error("Failed to detect text: "+(e instanceof Error?e.message:"Unknown error")),G(!1)}finally{X(!1),v(!1)}},eh=()=>{G(!1),Y([]),q(null),Q(""),er(!1),ea(!1),w(null)},em=()=>{el(!1),ei({x:.1,y:.1,width:.8,height:.8}),_(null)},ex=async()=>{let e=I||eo;if(e&&!ec){ed(!0);try{let r=await ef(t.src),n=new Image;await new Promise((e,t)=>{n.onload=e,n.onerror=t,n.src=r});let a=Math.round(e.x*n.width),s=Math.round(e.y*n.height),l=Math.round(e.width*n.width),o=Math.round(e.height*n.height),i=document.createElement("canvas");i.width=l,i.height=o;let c=i.getContext("2d");if(!c)throw Error("Failed to get canvas context");c.drawImage(n,a,s,l,o,0,0,l,o);let d=i.toDataURL("image/png");R(d,t.width*e.width,t.height*e.height),L.o.success("Crop created!"),em()}catch(e){console.error("Crop error:",e),L.o.error("Failed to crop: "+(e instanceof Error?e.message:"Unknown error"))}finally{ed(!1)}}},ep=async()=>{let e;if(Z.trim()){if(er(!1),en)e="".concat(Z,". Keep the same font style, size, color, and position as the original text.");else if(K)if(K.confidence>.6)e='Replace the text "'.concat(K.text,'" with "').concat(Z,'" in this image. Keep the same font style, size, color, and position.');else{let[t,r,n,a]=K.bbox,s=(t+n)/2/((null==J?void 0:J.width)||1)*100,l=(r+a)/2/((null==J?void 0:J.height)||1)*100;e="Replace the text in the ".concat(l<33?"top":l>66?"bottom":"middle","-").concat(s<33?"left":s>66?"right":"center",' area of this image with "').concat(Z,'". Keep the same font style, size, color, and background.')}else e="".concat(Z,". Keep the same font style, size, color, and position.");await eg("edit_text",e),eh()}},ef=async e=>{if(e.startsWith("data:"))return e;let t=T?M(T,e):e;try{let e={};P&&(e.Authorization="Bearer ".concat(P));let r=await fetch(t,{headers:e,credentials:"include"});if(!r.ok)throw Error("Failed to fetch image: ".concat(r.status));let n=await r.blob();return new Promise((e,t)=>{let r=new FileReader;r.onloadend=()=>e(r.result),r.onerror=t,r.readAsDataURL(n)})}catch(e){throw console.error("Failed to convert image to base64:",e),Error("Could not load image for processing")}},eg=async(e,r)=>{U(!0),F(e),b(!0),L.o.info({upscale:"Upscaling image...",remove_bg:"Removing background...",edit_text:"Editing text...",mark_edit:"Applying edit..."}[e],{description:r||"Processing with AI..."});let n=!1;try{let a=await ef(t.src),s=await fetch("".concat("https://api.rationalgo.ai/v1","/canvas-ai/process"),{method:"POST",headers:{"Content-Type":"application/json",...P?{Authorization:"Bearer ".concat(P)}:{}},body:JSON.stringify({action:e,image_base64:a,prompt:r||void 0})});if(!s.ok){let e=await s.text();throw Error(e||"API request failed")}let l=await s.json();if(l.success&&l.image_base64)if(n=!0,"upscale"===e){let e=new Image;e.onload=()=>{g(l.image_base64,{width:e.naturalWidth,height:e.naturalHeight}),L.o.success("Upscaled to ".concat(e.naturalWidth,"\xd7").concat(e.naturalHeight,"!"))},e.onerror=()=>{g(l.image_base64),L.o.success("Upscale completed!")},e.src=l.image_base64}else g(l.image_base64),L.o.success("".concat(e.replace("_"," ")," completed!"));else L.o.error(l.error||"Processing failed",{description:l.message||"Please try again"})}catch(e){console.error("AI action error:",e),L.o.error("Failed to process image",{description:e instanceof Error?e.message:"Unknown error"})}finally{U(!1),F(null),W(""),b(!1,!n)}};return H?(0,n.jsxs)("div",{style:{position:"absolute",left:t.x*r+s.x+t.width*r/2,top:t.y*r+s.y+t.height*r+8,transform:"translateX(-50%)",zIndex:100},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 bg-card border border-border rounded-full px-3 py-1.5",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"Click on text to edit"}),(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-6 px-2 rounded-full text-xs",onClick:eh,children:[(0,n.jsx)(o.default,{className:"h-3 w-3 mr-1"}),"Cancel"]})]}),(0,n.jsx)(D.lG,{open:et,onOpenChange:er,children:(0,n.jsxs)(D.Cf,{className:"sm:max-w-sm p-0 gap-0",children:[(0,n.jsxs)(D.c7,{className:"px-4 pt-4 pb-3 border-b border-border",children:[(0,n.jsx)(D.L3,{className:"text-base font-medium",children:en?"Edit Text":"Replace text"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:en?"Describe what text to change and what to replace it with":K&&K.confidence<=60?"Type what text you want in this area":'Replacing: "'.concat((null==K?void 0:K.text)||"",'"')})]}),(0,n.jsxs)("div",{className:"p-4 space-y-3",children:[(0,n.jsx)(A.T,{value:Z,onChange:e=>Q(e.target.value),placeholder:en?"e.g., Replace 'Hello' with 'Welcome' or Change the title to 'New Title'":K&&K.confidence<=60?"Type the new text you want here...":"Enter replacement text...",className:"min-h-[100px]",autoF
1ocus:!0}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)(E.$,{variant:"outline",onClick:eh,children:"Cancel"}),(0,n.jsxs)(E.$,{onClick:ep,disabled:!Z.trim()||z,children:[z?(0,n.jsx)(N.RgoLoader,{customSize:22,className:"mr-2"}):null,en?"Apply":"Replace"]})]})]})]})})]}):es?(0,n.jsx)("div",{style:{position:"absolute",left:t.x*r+s.x+t.width*r/2,top:t.y*r+s.y+t.height*r+8,transform:"translateX(-50%)",zIndex:100},children:(0,n.jsxs)("div",{className:"flex items-center gap-2 bg-card border border-border rounded-full px-3 py-1.5",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"Select area"}),(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-6 px-2 rounded-full text-xs",onClick:em,disabled:ec,children:[(0,n.jsx)(o.default,{className:"h-3 w-3 mr-1"}),"Cancel"]}),(0,n.jsxs)(E.$,{size:"sm",className:"h-6 px-3 rounded-full text-xs",onClick:ex,disabled:ec,children:[ec?(0,n.jsx)(N.RgoLoader,{customSize:19,className:"mr-1"}):null,"Create"]})]})}):(0,n.jsxs)("div",{style:{position:"absolute",left:t.x*r+s.x+t.width*r/2,top:t.y*r+s.y+t.height*r+8,transform:"translateX(-50%)",zIndex:100},children:[(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 mb-1",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate max-w-[150px]",children:t.name}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[Math.round(t.width),"\xd7",Math.round(t.height)]})]}),(0,n.jsx)("div",{className:"flex items-center gap-0.5 bg-card border border-border rounded-full px-1.5 py-1",children:(0,n.jsxs)(k.Bc,{delayDuration:0,children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-7 px-2 rounded-full gap-1.5 text-xs",onClick:()=>eg("upscale"),disabled:z,children:["upscale"===B?(0,n.jsx)(N.RgoLoader,{customSize:22}):(0,n.jsx)("span",{className:"text-[10px] font-semibold border border-current rounded px-0.5",children:"HD"}),"Upscale"]})}),(0,n.jsx)(k.ZI,{children:"Upscale image with AI"})]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-7 px-2 rounded-full gap-1.5 text-xs",onClick:()=>eg("remove_bg"),disabled:z,children:["remove_bg"===B?(0,n.jsx)(N.RgoLoader,{customSize:22}):(0,n.jsxs)("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,n.jsx)("rect",{x:"1",y:"1",width:"6",height:"6"}),(0,n.jsx)("rect",{x:"9",y:"1",width:"6",height:"6",strokeDasharray:"2 1"}),(0,n.jsx)("rect",{x:"1",y:"9",width:"6",height:"6",strokeDasharray:"2 1"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"})]}),"Remove bg"]})}),(0,n.jsx)(k.ZI,{children:"Remove background with AI"})]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-7 px-2 rounded-full gap-1.5 text-xs",onClick:()=>{G(!0),Y([]),q(null),eu()},disabled:z||H,children:[V?(0,n.jsx)(N.RgoLoader,{customSize:22}):(0,n.jsx)(i.default,{className:"h-3.5 w-3.5"}),"Edit text"]})}),(0,n.jsx)(k.ZI,{children:"Select and edit text in image"})]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-7 px-2 rounded-full gap-1.5 text-xs",onClick:()=>{el(!0);let e={x:.1,y:.1,width:.8,height:.8};ei(e),_({cropRect:e})},disabled:z||es,children:[(0,n.jsx)(c.default,{className:"h-3.5 w-3.5"}),"Cut"]})}),(0,n.jsx)(k.ZI,{children:"Create cropped copy"})]}),(0,n.jsxs)(C.AM,{children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(C.Wv,{asChild:!0,children:(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-7 px-2 rounded-full gap-1.5 text-xs",disabled:z,children:["mark_edit"===B?(0,n.jsx)(N.RgoLoader,{customSize:22}):(0,n.jsxs)("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"12",height:"12",strokeDasharray:"3 2",rx:"1"}),(0,n.jsx)("path",{d:"M6 8L7.5 9.5L10 6",strokeLinecap:"round",strokeLinejoin:"round"})]}),"Edit"]})})}),(0,n.jsx)(k.ZI,{children:"AI-powered image editing"})]}),(0,n.jsx)(C.hl,{className:"w-80 p-3",align:"end",children:(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide",children:"AI Image Edit"}),(0,n.jsx)(A.T,{placeholder:"Describe the edit you want to make...",value:O,onChange:e=>W(e.target.value),className:"min-h-[80px] resize-none shadow-none",onKeyDown:e=>{"Enter"===e.key&&e.metaKey&&O.trim()&&eg("mark_edit",O)}}),(0,n.jsx)(E.$,{size:"sm",className:"w-full",onClick:()=>eg("mark_edit",O),disabled:!O.trim()||z,children:z?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(N.RgoLoader,{customSize:22,className:"mr-2"}),"Generating..."]}):"Generate"})]})})]}),(0,n.jsx)("div",{className:"w-px h-5 bg-border mx-0.5"}),(0,n.jsxs)(S.rI,{children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(S.ty,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full",children:(0,n.jsx)(d.default,{className:"h-3.5 w-3.5"})})})}),(0,n.jsx)(k.ZI,{children:"Download"})]}),(0,n.jsxs)(S.SQ,{align:"center",className:"min-w-[140px]",children:[(0,n.jsxs)(S._2,{onClick:p,className:"cursor-pointer",children:[(0,n.jsx)("span",{className:"font-medium",children:"PNG"}),(0,n.jsx)("span",{className:"ml-auto text-xs text-muted-foreground",children:"Default"})]}),(0,n.jsxs)(S._2,{onClick:f,className:"cursor-pointer",children:[(0,n.jsx)("span",{className:"font-medium",children:"SVG"}),(0,n.jsx)("span",{className:"ml-auto text-xs text-muted-foreground",children:"Vector"})]})]})]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full",onClick:m,children:(0,n.jsx)(u.default,{className:"h-3.5 w-3.5"})})}),(0,n.jsx)(k.ZI,{children:"Duplicate"})]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full text-destructive hover:text-destructive",onClick:x,children:(0,n.jsx)(h.default,{className:"h-3.5 w-3.5"})})}),(0,n.jsx)(k.ZI,{children:"Delete"})]})]})})]})}function H(e){let{element:t,elements:r,scale:s,stagePosition:i,onChange:c,onDuplicate:x,onDelete:p,onExportFrame:f,sandboxId:g,authToken:b}=e,[v,w]=(0,a.useState)(!1),[j,y]=(0,a.useState)(!1),[S,D]=(0,a.useState)(!1),[A,L]=(0,a.useState)(!1),[I,R]=(0,a.useState)(String(Math.round(t.width))),[P,T]=(0,a.useState)(String(Math.round(t.height))),[M,z]=(0,a.useState)(t.name);(0,a.useEffect)(()=>{R(String(Math.round(t.width))),T(String(Math.round(t.height))),z(t.name)},[t.width,t.height,t.name]);let U=()=>{c({width:Math.max(100,parseInt(I)||400),height:Math.max(100,parseInt(P)||300)}),y(!1)};return(0,n.jsx)("div",{style:{position:"absolute",left:t.x*s+i.x+t.width*s/2,top:t.y*s+i.y+t.height*s+8,transform:"translateX(-50%)",zIndex:100},children:(0,n.jsx)("div",{className:"flex items-center gap-0.5 bg-card border border-border rounded-full px-1.5 py-1",children:(0,n.jsxs)(k.Bc,{delayDuration:0,
1children:[(0,n.jsxs)(C.AM,{open:S,onOpenChange:D,children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(C.Wv,{asChild:!0,children:(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-7 px-2 rounded-full gap-1 text-xs",children:[(0,n.jsx)(l.default,{className:"h-3 w-3"}),(0,n.jsx)("span",{className:"truncate max-w-[80px]",children:t.name})]})})}),(0,n.jsx)(k.ZI,{children:"Rename frame"})]}),(0,n.jsx)(C.hl,{className:"w-auto p-3",align:"center",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-medium",children:"Frame Name"}),(0,n.jsx)("input",{type:"text",value:M,onChange:e=>z(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(c({name:M.trim()||"Frame"}),D(!1))},className:"w-40 h-7 px-2 text-xs bg-background border border-border rounded focus:outline-none focus:ring-1 focus:ring-zinc-400",autoFocus:!0}),(0,n.jsx)(E.$,{size:"sm",className:"w-full h-7 text-xs",onClick:()=>{c({name:M.trim()||"Frame"}),D(!1)},children:"Rename"})]})})]}),(0,n.jsx)("div",{className:"w-px h-5 bg-border mx-0.5"}),(0,n.jsxs)(C.AM,{open:j,onOpenChange:y,children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(C.Wv,{asChild:!0,children:(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-7 px-2 rounded-full gap-1 text-xs font-mono",children:[Math.round(t.width),"\xd7",Math.round(t.height)]})})}),(0,n.jsx)(k.ZI,{children:"Set dimensions"})]}),(0,n.jsx)(C.hl,{className:"w-auto p-3",align:"center",children:(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-medium",children:"Frame Size"}),(0,n.jsxs)(C.AM,{children:[(0,n.jsx)(C.Wv,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"sm",className:"h-5 px-1.5 text-[10px] text-muted-foreground",children:"Presets"})}),(0,n.jsx)(C.hl,{className:"w-48 p-1 max-h-64 overflow-y-auto",align:"end",side:"right",children:[{cat:"SOCIAL",items:[{n:"Instagram Post",w:1080,h:1080},{n:"Instagram Story",w:1080,h:1920},{n:"TikTok",w:1080,h:1920},{n:"Twitter Post",w:1200,h:675},{n:"Facebook Post",w:1200,h:630},{n:"YouTube Thumb",w:1280,h:720}]},{cat:"DEVICES",items:[{n:"iPhone 15 Pro",w:1179,h:2556},{n:"iPhone 15 Pro Max",w:1290,h:2796},{n:'iPad Pro 11"',w:1668,h:2388}]},{cat:"DESIGN",items:[{n:"Dribbble",w:400,h:300},{n:"Dribbble HD",w:800,h:600},{n:"Square",w:1e3,h:1e3}]}].map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-2 py-1 text-[10px] text-muted-foreground uppercase tracking-wider",children:e.cat}),e.items.map(e=>(0,n.jsxs)("button",{className:"w-full flex items-center justify-between px-2 py-1 text-xs hover:bg-accent rounded-lg text-left",onClick:()=>{R(String(e.w)),T(String(e.h))},children:[(0,n.jsx)("span",{children:e.n}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground font-mono",children:[e.w,"\xd7",e.h]})]},e.n))]},e.cat))})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("label",{className:"text-[10px] text-muted-foreground uppercase",children:"Width"}),(0,n.jsx)("input",{type:"number",value:I,onChange:e=>R(e.target.value),onKeyDown:e=>"Enter"===e.key&&U(),className:"w-20 h-7 px-2 text-xs bg-background border border-border rounded focus:outline-none focus:ring-1 focus:ring-zinc-400",min:100})]}),(0,n.jsx)(o.default,{className:"h-3 w-3 text-muted-foreground mt-4"}),(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("label",{className:"text-[10px] text-muted-foreground uppercase",children:"Height"}),(0,n.jsx)("input",{type:"number",value:P,onChange:e=>T(e.target.value),onKeyDown:e=>"Enter"===e.key&&U(),className:"w-20 h-7 px-2 text-xs bg-background border border-border rounded focus:outline-none focus:ring-1 focus:ring-zinc-400",min:100})]})]}),(0,n.jsx)(E.$,{size:"sm",className:"w-full h-7 text-xs",onClick:U,children:"Apply"})]})})]}),(0,n.jsx)("div",{className:"w-px h-5 bg-border mx-0.5"}),(0,n.jsxs)(C.AM,{open:v,onOpenChange:w,children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(C.Wv,{asChild:!0,children:(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-7 px-2 rounded-full gap-1.5 text-xs",children:[(0,n.jsx)("div",{className:"w-3.5 h-3.5 rounded-sm border border-border",style:{backgroundColor:t.backgroundColor||"transparent",backgroundImage:t.backgroundColor&&"transparent"!==t.backgroundColor?void 0:"linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(-45deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(-45deg, transparent 75%, #ccc 75%)",backgroundSize:"6px 6px",backgroundPosition:"0 0, 0 3px, 3px -3px, -3px 0px"}}),"Fill"]})})}
1),(0,n.jsx)(k.ZI,{children:"Background color"})]}),(0,n.jsx)(C.hl,{className:"w-auto p-2",align:"center",children:(0,n.jsxs)("div",{className:"grid grid-cols-6 gap-1",children:[["transparent","#ffffff","#000000","#f5f5f5","#1a1a1a","#ef4444","#f97316","#eab308","#22c55e","#3b82f6","#8b5cf6"].map(e=>(0,n.jsx)("button",{className:(0,_.cn)("w-6 h-6 rounded-sm border border-border hover:ring-2 hover:ring-zinc-400 transition-all",t.backgroundColor===e&&"ring-2 ring-zinc-400"),style:{backgroundColor:"transparent"===e?"transparent":e,backgroundImage:"transparent"===e?"linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(-45deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(-45deg, transparent 75%, #ccc 75%)":void 0,backgroundSize:"8px 8px",backgroundPosition:"0 0, 0 4px, 4px -4px, -4px 0px"},onClick:()=>{c({backgroundColor:"transparent"===e?void 0:e}),w(!1)}},e)),(0,n.jsxs)("label",{className:"w-6 h-6 rounded-sm border border-dashed border-muted-foreground hover:border-zinc-400 hover:ring-2 hover:ring-zinc-400 transition-all cursor-pointer flex items-center justify-center overflow-hidden relative bg-background",children:[(0,n.jsx)(m.default,{className:"h-3 w-3 text-muted-foreground"}),(0,n.jsx)("input",{type:"color",className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",value:t.backgroundColor||"#ffffff",onChange:e=>{c({backgroundColor:e.target.value})}})]})]})})]}),(0,n.jsx)("div",{className:"w-px h-5 bg-border mx-0.5"}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-7 px-2 rounded-full gap-1.5 text-xs",onClick:f,disabled:A,children:[A?(0,n.jsx)(N.RgoLoader,{customSize:22}):(0,n.jsx)(d.default,{className:"h-3.5 w-3.5"}),"Export"]})}),(0,n.jsx)(k.ZI,{children:"Export frame as PNG"})]}),(0,n.jsx)("div",{className:"w-px h-5 bg-border mx-0.5"}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full",onClick:x,children:(0,n.jsx)(u.default,{className:"h-3.5 w-3.5"})})}),(0,n.jsx)(k.ZI,{children:"Duplicate"})]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full text-destructive hover:text-destructive",onClick:p,children:(0,n.jsx)(h.default,{className:"h-3.5 w-3.5"})})}),(0,n.jsx)(k.ZI,{children:"Delete"})]})]})})})}function G(e){let{elements:t,scale:r,stagePosition:s,onStartMerge:l,onMergeComplete:o,onMergeFailed:i,onDelete:c,onProcessingChange:d,authToken:u,sandboxId:m}=e,[g,b]=(0,a.useState)(!1),[v,w]=(0,a.useState)(""),[j,y]=(0,a.useState)(!1),[_,C]=(0,a.useState)([]),S=_.map(e=>t.find(t=>t.id===e)).filter(e=>void 0!==e&&"image"===e.type),I=t.reduce((e,t)=>({minX:Math.min(e.minX,t.x),minY:Math.min(e.minY,t.y),maxX:Math.max(e.maxX,t.x+t.width),maxY:Math.max(e.maxY,t.y+t.height)}),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}),R=(I.minX+I.maxX)/2*r+s.x,P=I.maxY*r+s.y+8,T=async e=>{if(e.startsWith("data:"))return e;let t=m?M(m,e):e,r={};u&&(r.Authorization="Bearer ".concat(u));let n=await fetch(t,{headers:r,credentials:"include"});if(!n.ok)throw Error("Failed to fetch image: ".concat(n.status));let a=await n.blob();return new Promise((e,t)=>{let r=new FileReader;r.onloadend=()=>e(r.result),r.onerror=t,r.readAsDataURL(a)})},z=async()=>{if(!v.trim()||t.length<2)return;b(!0),d(!0);let e=l();L.o.info("Merging images...",{description:v});try{let t=await Promise.all(S.map(async e=>({id:e.id,base64:await T(e.src),width:e.width,height:e.height}))),r=await fetch("".concat("https://api.rationalgo.ai/v1","/canvas-ai/merge"),{method:"POST",headers:{"Content-Type":"application/json",...u?{Authorization:"Bearer ".concat(u)}:{}},body:JSON.stringify({images:t.map(e=>e.base64),prompt:v})});if(!r.ok){let e=await r.json();throw Error(e.detail||"Failed to merge images")}let n=await r.json();if(n.image)L.o.success("Images merged successfully!"),o(e,n.image);else throw Error("No image returned from merge")}catch(t){console.error("Merge error:",t),L.o.error("Failed to merge images",{description:t instanceof Error?t.message:"Unknown error"}),i(e)}finally{b(!1),w(""),d(!1)}};return(0,n.jsxs)("div",{style:{position:"absolute",left:R,top:P,transform:"translateX(-50%)",zIndex:100},children:[(0,n.jsx)("div",{className:"flex items-center justify-center gap-2 mb-1",children:(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[t.length," images selected"]})}),(0,n.jsx)("div",{className:"flex items-center gap-1 bg-card border border-border rounded-full px-2 py-1",children:(0,n.jsxs)(k.Bc,{delayDuration:0,
1children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsxs)(E.$,{variant:"ghost",size:"sm",className:"h-7 px-2 rounded-full gap-1.5 text-xs",disabled:g,onClick:()=>{C(t.map(e=>e.id)),y(!0)},children:[g?(0,n.jsx)(N.RgoLoader,{customSize:22}):(0,n.jsx)(x.default,{className:"h-3.5 w-3.5"}),"Merge"]})}),(0,n.jsx)(k.ZI,{children:"Merge selected images with AI"})]}),(0,n.jsx)("div",{className:"w-px h-4 bg-border mx-1"}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full text-destructive hover:text-destructive",onClick:c,disabled:g,children:(0,n.jsx)(h.default,{className:"h-3.5 w-3.5"})})}),(0,n.jsx)(k.ZI,{children:"Delete selected"})]})]})}),(0,n.jsx)(D.lG,{open:j,onOpenChange:y,children:(0,n.jsxs)(D.Cf,{className:"sm:max-w-md p-0 gap-0",children:[(0,n.jsx)(D.c7,{className:"px-4 pt-4 pb-3 border-b border-border",children:(0,n.jsx)(D.L3,{className:"text-base font-medium",children:"Merge images"})}),(0,n.jsxs)("div",{className:"p-4 space-y-3",children:[(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("label",{className:"text-xs font-medium text-muted-foreground",children:"Image order (click arrows to swap)"}),(0,n.jsx)("div",{className:"flex items-center gap-2 overflow-x-auto py-2",children:S.map((e,t)=>{var r,a;return(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsxs)("div",{className:"relative group",children:[(0,n.jsx)("div",{className:"w-16 h-16 rounded border border-border overflow-hidden bg-card shrink-0 relative",children:(null==(r=e.src)?void 0:r.startsWith("data:"))?(0,n.jsx)("img",{src:e.src,alt:e.name,className:"w-full h-full object-cover"}):(0,n.jsxs)("div",{className:"w-full h-full flex flex-col items-center justify-center text-xs text-muted-foreground p-1",children:[(0,n.jsx)(p.default,{className:"h-4 w-4 mb-0.5 opacity-50"}),(0,n.jsx)("span",{className:"truncate w-full text-center text-[10px]",children:(null==(a=e.name)?void 0:a.split("/").pop())||"Image ".concat(t+1)})]})}),(0,n.jsx)("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 bg-primary text-primary-foreground text-[10px] px-1.5 rounded-full",children:t+1})]}),t<S.length-1&&(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0",onClick:()=>{var e;return e=t+1,void C(r=>{let n=[...r];return[n[t],n[e]]=[n[e],n[t]],n})},title:"Swap with next",children:(0,n.jsx)(f.default,{className:"h-3 w-3"})})]},e.id)})})]}),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("label",{className:"text-xs font-medium text-muted-foreground",children:"How should these images be merged?"}),(0,n.jsx)(A.T,{value:v,onChange:e=>w(e.target.value),placeholder:'e.g. "Blend seamlessly", "Create a collage", "Overlay second on first"',className:"min-h-[80px]",autoFocus:!0})]}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)(E.$,{variant:"outline",onClick:()=>{y(!1),w("")},children:"Cancel"}),(0,n.jsxs)(E.$,{onClick:()=>{y(!1),z()},disabled:!v.trim()||g,children:[g?(0,n.jsx)(N.RgoLoader,{customSize:22,className:"mr-2"}):null,"Create"]})]})]})]})})]})}function V(e){let{content:t,filePath:r,fileName:s,sandboxId:o,className:i,onSave:c}=e,{session:d}=(0,I.A)(),u=(0,a.useRef)(null),h=(0,a.useRef)(null),[x,f]=(0,a.useState)([]),[S,D]=(0,a.useState)([]),[P,V]=(0,a.useState)(null),[X,$]=(0,a.useState)(null),Y=(0,a.useRef)(null),[K,q]=(0,a.useState)(null),[Z,Q]=(0,a.useState)(null),[J,ee]=(0,a.useState)(null),[et,er]=(0,a.useState)([]),[en,ea]=(0,a.useState)(null),[es,el]=(0,a.useState)(1),[eo,ei]=(0,a.useState)({x:50,y:50}),[ec,ed]=(0,a.useState)("select"),[eu,eh]=(0,a.useState)(!1),[em,ex]=(0,a.useState)(!1),[ep,ef]=(0,a.useState)({width:800,height:600}),[eg,eb]=(0,a.useState)(null),[ev,ew]=(0,a.useState)(!1),[ej,ey]=(0,a.useState)(!1),[eN,e_]=(0,a.useState)(""),[eE,ek]=(0,a.useState)(!1),[eC,eS]=(0,a.useState)([]),eD=(0,a.useRef)(null),eA=(0,a.useRef)(null),eL=(0,a.useRef)(!1),eI=(0,a.useRef)(!1),eR=null==d?void 0:d.accessToken,eP=(0,R.y3)(12e4),eT=(0,a.useMemo)(()=>x.filter(e=>"frame"===e.type),[x]);(0,a.useEffect)(()=>{eI.current=ev},[ev]),(0,a.useEffect)(()=>
1{if(!t){ea({name:s.replace(".rgocanvas",""),version:"1.0",background:"var(--background)",description:"",elements:[],created_at:new Date().toISOString(),updated_at:new Date().toISOString()}),f([]);return}try{var e;let r=JSON.parse(t),n=(r.elements||[]).length,a=x.length;en&&JSON.stringify(null==(e=r.elements)?void 0:e.map(e=>e.id))===JSON.stringify(x.map(e=>e.id))&&r.background===en.background||(ea(r),f(T(r.elements||[])),(!eL.current||n>a)&&(eL.current=!1))}catch(e){console.error("[CanvasRenderer] Parse error:",e,"Content:",null==t?void 0:t.substring(0,100)),en||(ea({name:s.replace(".rgocanvas",""),version:"1.0",background:"var(--background)",description:"",elements:[],created_at:new Date().toISOString(),updated_at:new Date().toISOString()}),f([]))}},[t,s]),(0,a.useEffect)(()=>{ex(!0)},[]),(0,a.useEffect)(()=>{if(!u.current)return;let e=()=>{u.current&&ef({width:u.current.offsetWidth,height:u.current.offsetHeight})},t=new ResizeObserver(e);return t.observe(u.current),e(),()=>t.disconnect()},[]);let eM=(0,a.useRef)(0),ez=(0,a.useRef)(!1),eU=(0,a.useRef)(x);(0,a.useEffect)(()=>{eU.current=x},[x]);let eB=(0,a.useCallback)(async()=>{let e=eG.current,t=ez.current;if(console.log("[CANVAS_LIVE_DEBUG] forceFetch called:",{sandboxId:o,filePath:r,hasAuth:!!eR,hasUnsaved:e,isEditing:t}),!o||!r||!eR)return void console.log("[CANVAS_LIVE_DEBUG] forceFetch skipped - missing required params");if(e||t)return void console.log("[CANVAS_LIVE_DEBUG] forceFetch skipped - user editing or unsaved changes");eM.current=Date.now();try{let e=M(o,r),t="".concat(e).concat(e.includes("?")?"&":"?","_t=").concat(Date.now());console.log("[CANVAS_LIVE_DEBUG] forceFetch fetching:",t);let a=await fetch(t,{headers:eR?{Authorization:"Bearer ".concat(eR)}:{},credentials:"include",cache:"no-store"});if(console.log("[CANVAS_LIVE_DEBUG] forceFetch response status:",a.status),!a.ok)return void console.log("[CANVAS_LIVE_DEBUG] forceFetch failed - bad response");let s=await a.text();if(console.log("[CANVAS_LIVE_DEBUG] forceFetch content length:",null==s?void 0:s.length),!s)return;try{var n;let e=JSON.parse(s),t=(null==(n=e.elements)?void 0:n.length)||0,r=eU.current.length,a=(e.elements||[]).map(e=>e.id).sort().join(","),l=eU.current.map(e=>e.id).sort().join(",");if(console.log("[CANVAS_LIVE_DEBUG] forceFetch comparing elements:",{serverCount:t,localCount:r,changed:a!==l,hasUnsavedNow:eG.current}),r>t)return void console.log("[CANVAS_LIVE_DEBUG] forceFetch SKIPPED - local has MORE elements (user added content)");a!==l?(console.log("[CANVAS_LIVE_DEBUG] forceFetch updating elements - CHANGE DETECTED!"),ea(e),f(T(e.elements||[])),t>r&&(eL.current=!1)):console.log("[CANVAS_LIVE_DEBUG] forceFetch - no changes detected")}catch(e){console.log("[CANVAS_LIVE_DEBUG] forceFetch parse error:",e)}}catch(e){console.log("[CANVAS_LIVE_DEBUG] forceFetch network error:",e)}},[o,r,eR]);(0,a.useEffect)(()=>{console.log("[CANVAS_LIVE_DEBUG] Setting up canvas-tool-updated listener for filePath:",r);let e=e=>{let t=e.detail.canvasPath;console.log("[CANVAS_LIVE_DEBUG] Received canvas-tool-updated event:",{eventPath:t,filePath:r,timestamp:e.detail.timestamp}),r&&(r.includes(t)||t.includes(r.replace("canvases/","")))?(console.log("[CANVAS_LIVE_DEBUG] Event matches our canvas, calling forceFetch"),eB()):console.log("[CANVAS_LIVE_DEBUG] Event does NOT match our canvas, ignoring")};window.addEventListener("canvas-tool-updated",e);let t=window.__pendingCanvasRefreshEvents;if(t&&r)for(let[e,n]of t.entries())if(Date.now()-n<1e4){if(r.includes(e)||e.includes(r.replace("canvases/","").replace("/workspace/",""))){console.log("[CANVAS_LIVE_DEBUG] Found pending event for our canvas, forcing fetch:",e),t.delete(e),eB();break}}else t.delete(e);return()=>{console.log("[CANVAS_LIVE_DEBUG] Removing canvas-tool-updated listener"),window.removeEventListener("canvas-tool-updated",e)}},[r,eB]),(0,a.useEffect)(()=>{if(!o||!r||!eR||!eP)return;let e=setInterval(async()=>{let e=eG.current,t=ez.current;if(e||t)return void console.log("[CANVAS_LIVE_DEBUG] Polling skipped - user editing or unsaved changes",{hasUnsaved:e,isEditing:t});let n=Date.now();if(!(n-eM.current<1300)){eM.current=n,console.log("[CANVAS_LIVE_DEBUG] Polling: fetching canvas content");try{let e=M(o,r),t="".concat(e).concat(e.includes("?")?"&":"?","_t=").concat(Date.now()),n=await fetch(t,{headers:eR?{Authorization:"Bearer ".concat(eR)}:{},credentials:"include",cache:"no-store"});if(!n.ok)return void console.log("[CANVAS_LIVE_DEBUG] Polling: fetch failed with status",n.status);let s=await n.text();if(!s)return;try{var a;let e=JSON.parse(s),t=(null==(a=e.elements)?void 0:a.length)||0,r=eU.current.length,n=(e.elements||[]).map(e=>e.id).sort().join(","),l=eU.current.map(e=>e.id).sort().join(",");if(console.log("[CANVAS_LIVE_DEBUG] Polling: comparing elements",{serverCount:t,localCount:r,changed:n!==l,hasUnsavedNow:eG.current}),r>t)return void console.log("[CANVAS_LIVE_DEBUG] Polling SKIPPED - local has MORE elements (user added content)");n!==l&&(console.log("[CANVAS_LIVE_DEBUG] Polling: UPDATING - new elements detected!"),ea(e),f(T(e.elements||[])),t>r&&(eL.current=!1))}catch(e){console.log("[CANVAS_LIVE_DEBUG] Polling: parse error",e)}}catch(e){console.log("[CANVAS_LIVE_DEBUG] Polling: network error",e)}}},1500);return()=>clearInterval(e)},[o,r,eR,eP]),(0,a.useEffect)(()=>
1{if(eL.current||0===x.length||0===ep.width||0===ep.height)return;let e=1/0,t=1/0,r=-1/0,n=-1/0;x.forEach(a=>{e=Math.min(e,a.x),t=Math.min(t,a.y),r=Math.max(r,a.x+a.width),n=Math.max(n,a.y+a.height)});let a=r-e,s=n-t,l=e+a/2,o=t+s/2,i=Math.max(Math.min(.8*ep.width/a,.8*ep.height/s,1),.15),c=ep.width/2-l*i,d=ep.height/2-o*i;el(i),ei({x:c,y:d}),eL.current=!0},[x,ep.width,ep.height]);let eF=(0,a.useRef)(es),eO=(0,a.useRef)(eo);(0,a.useEffect)(()=>{eF.current=es},[es]),(0,a.useEffect)(()=>{eO.current=eo},[eo]),(0,a.useEffect)(()=>{if(!em)return;let e=requestAnimationFrame(()=>{let e=u.current;if(!e)return void console.warn("Canvas container not found for wheel handler");let t=t=>{if(t.preventDefault(),t.stopPropagation(),t.ctrlKey||t.metaKey){let r=e.getBoundingClientRect(),n=t.clientX-r.left,a=t.clientY-r.top,s=eF.current,l=eO.current,o=Math.max(.1,Math.min(5,s*(1-.01*t.deltaY))),i=o/s,c=n-(n-l.x)*i,d=a-(a-l.y)*i;el(o),ei({x:c,y:d})}else ei(e=>({x:e.x-t.deltaX,y:e.y-t.deltaY}))};e.addEventListener("wheel",t,{passive:!1}),e._wheelHandler=t});return()=>{cancelAnimationFrame(e);let t=u.current;if(t){let e=t._wheelHandler;e&&t.removeEventListener("wheel",e)}}},[em]),(0,a.useEffect)(()=>{if(!eu&&!eg)return;let e=e=>{if(eu&&eD.current&&ei({x:eD.current.stageX+(e.clientX-eD.current.x),y:eD.current.stageY+(e.clientY-eD.current.y)}),eg&&eA.current){var t;let r=null==(t=u.current)?void 0:t.getBoundingClientRect();if(r){let t=e.clientX-r.left,n=e.clientY-r.top,a=Math.min(eA.current.x,t),s=Math.min(eA.current.y,n),l=Math.abs(t-eA.current.x),o=Math.abs(n-eA.current.y);eb({...eg,x:a,y:s,w:l,h:o})}}},t=()=>{if(eg&&eg.w>5&&eg.h>5){let e=[];x.forEach(t=>{let r=t.x*es+eo.x,n=t.y*es+eo.y,a=r+t.width*es,s=n+t.height*es;r<eg.x+eg.w&&a>eg.x&&n<eg.y+eg.h&&s>eg.y&&e.push(t.id)}),D(e)}eh(!1),eb(null),eD.current=null,eA.current=null};return window.addEventListener("mousemove",e),window.addEventListener("mouseup",t),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",t)}},[eu,eg,x,es,eo]);let eW=(e,t)=>{f(r=>r.map(r=>r.id===e?{...r,...t}:r))},eH=(e,t)=>{(null==t?void 0:t.shiftKey)?D(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]):D([e]),K&&K.elementId!==e&&q(null),J&&J.elementId!==e&&ee(null)},eG=(0,a.useRef)(!1);(0,a.useEffect)(()=>{if(en&&x.length>0){let t=JSON.stringify(x)!==JSON.stringify(T(en.elements||[]));if(t!==ej){var e;console.log("[CANVAS_LIVE_DEBUG] hasUnsavedChanges changed to:",t,{localCount:x.length,serverCount:(null==(e=en.elements)?void 0:e.length)||0})}ey(t),eG.current=t}},[x,en,ej]);let eV=(0,a.useCallback)((e,t)=>{if(0===x.length)return{x:(ep.width/2-eo.x)/es-e/2,y:(ep.height/2-eo.y)/es-t/2};let r=-1/0,n=0;return x.forEach(e=>{let t=e.x+e.width;t>r&&(r=t,n=e.y)}),{x:r+24,y:n}},[x,ep,eo,es]),eX=(0,a.useCallback)(async e=>{var t;if(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement)return;let r=null==(t=e.clipboardData)?void 0:t.items;if(r){for(let t of Array.from(r))if(t.type.startsWith("image/")){e.preventDefault();let r=t.getAsFile();if(!r)continue;ez.current=!0;let n=new FileReader;n.onload=e=>{var t;let r=new Image;r.onload=()=>{var t;let n=r.width,a=r.height;if(n>800||a>800){let e=Math.min(800/n,800/a);n=Math.round(n*e),a=Math.round(a*e)}let{x:s,y:l}=eV(n,a),o={id:"img-".concat(Date.now()),type:"image",src:null==(t=e.target)?void 0:t.result,x:s,y:l,width:n,height:a,rotation:0,scaleX:1,scaleY:1,opacity:1,locked:!1,name:"pasted-image-".concat(Date.now(),".png")};f(e=>[...e,o]),ey(!0),L.o.success("Image pasted"),setTimeout(()=>{ez.current=!1},500)},r.src=null==(t=e.target)?void 0:t.result},n.readAsDataURL(r);break}}},[eV]);(0,a.useEffect)(()=>{let e=e=>{if(!(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement)){if((e.metaKey||e.ctrlKey)&&"s"===e.key){if(e.preventDefault(),!eI.current){var t;null==(t=document.getElementById("canvas-save-btn"))||t.click()}return}if("v"===e.key.toLowerCase()&&!e.metaKey&&!e.ctrlKey)return void ed("select");switch(e.key.toLowerCase()){case"h":ed("pan");break;case"escape":D([]),q(null),Q(null),ee(null);break;case"delete":case"backspace":S.length>0&&(f(e=>e.filter(e=>!S.includes(e.id))),D([]),q(null),Q(null),ee(null))}}};return window.addEventListener("keydown",e),window.addEventListener("paste",eX),()=>{window.removeEventListener("keydown",e),window.removeEventListener("paste",eX)}},[S,eX]);let e$=(0,a.useCallback)(async()=>
1{if(!en||!c)return void L.o.error("Cannot save - missing data or save handler");ew(!0);try{let e={...en,elements:x};await c(JSON.stringify(e,null,2)),ea(e),ey(!1),L.o.success("Canvas saved")}catch(e){console.error("Save error:",e),L.o.error("Failed to save canvas")}finally{ew(!1)}},[en,x,c]),eY=(0,a.useMemo)(()=>[{category:"Social Media",items:[{name:"Instagram Post",width:1080,height:1080},{name:"Instagram Story",width:1080,height:1920},{name:"Instagram Reel",width:1080,height:1920},{name:"TikTok",width:1080,height:1920},{name:"Twitter Post",width:1200,height:675},{name:"Twitter Header",width:1500,height:500},{name:"Facebook Post",width:1200,height:630},{name:"Facebook Cover",width:820,height:312},{name:"LinkedIn Post",width:1200,height:627},{name:"LinkedIn Cover",width:1584,height:396},{name:"Pinterest Pin",width:1e3,height:1500},{name:"YouTube Thumbnail",width:1280,height:720},{name:"YouTube Shorts",width:1080,height:1920}]},{category:"Devices",items:[{name:"iPhone 15 Pro Max",width:1290,height:2796},{name:"iPhone 15 Pro",width:1179,height:2556},{name:"iPhone 15",width:1179,height:2556},{name:"iPhone 14",width:1170,height:2532},{name:"iPhone SE",width:750,height:1334},{name:'iPad Pro 12.9"',width:2048,height:2732},{name:'iPad Pro 11"',width:1668,height:2388},{name:"Android Phone",width:1080,height:2400}]},{category:"Design",items:[{name:"Dribbble Shot",width:400,height:300},{name:"Dribbble Shot HD",width:800,height:600},{name:"Behance Project",width:1400,height:788},{name:"App Icon",width:1024,height:1024},{name:"Favicon",width:512,height:512},{name:"Open Graph",width:1200,height:630}]},{category:"Print",items:[{name:"Business Card",width:1050,height:600},{name:"Poster 18\xd724",width:1800,height:2400},{name:"A4",width:2480,height:3508},{name:"Square",width:1e3,height:1e3}]}],[]),eK=(0,a.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:400,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:300,r=arguments.length>2?arguments[2]:void 0,{x:n,y:a}=eV(e,t),s=x.filter(e=>"frame"===e.type).length+1,l={id:"frame-".concat(Date.now()),type:"frame",x:n,y:a,width:e,height:t,rotation:0,opacity:1,locked:!1,visible:!0,name:r||"Frame ".concat(s),backgroundColor:void 0};f(e=>[...e,l]),D([l.id]),L.o.success("Frame added")},[x,eV]),eq=async e=>{var t;let r=null==(t=e.target.files)?void 0:t[0];if(!r)return;let n=new FileReader;n.onload=e=>{var t;let n=new Image;n.onload=()=>{var t;let a=n.width,s=n.height;if(a>800||s>800){let e=Math.min(800/a,800/s);a=Math.round(a*e),s=Math.round(s*e)}let{x:l,y:o}=eV(a,s),i={id:"img-".concat(Date.now()),type:"image",src:null==(t=e.target)?void 0:t.result,x:l,y:o,width:a,height:s,rotation:0,scaleX:1,scaleY:1,opacity:1,locked:!1,name:r.name};f(e=>[...e,i]),L.o.success("Added ".concat(r.name))},n.src=null==(t=e.target)?void 0:t.result},n.readAsDataURL(r),h.current&&(h.current.value="")},eZ=async()=>{if(eN.trim()){ek(!0),eS([]);try{var e;let t=await fetch("".concat("https://api.rationalgo.ai/v1","/canvas-ai/generate"),{method:"POST",headers:{"Content-Type":"application/json",...eR?{Authorization:"Bearer ".concat(eR)}:{}},body:JSON.stringify({prompt:eN,num_images:2,aspect_ratio:"1:1"})});if(!t.ok){let e=await t.text();throw Error(e||"Generation failed")}let r=await t.json();r.success&&(null==(e=r.images)?void 0:e.length)>0?(eS(r.images),L.o.success("Generated ".concat(r.images.length," images!"))):L.o.error(r.error||"Failed to generate images")}catch(e){console.error("AI generate error:",e),L.o.error("Failed to generate images: "+(e instanceof Error?e.message:"Unknown error"))}finally{ek(!1)}}};if(!em)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full w-full bg-transparent",children:(0,n.jsx)(N.RgoLoader,{size:"medium"})});if(!t&&!en)return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full w-full gap-4 bg-transparent",children:[(0,n.jsx)(N.RgoLoader,{size:"medium"}),(0,n.jsx)("div",{className:"text-muted-foreground text-center text-sm",children:"Loading canvas..."})]});let eQ=1===S.length?x.find(e=>e.id===S[0]):null;return(0,n.jsxs)("div",{className:(0,_.cn)("flex flex-col h-full w-full bg-background",i),style:(null==en?void 0:en.background)?{backgroundColor:en.background}:void 0,children:[(0,n.jsx)("input",{ref:h,type:"file",accept:"image/*",className:"hidden",onChange:eq}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border bg-card shrink-0",children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsxs)(k.Bc,{delayDuration:0,
1children:[(0,n.jsxs)("div",{className:"flex items-center border border-border rounded-full px-1 py-0.5",children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:(0,_.cn)("h-7 w-7 rounded-full","select"===ec&&"bg-primary text-primary-foreground"),onClick:()=>ed("select"),children:(0,n.jsx)(g.default,{className:"h-4 w-4"})})}),(0,n.jsx)(k.ZI,{children:"Select (V)"})]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:(0,_.cn)("h-7 w-7 rounded-full","pan"===ec&&"bg-primary text-primary-foreground"),onClick:()=>ed("pan"),children:(0,n.jsx)(b.default,{className:"h-4 w-4"})})}),(0,n.jsx)(k.ZI,{children:"Pan (H)"})]})]}),(0,n.jsxs)("div",{className:"flex items-center border border-border rounded-full px-1 py-0.5",children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full",onClick:()=>el(e=>Math.max(e/1.15,.1)),children:(0,n.jsx)(v.default,{className:"h-4 w-4"})})}),(0,n.jsx)(k.ZI,{children:"Zoom Out"})]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground px-2 min-w-12 text-center",children:[Math.round(100*es),"%"]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full",onClick:()=>el(e=>Math.min(1.15*e,5)),children:(0,n.jsx)(m.default,{className:"h-4 w-4"})})}),(0,n.jsx)(k.ZI,{children:"Zoom In"})]})]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>{el(1),eL.current=!1},children:(0,n.jsx)(w.default,{className:"h-4 w-4"})})}),(0,n.jsx)(k.ZI,{children:"Reset View"})]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsxs)(E.$,{id:"canvas-save-btn",variant:"ghost",size:"icon",className:(0,_.cn)("h-8 w-8 relative",ej&&"text-primary"),onClick:e$,disabled:ev||!c,children:[ev?(0,n.jsx)(N.RgoLoader,{customSize:22}):(0,n.jsx)(j.default,{className:"h-4 w-4"}),ej&&(0,n.jsx)("span",{className:"absolute top-0.5 right-0.5 w-2 h-2 bg-primary rounded-full"})]})}),(0,n.jsx)(k.ZI,{children:ev?"Saving...":ej?"Save changes (âS)":"No changes"})]}),(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>{var e;return null==(e=h.current)?void 0:e.click()},children:(0,n.jsx)(p.default,{className:"h-4 w-4"})})}),(0,n.jsx)(k.ZI,{children:"Add Image"})]}),(0,n.jsxs)(C.AM,{children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(C.Wv,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-8 w-8",children:(0,n.jsx)(l.default,{className:"h-4 w-4"})})})}),(0,n.jsx)(k.ZI,{children:"Add Frame"})]}),(0,n.jsxs)(C.hl,{className:"w-56 p-1 max-h-96 overflow-y-auto",align:"start",children:[(0,n.jsx)("button",{className:"w-full flex items-center px-2 py-1.5 text-sm hover:bg-accent rounded-lg transition-colors text-left mb-1",onClick:()=>eK(400,300),children:"Custom"}),eY.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-2 py-1 text-[10px] text-muted-foreground uppercase tracking-wider",children:e.category}),e.items.map(e=>(0,n.jsxs)("button",{className:"w-full flex items-center justify-between px-2 py-1.5 text-sm hover:bg-accent rounded-lg transition-colors text-left",onClick:()=>eK(e.width,e.height,e.name),children:[(0,n.jsx)("span",{children:e.name}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground font-mono",children:[e.width,"\xd7",e.height]})]},e.name))]},e.category))]})]}),(0,n.jsxs)(C.AM,{children:[(0,n.jsxs)(k.m_,{children:[(0,n.jsx)(k.k$,{asChild:!0,children:(0,n.jsx)(C.Wv,{asChild:!0,children:(0,n.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-8 w-8",children:(0,n.jsx)(y.default,{className:"h-4 w-4"})})})}),(0,n.jsx)(k.ZI,{children:"Generate with AI"})]}),(0,n.jsx)(C.hl,{className:"w-80 p-3",align:"end",children:(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide",children:"Qu
1ick Image Generation"}),(0,n.jsx)(A.T,{placeholder:"Describe the image you want to create...",value:eN,onChange:e=>e_(e.target.value),className:"min-h-[80px] resize-none shadow-none",onKeyDown:e=>{"Enter"===e.key&&e.metaKey&&eN.trim()&&eZ()}}),(0,n.jsx)(E.$,{size:"sm",className:"w-full",onClick:eZ,disabled:!eN.trim()||eE,children:eE?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(N.RgoLoader,{customSize:22,className:"mr-2"}),"Generating..."]}):"Generate"}),eC.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-2 gap-2 pt-2",children:eC.map((e,t)=>(0,n.jsxs)("div",{onClick:()=>(e=>{let t=new Image;t.onload=()=>{let r=t.width,n=t.height;if(r>512||n>512){let e=Math.min(512/r,512/n);r=Math.round(r*e),n=Math.round(n*e)}let{x:a,y:s}=eV(r,n),l={id:"img-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,8)),type:"image",src:e,x:a,y:s,width:r,height:n,rotation:0,scaleX:1,scaleY:1,opacity:1,locked:!1,name:"generated-".concat(Date.now(),".webp")};f(e=>[...e,l]),L.o.success("Added to canvas")},t.src=e})(e),style:{borderColor:"var(--border)"},className:"relative aspect-square rounded-lg overflow-hidden border outline-none transition-colors group cursor-pointer",children:[(0,n.jsx)("img",{src:e,alt:"Generated ".concat(t+1),className:"w-full h-full object-cover"}),(0,n.jsx)("div",{className:"absolute top-1 right-1 w-5 h-5 rounded-full bg-primary text-primary-foreground flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsx)(m.default,{className:"h-3 w-3"})})]},t))})]})})]})]})}),(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:(null==en?void 0:en.name)||(null==s?void 0:s.replace(".rgocanvas",""))})]}),(0,n.jsxs)("div",{ref:u,className:"flex-1 relative overflow-hidden bg-background",style:{cursor:eu?"grabbing":"pan"===ec?"grab":eg?"crosshair":"default",touchAction:"none"},onMouseDown:e=>{if(e.target===e.currentTarget){if("pan"===ec||1===e.button)eh(!0),eD.current={x:e.clientX,y:e.clientY,stageX:eo.x,stageY:eo.y};else if("select"===ec){var t;D([]),q(null),Q(null),ee(null);let r=null==(t=u.current)?void 0:t.getBoundingClientRect();if(r){let t=e.clientX-r.left,n=e.clientY-r.top;eA.current={x:t,y:n},eb({startX:t,startY:n,x:t,y:n,w:0,h:0})}}}},children:[(0,n.jsx)("div",{className:"absolute inset-0 pointer-events-none",style:{backgroundImage:"linear-gradient(var(--foreground) 1px, transparent 1px), linear-gradient(90deg, var(--foreground) 1px, transparent 1px)",backgroundSize:"".concat(50*es,"px ").concat(50*es,"px"),backgroundPosition:"".concat(eo.x,"px ").concat(eo.y,"px"),opacity:.02}}),0===x.length&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:(0,n.jsxs)("div",{className:"text-center text-muted-foreground",children:[(0,n.jsx)(p.default,{className:"h-16 w-16 mx-auto mb-4 opacity-50"}),(0,n.jsx)("p",{className:"text-lg font-medium",children:"Canvas is empty"}),(0,n.jsx)("p",{className:"text-sm mt-1",children:"Add images to get started"})]})}),(()=>{let e=x.filter(e=>"frame"===e.type),t=x.filter(e=>"image"===e.type);return(0,n.jsxs)(n.Fragment,{children:[e.map(e=>(0,n.jsx)("div",{style:{position:"absolute",left:e.x*es+eo.x,top:e.y*es+eo.y,width:e.width*es,height:e.height*es,backgroundColor:e.backgroundColor||"transparent",borderRadius:"4px",zIndex:1,pointerEvents:"none"}},"frame-bg-".concat(e.id))),t.map(t=>{let r=(t=>{for(let r of e){let e=t.x+t.width,n=t.y+t.height,a=r.x+r.width,s=r.y+r.height;if(t.x<a&&e>r.x&&t.y<s&&n>r.y)return r}return null})(t),a=r?((e,t)=>{let r=e.x*es+eo.x,n=e.y*es+eo.y,a=e.width*es,s=e.height*es,l=t.x*es+eo.x,o=t.y*es+eo.y,i=t.width*es,c=t.height*es,d=Math.max(0,(l-r)/a*100),u=Math.max(0,(o-n)/s*100),h=Math.min(100,(l+i-r)/a*100),m=Math.min(100,(o+c-n)/s*100);return"polygon(".concat(d,"% ").concat(u,"%, ").concat(h,"% ").concat(u,"%, ").concat(h,"% ").concat(m,"%, ").concat(d,"% ").concat(m,"%)")})(t,r):void 0;return(0,n.jsx)(B,{element:t,isSelected:S.includes(t.id),onSelect:e=>eH(t.id,e),onChange:e=>eW(t.id,e),authToken:eR,sandboxId:o,scale:es,stagePosition:eo,isProcessing:P===t.id,clipPath:a,frames:e,onSnapChange:er},t.id)}),e.map(e=>(0,n.jsx)(F,{element:e,isSelected:S.includes(e.id),onSelect:t=>eH(e.id,t),onChange:t=>eW(e.id,t),scale:es,stagePosition:eo,allElements:x,onMoveChildren:(e,t,r)=>{f(n=>n.map(n=>{let a=e.find(e=>e.id===n.id);return a?{...n,x:a.x+t,y:a.y+r}:n}))}},e.id))]})})(),P&&(()=>{let e=x.find(e=>e.id===P);if(!e||"image"!==e.type)return null;let t=x.filter(e=>"frame"===e.type),r=null;for(let n of t){let t=e.x+e.width,a=e.y+e.height,s=n.x+n.width,l=n.y+n.height;if(e.x<s&&t>n.x&&e.y<l&&a>n.y){r=n;break}}let a=r||e,s=a.x*es+eo.x,l=a.y*es+eo.y,o=a.width*es,i=a.height*es;
1return console.log("[SHIMMER_DEBUG] Showing shimmer on:",{processingId:P,showingOn:r?"FRAME":"IMAGE",frameId:null==r?void 0:r.id,posX:s,posY:l,width:o,height:i}),(0,n.jsx)("div",{style:{position:"absolute",left:s,top:l,width:o,height:i,borderRadius:"4px",overflow:"hidden",zIndex:9999,pointerEvents:"none"},children:(0,n.jsx)(z,{isVisible:!0})},"shimmer-".concat(P))})(),(0,n.jsx)(U,{guides:et,frames:eT,scale:es,stagePosition:eo}),J&&1===S.length&&(()=>{let e=x.find(e=>e.id===J.elementId);return e?(0,n.jsx)(O,{element:e,scale:es,stagePosition:eo,cropRect:J.cropRect,onCropChange:e=>{ee({elementId:J.elementId,cropRect:e})}}):null})(),K&&1===S.length&&(()=>{let e,t,r,a,s=x.find(e=>e.id===K.elementId);if(!s)return null;let l=s.width,o=s.height,i=K.ocrImageSize.width,c=K.ocrImageSize.height,d=i/c;d>l/o?(e=l,r=0,a=(o-(t=l/d))/2):(t=o,r=(l-(e=o*d))/2,a=0);let u=(s.x+r)*es+eo.x,h=(s.y+a)*es+eo.y,m=e*es,p=t*es,f=m/i,g=p/c;return(0,n.jsx)("svg",{className:"absolute pointer-events-none z-50",style:{left:u,top:h,width:m,height:p}
1,viewBox:"0 0 ".concat(i," ").concat(c),preserveAspectRatio:"none",children:K.regions.map(e=>{let t=(null==Z?void 0:Z.id)===e.id,r=e.polygon;if(!r||r.length<4)return null;let a=r.map(e=>{let[t,r]=e;return"".concat(t,",").concat(r)}).join(" ");return(0,n.jsx)("polygon",{points:a,className:(0,_.cn)("cursor-pointer transition-all pointer-events-auto",t?"fill-zinc-500/20 stroke-zinc-500":"fill-transparent stroke-zinc-400/50 hover:stroke-zinc-500 hover:fill-zinc-500/10"),style:{strokeWidth:2/Math.min(f,g)},onClick:()=>Q(e),children:(0,n.jsx)("title",{children:e.text})},e.id)})})})(),eg&&eg.w>0&&eg.h>0&&(0,n.jsx)("div",{className:"absolute border border-dashed border-zinc-400 bg-zinc-400/10 pointer-events-none",style:{left:eg.x,top:eg.y,width:eg.w,height:eg.h}}),1===S.length&&eQ&&"image"===eQ.type&&(0,n.jsx)(W,{element:eQ,scale:es,stagePosition:eo,onChange:e=>eW(eQ.id,e),onDuplicate:()=>{let e={...eQ,id:"img-".concat(Date.now()),x:eQ.x+eQ.width+24,y:eQ.y};f(t=>[...t,e]),D([e.id])},onDelete:()=>{f(e=>e.filter(e=>e.id!==eQ.id)),D([]),q(null),Q(null),ee(null)},onDownloadPng:()=>{if(eQ.src.startsWith("data:")){let e=document.createElement("a");e.href=eQ.src,e.download=(eQ.name||"image").replace(/\.[^.]+$/,"")+".png",e.click()}else L.o.info("Downloading from sandbox...")},onDownloadSvg:async()=>
1{try{L.o.info("Converting to SVG...");let e=eQ.src;if(!e.startsWith("data:"))return void L.o.error("SVG conversion requires base64 image data");let t=await fetch("".concat("https://api.rationalgo.ai/v1","/canvas-ai/convert-svg"),{method:"POST",headers:{"Content-Type":"application/json",...eR?{Authorization:"Bearer ".concat(eR)}:{}},body:JSON.stringify({image_base64:e,colormode:"color",mode:"spline"})});if(!t.ok){let e=await t.text();throw Error(e||"SVG conversion failed")}let r=await t.json();if(r.success&&r.svg){let e=new Blob([r.svg],{type:"image/svg+xml"}),t=URL.createObjectURL(e),n=document.createElement("a");n.href=t,n.download=(eQ.name||"image").replace(/\.[^.]+$/,"")+".svg",n.click(),URL.revokeObjectURL(t),L.o.success("SVG downloaded!")}else L.o.error(r.error||"SVG conversion failed")}catch(e){console.error("SVG conversion error:",e),L.o.error("Failed to convert to SVG: "+(e instanceof Error?e.message:"Unknown error"))}},onImageUpdate:(e,t)=>{let r=(null==t?void 0:t.width)||eQ.width,n=(null==t?void 0:t.height)||eQ.height,a=Y.current;a&&(f(t=>t.map(t=>t.id===a?{...t,src:e,width:r,height:n,locked:!1,name:t.name.replace("_processing","_processed")}:t)),D([a]),Y.current=null,$(null),V(null))},onProcessingChange:function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e){let e="placeholder-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,8)),t={id:e,type:"image",src:"",x:eQ.x+eQ.width+20,y:eQ.y,width:eQ.width,height:eQ.height,rotation:0,scaleX:1,scaleY:1,opacity:1,locked:!0,visible:!0,name:"".concat(eQ.name,"_processing")};f(e=>[...e,t]),Y.current=e,$(e),V(e)}else if(t){let e=Y.current;e&&f(t=>t.filter(t=>t.id!==e)),Y.current=null,$(null),V(null)}},onOcrProcessing:e=>{V(e?eQ.id:null)},onTextEditStateChange:e=>{e?q({elementId:eQ.id,regions:e.regions,ocrImageSize:e.ocrImageSize}):(q(null),Q(null))},onTextRegionSelect:e=>Q(e),externalSelectedRegion:Z,onCropStateChange:e=>{e?ee({elementId:eQ.id,cropRect:e.cropRect}):ee(null)},externalCropRect:(null==J?void 0:J.elementId)===eQ.id?J.cropRect:null,onCropCreate:(e,t,r)=>{let n={id:"img-".concat(Date.now()),type:"image",src:e,x:eQ.x+eQ.width+24,y:eQ.y,width:t,height:r,rotation:0,scaleX:1,scaleY:1,opacity:1,locked:!1,visible:!0,name:"".concat(eQ.name.replace(/\.[^.]+$/,""),"_crop.png")};f(e=>[...e,n]),D([n.id]),ee(null)},authToken:eR,sandboxId:o}),1===S.length&&eQ&&"frame"===eQ.type&&(0,n.jsx)(H,{element:eQ,elements:x,scale:es,stagePosition:eo,onChange:e=>eW(eQ.id,e),onDuplicate:()=>{let e={...eQ,id:"frame-".concat(Date.now()),x:eQ.x+eQ.width+24};f(t=>[...t,e]),D([e.id])},onDelete:()=>{f(e=>e.filter(e=>e.id!==eQ.id)),D([])},onExportFrame:async()=>
1{try{L.o.info("Exporting frame...");let e=document.createElement("canvas");e.width=Math.round(eQ.width),e.height=Math.round(eQ.height);let t=e.getContext("2d");if(!t)throw Error("Failed to get canvas context");eQ.backgroundColor&&"transparent"!==eQ.backgroundColor&&(t.fillStyle=eQ.backgroundColor,t.fillRect(0,0,e.width,e.height));let r=eQ.x,n=eQ.y,a=eQ.x+eQ.width,s=eQ.y+eQ.height;for(let e of x.filter(e=>{if("image"!==e.type)return!1;let t=e.x+e.width,l=e.y+e.height;return e.x<a&&t>r&&e.y<s&&l>n}).sort((e,t)=>x.indexOf(e)-x.indexOf(t)))try{let r=e.src;if(!r.startsWith("data:")){let e=o?M(o,r):r,t={};eR&&(t.Authorization="Bearer ".concat(eR));let n=await fetch(e,{credentials:"include",headers:t});if(!n.ok)continue;let a=await n.blob();r=await new Promise(e=>{let t=new FileReader;t.onloadend=()=>e(t.result),t.readAsDataURL(a)})}let n=new Image;await new Promise((e,t)=>{n.onload=()=>e(),n.onerror=t,n.src=r});let a=e.x-eQ.x,s=e.y-eQ.y;t.drawImage(n,a,s,e.width,e.height)}catch(t){console.warn("Failed to draw image:",e.name,t)}let l=e.toDataURL("image/png"),i=document.createElement("a");i.href=l,i.download="".concat(eQ.name.replace(/[^a-zA-Z0-9-_]/g,"_"),".png"),i.click(),L.o.success("Frame exported!")}catch(e){console.error("Export error:",e),L.o.error("Failed to export frame: "+(e instanceof Error?e.message:"Unknown error"))}},sandboxId:o,authToken:eR}),S.length>1&&(0,n.jsx)(G,{elements:x.filter(e=>S.includes(e.id)),scale:es,stagePosition:eo,onStartMerge:()=>{let e=x.filter(e=>S.includes(e.id)),t=e[0],r=e.reduce((e,t)=>({maxX:Math.max(e.maxX,t.x+t.width),minY:Math.min(e.minY,t.y)}),{maxX:-1/0,minY:1/0}),n="merge-temp-".concat(Date.now()),a={id:n,type:"image",src:"",name:"Merging...",x:r.maxX+24,y:r.minY,width:(null==t?void 0:t.width)||400,height:(null==t?void 0:t.height)||400,visible:!0};return f(e=>[...e,a]),D([n]),V(n),n},onMergeComplete:(e,t)=>{f(r=>r.map(r=>r.id===e?{...r,src:t,name:"merged-image.png"}:r)),V(null)},onMergeFailed:e=>{f(t=>t.filter(t=>t.id!==e)),D([]),V(null)},onDelete:()=>{f(e=>e.filter(e=>!S.includes(e.id))),D([])},onProcessingChange:e=>{V(e?S[0]:null)},authToken:eR,sandboxId:o})]})]})}},40181:(e,t,r)=>{r.d(t,{P:()=>c});var n=r(78542),a=r(18558),s=r(29798),l=r(72842),o=r(99870),i=r(72409);function c(e){let{url:t,title:r,className:c,onRetry:d,autoRetry:u=!1,maxRetries:h=10,retryInterval:m=3e3,projectId:x}=e,[p,f]=a.useState(!0),[g,b]=a.useState(!1),v=a.useRef(null),{refreshKey:w,retryCount:j,status:y,triggerRetry:N,onLoadSuccess:_,onLoadError:E,onLoadTimeout:k,reset:C,onHealthCheckPassed:S,setHealthCheckPending:D}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{maxRetries:t=10,initialDelay:r=2e3,enabled:n=!0,projectId:s}=e,[l,o]=(0,a.useState)("loading"),[i,c]=(0,a.useState)(0),[d,u]=(0,a.useState)(0),h=(0,a.useRef)(null),m=(0,a.useRef)(!1),x=(0,a.useRef)(!1),p=(0,a.useRef)(!1),f=(0,a.useRef)(!1),g=(0,a.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),b=(0,a.useCallback)(e=>Math.min(r*Math.pow(1.5,e),1e4),[r]),v=(0,a.useCallback)(()=>{if(!n||i>=t){console.log("[IframeAutoRetry] Max retries reached (".concat(t,"), stopping")),o("error"),m.current=!1;return}let e=b(i);console.log("[IframeAutoRetry] Scheduling retry in ".concat(e,"ms (attempt ").concat(i+1,"/").concat(t,")")),o("retrying"),m.current=!0,h.current=setTimeout(()=>{c(e=>e+1),u(e=>e+1),o("loading"),m.current=!1},e)},[n,i,t,b]),w=(0,a.useCallback)(()=>{console.log("[IframeAutoRetry] Manual retry triggered"),g(),c(0),u(e=>e+1),o("loading"),m.current=!1},[g]),j=(0,a.useCallback)(()=>(f.current=!0,x.current)?void console.log("[IframeAutoRetry] Iframe onLoad fired, but health check pending - waiting"):p.current?void(console.log("[IframeAutoRetry] Both health check and iframe load succeeded - setting ready"),g(),o("ready"),c(0),m.current=!1):void console.log("[IframeAutoRetry] Iframe onLoad fired, but health check not passed - ignoring"),[g]),y=(0,a.useCallback)(()=>{if(console.log("[IframeAutoRetry] Load error (attempt ".concat(i+1,")")),x.current=!1,p.current=!1,f.current=!1,!n)return void o("error");m.current||v()},[n,i,v]),N=(0,a.useCallback)(()=>
1{if(console.log("[IframeAutoRetry] Iframe load timeout (attempt ".concat(i+1,")")),x.current=!1,p.current=!1,f.current=!1,!n)return void o("error");m.current||v()},[n,i,v]),_=(0,a.useCallback)(()=>{g(),o("loading"),c(0),u(e=>e+1),m.current=!1,x.current=!1,p.current=!1,f.current=!1},[g]),E=(0,a.useCallback)(()=>{console.log("[IframeAutoRetry] Health check passed"),x.current=!1,p.current=!0,f.current?(console.log("[IframeAutoRetry] Iframe already loaded - setting ready"),g(),o("ready"),c(0),m.current=!1):console.log("[IframeAutoRetry] Waiting for iframe load")},[g]),k=(0,a.useCallback)(e=>{x.current=e},[]),C=(0,a.useRef)(l);return(0,a.useEffect)(()=>{C.current=l},[l]),(0,a.useEffect)(()=>{if(!n||!s)return;let e=e=>{var t;if((null==(t=e.detail)?void 0:t.projectId)===s){if("ready"===C.current)return void console.log("[IframeAutoRetry] Sandbox active event received, but iframe already loaded - skipping retry");console.log("[IframeAutoRetry] Sandbox active event received, triggering retry"),w()}};return window.addEventListener("sandbox-active",e),()=>{window.removeEventListener("sandbox-active",e)}},[n,s,w]),(0,a.useEffect)(()=>()=>{g()},[g]),{refreshKey:d,retryCount:i,status:l,triggerRetry:w,onLoadSuccess:j,onLoadError:y,onLoadTimeout:N,reset:_,onHealthCheckPassed:E,setHealthCheckPending:k}}({maxRetries:h,initialDelay:m,enabled:u,projectId:x});a.useEffect(()=>{t&&(f(!0),b(!1),u&&C())},[t,u,C]),a.useEffect(()=>(v.current&&clearTimeout(v.current),p&&t&&(v.current=setTimeout(()=>{console.warn("[IframePreview] Load timeout for URL:",t),f(!1),u&&"ready"!==y&&k()},1e4)),()=>{v.current&&clearTimeout(v.current)}),[p,t,u,y,k]),a.useEffect(()=>{if(!t||!u||"ready"===y)return;let e=new AbortController;return D(!0),(async()=>{try{let r=await fetch(t,{method:"GET",signal:e.signal}),n=await r.text(),a=r.headers.get("content-type");if((!r.ok||(null==a?void 0:a.includes("application/json")))&&(n.includes("statusCode")||n.includes("BAD_REQUEST")||n.includes("failed to get runner"))){console.log("[IframePreview] Health check: JSON error detected:",n.substring(0,100)),E();return}if(n.length<200||/^\s*<!DOCTYPE[^>]*>\s*<html[^>]*>\s*<\/html>\s*$/i.test(n)||/^\s*<html[^>]*>\s*(<head[^>]*>[\s\S]*?<\/head>)?\s*<body[^>]*>\s*<\/body>\s*<\/html>\s*$/i.test(n)){console.log("[IframePreview] Health check: Content blank/placeholder, length:",n.length),E();return}console.log("[IframePreview] Health check passed, content length:",n.length),S()}catch(e){e instanceof Error&&"AbortError"!==e.name&&(console.log("[IframePreview] Health check failed:",e.message),E())}})(),()=>e.abort()},[t,w,u,y,E,S,D]);let A=a.useCallback(()=>{f(!1),u&&_()},[u,_]),L=a.useCallback(()=>{f(!1),u&&"ready"!==y?E():b(!0)},[u,y,E]),I=a.useCallback(()=>{b(!1),f(!0),u&&N(),d&&d()},[u,N,d]),R=u?"error"===y:g,P=u?(p||"loading"===y||"retrying"===y)&&"ready"!==y:p;return(0,n.jsxs)(n.Fragment,{children:[P&&(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-background/50 z-10",children:[(0,n.jsx)(s.RgoLoader,{size:"medium"}),(0,n.jsx)("span",{className:"mt-2 text-sm text-muted-foreground",children:(u,"Loading preview...")})]}),R?(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-4 bg-muted/30",children:[(0,n.jsx)("div",{className:"text-muted-foreground font-medium mb-1",children:"Unable to load preview"}),(0,n.jsx)("div",{className:"text-muted-foreground text-sm text-center mb-4",children:u?"Couldn't load the preview yet â your computer may still be starting up.":d?"The preview couldn't be loaded. Try again or open in a new tab.":"Click the link in the header to open in a new tab."}),(d||u)&&(0,n.jsxs)(l.$,{variant:"outline",size:"sm",onClick:I,children:[(0,n.jsx)(o.default,{className:"h-4 w-4 mr-2"}),"Retry"]})]}):(0,n.jsx)("iframe",{src:t,title:r||"Preview",className:(0,i.cn)("absolute inset-0 w-full h-full border-0",c),sandbox:"allow-same-origin allow-scripts allow-forms allow-popups allow-downloads",style:{background:"white"},onLoad:A,onError:L},u?w:void 0)]})}},43835:(e,t,r)=>{r.d(t,{C:()=>n.C});var n=r(90373)},46032:(e,t,r)=>{r.d(t,{M:()=>c});var n=r(78542),a=r(18558),s=r(56378),l=r(51591),o=r(39214),i=r(2803);function c(e){var t;let{slide:r,project:c,onFullScreenClick:d,className:u="",showFullScreenButton:h=!0,refreshTimestamp:m}=e,[x,p]=(0,a.useState)(null),[f,g]=(0,a.useState)(1),b=(0,a.useMemo)(()=>{var e;if(!(null==c||null==(e=c.sandbox)?void 0:e.sandbox_url))return null;let t=(0,i.i)(c.sandbox.sandbox_url,r.file_path);return m?"".concat(t,"?t=").concat(m):t},[null==c||null==(t=c.sandbox)?void 0:t.sandbox_url,r.file_path,m]);return((0,a.useEffect)(()=>{let e;if(!x)return;let t=()=>{let e=x.offsetWidth,t=Math.min(e/1920,x.offsetHeight/1080);Math.abs(t-f)>.001&&g(t)};t();let r=()=>{clearTimeout(e),e=setTimeout(t,50)},n=new ResizeObserver(r);return n.observe(x),window.addEventListener("resize",r),()=>{n.disconnect(),window.removeEventListener("resize",r),clearTimeout(e)}},[x,f]),b)?(0,n.jsxs)("div",{className:"group relative bg-background border border-border rounded-xl overflow-hidden hover:shadow-md hover:scale-[1.01] transition-all duration-200 ".concat(u),children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-hairline flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)(s.aX,{className:"font-mono",children:["#",r.number]}),r.title&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:r.title})]}),!1!==h&&(0,n.jsx)(s.K0,{onClick:()=>null==d?void 0:d(r.number),className:"opacity-60 group-hover:opacity-100 transition-all",title:"Open in full screen","aria-label":"Open in full screen",disabled:!d,children:(0,n.jsx)(o.default,{className:"h-3.5 w-3.5",
1strokeWidth:1.75})})]}),(0,n.jsxs)("div",{className:"relative aspect-video bg-bg-subtle cursor-pointer",onClick:()=>null==d?void 0:d(r.number),children:[(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center bg-transparent",children:(0,n.jsx)("div",{ref:p,className:"relative w-full h-full bg-background rounded-lg overflow-hidden",style:{containIntrinsicSize:"1920px 1080px",contain:"layout style"},children:(0,n.jsx)("iframe",{src:b,title:"Slide ".concat(r.number,": ").concat(r.title),className:"border-0 rounded-xl",sandbox:"allow-same-origin allow-scripts",style:{width:"1920px",height:"1080px",border:"none",display:"block",transform:"scale(".concat(f,")"),transformOrigin:"0 0",position:"absolute",top:0,left:0,willChange:"transform",backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"}},"slide-".concat(r.number,"-").concat(m||r.file_path))})}),(0,n.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/5 transition-colors duration-200"})]})]}):(0,n.jsxs)("div",{className:"group relative bg-background border border-border rounded-xl overflow-hidden ".concat(u),children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-hairline flex items-center justify-between",children:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)(s.aX,{className:"font-mono",children:["#",r.number]}),r.title&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:r.title})]})}),(0,n.jsx)("div",{className:"flex items-center justify-center h-48 bg-bg-subtle",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(l.default,{className:"h-[26px] w-[26px] mx-auto mb-2 text-text-subtle opacity-60"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground",children:"No slide content to preview"})]})})]})}},47044:(e,t,r)=>{r.d(t,{KX:()=>o,e4:()=>l,fG:()=>s});var n=r(40570);r(93434);let a="https://api.rationalgo.ai/v1",s=async e=>{let t=await (0,n.getAccessTokenAsync)(),r={"Content-Type":"application/json"};t&&(r.Authorization="Bearer ".concat(t));let s=await fetch("".concat(a,"/threads/").concat(e),{headers:r,cache:"no-store"});if(!s.ok)throw Error(await s.text().catch(()=>"Unknown error")||"Failed to fetch thread: ".concat(s.statusText));return await s.json()},l=async(e,t)=>{let r=await (0,n.getAccessTokenAsync)();if(!r)throw Error("You must be logged in to update a thread");let s=await fetch("".concat(a,"/threads/").concat(e),{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(r)},body:JSON.stringify(t),cache:"no-store"});if(!s.ok){let e=await s.text().catch(()=>"Unknown error");throw console.error("Error updating thread:",e),Error("Error updating thread: ".concat(e))}return await s.json()},o=async(e,t)=>{try{let t=await (0,n.getAccessTokenAsync)(),r={"Content-Type":"application/json"};t&&(r.Authorization="Bearer ".concat(t));let s=await fetch("".concat(a,"/threads/").concat(e),{method:"DELETE",headers:r});if(!s.ok){let e=await s.text().catch(()=>"Unknown error");throw console.error("Error deleting thread:",e),Error("Failed to delete thread: ".concat(e))}console.log("Thread ".concat(e," deleted successfully"))}catch(e){throw console.error("Error deleting thread:",e),e}}},50977:(e,t,r)=>{r.d(t,{A:()=>o});var n=r(78542),a=r(18558),s=r(39084),l=r(72409);function o(e){let{className:t,defaultValue:r,value:o,min:i=0,max:c=100,...d}=e,u=a.useMemo(()=>Array.isArray(o)?o:Array.isArray(r)?r:[i,c],[o,r,i,c]);return(0,n.jsxs)(s.bL,{"data-slot":"slider",defaultValue:r,value:o,min:i,max:c,className:(0,l.cn)("relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",t),...d,children:[(0,n.jsx)(s.CC,{"data-slot":"slider-track",className:(0,l.cn)("bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"),children:(0,n.jsx)(s.Q6,{"data-slot":"slider-range",className:(0,l.cn)("cursor-pointer bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full")})}),Array.from({length:u.length},(e,t)=>(0,n.jsx)(s.zi,{"data-slot":"slider-thumb",className:"cursor-pointer border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"},t))]})}},51145:(e,t,r)=>{r.d(t,{AM:()=>l,Wv:()=>
1o,dT:()=>c,hl:()=>i});var n=r(78542);r(18558);var a=r(50922),s=r(72409);function l(e){let{...t}=e;return(0,n.jsx)(a.bL,{"data-slot":"popover",...t})}function o(e){let{...t}=e;return(0,n.jsx)(a.l9,{"data-slot":"popover-trigger",...t})}function i(e){let{className:t,align:r="center",sideOffset:l=4,container:o,...i}=e;return(0,n.jsx)(a.ZL,{container:o,children:(0,n.jsx)(a.UC,{"data-slot":"popover-content",align:r,sideOffset:l,className:(0,s.cn)("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-xl border p-3 shadow-md outline-hidden",t),...i})})}function c(e){let{...t}=e;return(0,n.jsx)(a.Mz,{"data-slot":"popover-anchor",...t})}},54848:(e,t,r)=>{r.d(t,{R:()=>v});var n=r(78542),a=r(18558),s=r(72409),l=r(72842),o=r(50977),i=r(6851),c=r(88509),d=r(79083),u=r(27496),h=r(99870),m=r(49664),x=r(30070),p=r(46891),f=r(6721),g=r(29798);function b(e){let t=Math.floor(e/60),r=Math.floor(e%60);return"".concat(t,":").concat(r.toString().padStart(2,"0"))}function v(e){let{url:t,className:r,compact:v=!1,autoPlay:w=!1,loop:j=!1,onDownload:y}=e,N=(0,a.useRef)(null),_=(0,a.useRef)(null),[E,k]=(0,a.useState)(!1),[C,S]=(0,a.useState)(!1),[D,A]=(0,a.useState)(1),[L,I]=(0,a.useState)(0),[R,P]=(0,a.useState)(0),[T,M]=(0,a.useState)(!0),[z,U]=(0,a.useState)(!1),[B,F]=(0,a.useState)(!1),[O,W]=(0,a.useState)(!0),[H,G]=(0,a.useState)(!1),[V,X]=(0,a.useState)(null),$=(0,a.useRef)(null);(0,a.useEffect)(()=>{let e=()=>{F(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",e),()=>document.removeEventListener("fullscreenchange",e)},[]);let Y=(0,a.useCallback)(()=>{$.current&&clearTimeout($.current),W(!0),E&&!v&&($.current=setTimeout(()=>{W(!1)},3e3))},[E,v]);(0,a.useEffect)(()=>(Y(),()=>{$.current&&clearTimeout($.current)}),[E,Y]);let K=()=>{let e=N.current;e&&(P(e.duration),X({width:e.videoWidth,height:e.videoHeight,duration:e.duration}),M(!1))},q=()=>{N.current&&I(N.current.currentTime)},Z=e=>{let t=e.currentTarget,r=t.error;console.error("[VideoRenderer] Video error:",{code:null==r?void 0:r.code,message:null==r?void 0:r.message,url:t.src,networkState:t.networkState,readyState:t.readyState}),U(!0),M(!1)},Q=()=>{M(!1)},J=()=>{N.current&&(E?N.current.pause():N.current.play(),k(!E))},ee=async()=>{_.current&&(B?await document.exitFullscreen():await _.current.requestFullscreen())};return v?(0,n.jsxs)("div",{className:(0,s.cn)("relative rounded-2xl overflow-hidden bg-black/5 dark:bg-black/20",r),children:[T&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-muted/50",children:(0,n.jsx)(g.RgoLoader,{size:"medium"})}),z?(0,n.jsx)("div",{className:"flex flex-col items-center justify-center h-full p-4 text-center",children:(0,n.jsx)("p",{className:"text-destructive font-medium text-sm",children:"Failed to load video"})}):(0,n.jsxs)("div",{className:"relative group",children:[(0,n.jsx)("video",{ref:N,src:t,className:"w-full h-auto max-h-80 object-contain",autoPlay:w,loop:j,muted:C,playsInline:!0,onLoadedMetadata:K,onTimeUpdate:q,onError:Z,onCanPlay:Q,onPlay:()=>k(!0),onPause:()=>k(!1),onEnded:()=>k(!1)}),(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity bg-black/20",children:(0,n.jsx)(l.$,{variant:"ghost",size:"icon",className:"h-12 w-12 rounded-full bg-white/90 dark:bg-black/90 hover:bg-white dark:hover:bg-black shadow-lg",onClick:J,children:E?(0,n.jsx)(i.default,{className:"h-6 w-6"}):(0,n.jsx)(c.default,{className:"h-6 w-6 ml-0.5"})})}),(0,n.jsx)("div",{className:"absolute bottom-0 left-0 right-0 h-1 bg-black/30",children:(0,n.jsx)("div",{className:"h-full bg-white/80",style:{width:"".concat(R?L/R*100:0,"%")}})})]})]}):(0,n.jsxs)("div",{ref:_,className:(0,s.cn)("relative w-full h-full group bg-black",r),onMouseMove:Y,onMouseEnter:()=>W(!0),children:[T&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-black z-10",children:(0,n.jsx)(g.RgoLoader,{size:"large",variant:"white"})}),z?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full p-6 text-center",children:[(0,n.jsx)("p",{className:"text-white font-medium mb-2",children:"Failed to load video"}),(0,n.jsx)("p",{className:"text-sm text-white/60",children:"The video could not be played"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("video",{ref:N,src:t,className:"w-full h-full object-contain",autoPlay:w,loop:j,muted:C,playsInl
1ine:!0,onClick:J,onLoadedMetadata:K,onTimeUpdate:q,onError:Z,onCanPlay:Q,onPlay:()=>k(!0),onPause:()=>k(!1),onEnded:()=>k(!1)}),!E&&!T&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:(0,n.jsx)("div",{className:"h-20 w-20 rounded-full bg-white/20 backdrop-blur-sm flex items-center justify-center",children:(0,n.jsx)(c.default,{className:"h-10 w-10 text-white ml-1"})})}),(0,n.jsx)("div",{className:(0,s.cn)("absolute top-0 left-0 right-0 p-4 transition-opacity duration-200 bg-gradient-to-b from-black/60 to-transparent",O?"opacity-100":"opacity-0 pointer-events-none"),children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-white hover:bg-white/20",onClick:()=>G(!H),children:(0,n.jsx)(d.default,{className:"h-4 w-4"})}),y&&(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-white hover:bg-white/20",onClick:y,children:(0,n.jsx)(u.default,{className:"h-4 w-4"})})]})}),H&&V&&(0,n.jsx)("div",{className:"absolute top-14 right-4 z-10 bg-black/80 p-4 rounded-lg text-sm text-white min-w-[180px]",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex justify-between gap-6",children:[(0,n.jsx)("span",{className:"text-white/60",children:"Resolution"}),(0,n.jsxs)("span",{className:"font-medium",children:[V.width," \xd7 ",V.height]})]}),(0,n.jsxs)("div",{className:"flex justify-between gap-6",children:[(0,n.jsx)("span",{className:"text-white/60",children:"Duration"}),(0,n.jsx)("span",{className:"font-medium",children:b(V.duration)})]})]})}),(0,n.jsxs)("div",{className:(0,s.cn)("absolute bottom-0 left-0 right-0 p-4 transition-opacity duration-200 bg-gradient-to-t from-black/80 to-transparent",O?"opacity-100":"opacity-0 pointer-events-none"),children:[(0,n.jsx)("div",{className:"mb-3",children:(0,n.jsx)(o.A,{value:[L],max:R||100,step:.1,onValueChange:e=>{let t=e[0];N.current&&(N.current.currentTime=t,I(t))},className:"cursor-pointer [&_[data-slot=range]]:bg-white [&_[data-slot=thumb]]:bg-white [&_[data-slot=thumb]]:border-0 [&_[data-slot=thumb]]:h-3 [&_[data-slot=thumb]]:w-3 [&_[data-slot=track]]:bg-white/30"})}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-9 w-9 p-0 text-white hover:bg-white/20",onClick:J,children:E?(0,n.jsx)(i.default,{className:"h-5 w-5"}):(0,n.jsx)(c.default,{className:"h-5 w-5 ml-0.5"})}),(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-9 w-9 p-0 text-white hover:bg-white/20",onClick:()=>{N.current&&(N.current.currentTime=0,I(0),N.current.play(),k(!0))},children:(0,n.jsx)(h.default,{className:"h-4 w-4"})}),(0,n.jsxs)("span",{className:"text-white text-sm font-mono min-w-[90px]",children:[b(L)," / ",b(R)]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-9 w-9 p-0 text-white hover:bg-white/20",onClick:()=>{N.current&&(N.current.muted=!C,S(!C))},children:C||0===D?(0,n.jsx)(m.default,{className:"h-5 w-5"}):(0,n.jsx)(x.default,{className:"h-5 w-5"})}),(0,n.jsx)(o.A,{value:[C?0:D],max:1,step:.1,onValueChange:e=>{let t=e[0];N.current&&(N.current.volume=t,A(t),S(0===t))},className:"w-20 cursor-pointer [&_[data-slot=range]]:bg-white [&_[data-slot=thumb]]:bg-white [&_[data-slot=thumb]]:border-0 [&_[data-slot=thumb]]:h-3 [&_[data-slot=thumb]]:w-3 [&_[data-slot=track]]:bg-white/30"})]}),(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-9 w-9 p-0 text-white hover:bg-white/20",onClick:ee,children:B?(0,n.jsx)(p.default,{className:"h-5 w-5"}):(0,n.jsx)(f.default,{className:"h-5 w-5"})})]})]})]})]})}},56378:(e,t,r)=>{r.d(t,{K0:()=>f,Lw:()=>h,NG:()=>d,aX:()=>u,mi:()=>g,pp:()=>x,uI:()=>p,uO:()=>m,wn:()=>c});var n=r(78542),a=r(18558),s=r(34215),l=r(91365),o=r(44598),i=r(72409);function c(e){let{label:t,children:r,className:a}=e;return(0,n.jsxs)("div",{className:(0,i.cn)("mb-3",a),children:[(0,n.jsx)("div",{className:"text-[10.5px] font-bold uppercase tracking-[0.4px] text-text-subtle mb-[5px]",children:t}),r]})}function d(e){let{text:t,limit:r=6e3,clip:a="head",prefix:s,className:l}=e,o=t.length>r,c=o?"tail"===a?t.slice(-r):t.slice(0,r):t;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("pre",{className:(0,i.cn)("m-0 px-3 py-2.5 rounded-xl bg-bg-subtle border border-hairline overflow-x-auto","text-xs leading-normal whitespace-pre-wrap break-words font-mono text-foreground",l),children:[s,c]}),o&&(0,n.jsxs)("div",{className:"text-[11px] text-text-subtle mt-1",children:["Showing ","tail"===a?"last":"first"," ",r.toLocaleStr
1ing()," of"," ",t.length.toLocaleString()," characters"]})]})}function u(e){let{children:t,className:r}=e;return(0,n.jsx)("span",{className:(0,i.cn)("inline-flex items-center rounded-full px-2 py-0.5 text-[10.5px] font-semibold","text-muted-foreground bg-bg-subtle border border-hairline",r),children:t})}function h(e){let{children:t,className:r}=e;return(0,n.jsx)("div",{className:(0,i.cn)("flex flex-wrap items-center gap-1.5",r),children:t})}function m(e){let{isStreaming:t=!1,isSuccess:r=!0,showLabel:a=!1,className:c}=e,d=t?s.default:r?l.default:o.default;return(0,n.jsxs)("span",{className:(0,i.cn)("flex items-center gap-1",t?"text-text-subtle":r?"text-gold-strong":"text-destructive",c),children:[(0,n.jsx)(d,{className:(0,i.cn)("h-[15px] w-[15px]",t?"animate-spin":"fill-current stroke-bg-subtle")}),a&&(0,n.jsx)("span",{className:"text-[11px] font-semibold",children:t?"runningâ¦":r?"done":"failed"})]})}function x(e){let{icon:t,title:r,subtitle:a,className:s}=e;return(0,n.jsxs)("div",{className:(0,i.cn)("flex h-full w-full flex-col items-center justify-center p-8 text-center",s),children:[(0,n.jsx)(t,{className:"mb-2.5 h-[26px] w-[26px] opacity-60 text-text-subtle"}),(0,n.jsx)("div",{className:"text-[13px] font-semibold text-muted-foreground",children:r}),a&&(0,n.jsx)("div",{className:"mt-1 text-xs text-text-subtle",children:a})]})}function p(e){let{message:t,className:r}=e;if(!t)return null;let a=t.length>1e3;return(0,n.jsxs)(c,{label:"Error",className:r,children:[(0,n.jsx)("div",{className:"text-[12.5px] text-destructive leading-normal break-words",children:a?t.slice(0,1e3):t}),a&&(0,n.jsxs)("div",{className:"text-[11px] text-text-subtle mt-1",children:["Showing first ",1e3.toLocaleString()," of ",t.length.toLocaleString()," characters"]})]})}let f=a.forwardRef(function(e,t){let{className:r,type:a="button",...s}=e;return(0,n.jsx)("button",{ref:t,type:a,className:(0,i.cn)("flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-[6px] text-muted-foreground transition-colors","hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 disabled:text-text-subtle disabled:hover:bg-transparent disabled:hover:text-text-subtle",r),...s})});function g(e){let{path:t,className:r}=e;return(0,n.jsx)("span",{className:(0,i.cn)("block mb-1.5 text-xs font-semibold text-gold-strong break-all",r),children:t})}},58261:(e,t,r)=>{r.d(t,{Z:()=>f});var n=r(78542),a=r(18558),s=r(72409),l=r(47358),o=r(72842),i=r(39214),c=r(53401),d=r(99870),u=r(45068),h=r(29798);let m=new Map,x=null,p=()=>{let e=document.querySelectorAll("div, span, p, text, tspan"),t=0;e.forEach(e=>{let r=e.textContent||"";(r.includes("Syntax error in text")||r.includes("mermaid version 11.12.0")||"Syntax error in text"===r.trim())&&(console.log("\uD83E\uDDF9 Global cleanup of Mermaid error element:",r),e.remove(),t++)}),t>0&&console.log("\uD83E\uDDF9 Cleaned up ".concat(t," Mermaid error elements"))},f=a.memo(e=>{let{chart:t,className:f,enableFullscreen:g=!0}=e,b=(0,a.useRef)(null),[v,w]=(0,a.useState)(null),[j,y]=(0,a.useState)(!0),[N,_]=(0,a.useState)(""),[E,k]=(0,a.useState)(!1),[C,S]=(0,a.useState)(""),D=(0,a.useMemo)(()=>{let e=0,r=t.trim();for(let t=0;t<r.length;t++)e=(e<<5)-e+r.charCodeAt(t),e&=e;return e.toString(36)},[t]),A=(0,a.useRef)(null),[L,I]=(0,a.useState)(1),[R,P]=(0,a.useState)({x:0,y:0}),[T,M]=(0,a.useState)(!1),[z,U]=(0,a.useState)({x:0,y:0}),[B,F]=(0,a.useState)(null);(0,a.useEffect)(()=>{let e=setInterval(p,5e3);return p(),()=>{clearInterval(e),p()}},[]);let O=(0,a.useCallback)(e=>{0===e.button&&(M(!0),U({x:e.clientX-R.x,y:e.clientY-R.y}))},[R]),W=(0,a.useCallback)(e=>{T&&P({x:e.clientX-z.x,y:e.clientY-z.y})},[T,z]),H=(0,a.useCallback)(()=>{M(!1)},[]),G=e=>{if(e.length<2)return null;let t=e[0],r=e[1];return Math.sqrt(Math.pow(r.clientX-t.clientX,2)+Math.pow(r.clientY-t.clientY,2))},V=(0,a.useCallback)(e=>{1===e.touches.length?(M(!0),U({x:e.touches[0].clientX-R.x,y:e.touches[0].clientY-R.y})):2===e.touches.length&&(M(!1),F(G(e.touches)))},[R]),X=(0,a.useCallback)(e=>{if((T||2===e.touches.length&&B)&&e.preventDefault(),1===e.touches.length&&T)P({x:e.touches[0].clientX-z.x,y:e.touches[0].clientY-z.y});else if(2===e.touches.length&&B){e.preventDefault();let t=G(e.touches);if(t){let r=Math.max(.1,Math.min(5,t/B*L));if(A.current){let t=A.current.getBoundingClientRect(),n=(e=>{if(0===e.length)return{x:0,y:0};if(1===e.length)return{x:e[0].clientX,y:e[0].clientY};let t=e[0],r=e[1];return{x:(t.clientX+r.clientX)/2,y:(t.clientY+r.clientY)/2}})(e.touches),a=n.x-t.left,s=n.y-t.top,l={x:a-(a-R.x)*(r/L),y:s-(s-R.y)*(r/L)};I(r),P(l)}F(t)}}},[T,z,B,L,R]),$=(0,a.useCallback)(()=>{M(!1),F(null)},[]),Y=(0,a.useCallback)(e=>{var t;if(!(null==(t=A.current)?void 0:t.contains(e.target)))return;e.preventDefault();let r=Math.max(.1,Math.min(5,L*(e.deltaY>0?.9:1.1)));if(A.current){let t=A.current.getBoundingClientRect(),n=e.clientX-t.left,a=e.clientY-t.top,s={x:n-(n-R.x)*(r/L),y:a-(a-R.y)*(r/L)};I(r),P(s)}},[L,R]);(0,a.useEffect)(()=>{let e=A.current;if(e&&E)return e.addEventListener("wheel",Y,{passive:!1}),()=>{e.removeEventListener("wheel",Y)}},[E,Y]);let K=()=>I(e=>Math.min(5,1.2*e)),q=()=>I(e=>Math.max(.1,.8*e)),Z=()=>{I(1),P({x:0,y:0})},Q=()=>{I(.8),P({x:0,y:0})},J=()=>{g&&(k(!0),I(.8),P({x:0,y:0}),M(!1),ee())},ee=async()=>
1{try{let e=m.get(D);if(e)return void S(e);if(!x){let e=(await Promise.all([r.e(12463),r.e(45330),r.e(65330)]).then(r.bind(r,65330))).default;await e.initialize({startOnLoad:!1,securityLevel:"strict",theme:"base",fontFamily:"ui-sans-serif, system-ui, sans-serif",gitGraph:{showBranches:!0,showCommitLabel:!0,mainBranchName:"main",rotateCommitLabel:!0}}),x=e}let n="mermaid-fullscreen-".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),a=await x.render(n,t);m.set(D,a.svg),S(a.svg)}catch(e){console.error("Fullscreen rendering error:",e),E&&S('\n <div style="display: flex; align-items: center; justify-content: center; height: 200px; color: #6b7280; font-family: ui-sans-serif, system-ui, sans-serif;">\n <div style="text-align: center;">\n <div style="font-size: 24px; margin-bottom: 8px;">\uD83D\uDCCA</div>\n <div>Diagram rendering failed</div>\n <div style="font-size: 12px; margin-top: 4px; opacity: 0.7;">Check diagram syntax</div>\n </div>\n </div>\n ')}};(0,a.useEffect)(()=>{if(!E)return;let e=e=>{switch(e.key){case"Escape":k(!1);break;case"+":case"=":e.preventDefault(),K();break;case"-":e.preventDefault(),q();break;case"0":e.preventDefault(),Z();break;case"f":case"F":e.preventDefault(),Q()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[E]);let et=(0,a.useRef)(null),er=(0,a.useRef)(null),[en,ea]=(0,a.useState)(null);return((0,a.useEffect)(()=>{if(m.has(D)){et.current=D,ea(D);return}return er.current&&clearTimeout(er.current),er.current=setTimeout(()=>{et.current=D,ea(D)},300),()=>{er.current&&clearTimeout(er.current)}},[D]),(0,a.useEffect)(()=>{if(!en)return;let e=!0;return(async()=>{if(!t.trim()){e&&y(!1);return}let n=m.get(en);if(n){e&&(_(n),y(!1));return}try{var a;let n;e&&(y(!0),w(null));let s=t.trim();if(!s)throw Error("Empty chart content");let l=s.split("\n"),o=(null==(a=l[l.length-1])?void 0:a.trim())||"";if(o.endsWith("--\x3e")||o.endsWith("->")||o.endsWith("--")||o.endsWith("|")||o.endsWith("[")||o.endsWith("(")||o.endsWith("{")||o.includes("[")&&!o.includes("]")||o.includes("(")&&!o.includes(")")){e&&y(!0);return}let i=s.split("\n")[0].toLowerCase().trim();if(!["graph","flowchart","sequencediagram","sequence","classdiagram","class","statediagram","state","erdiagram","journey","gantt","pie","gitgraph","mindmap","timeline","sankey","block","quadrant","requirement","c4context","c4container","c4component","c4dynamic"].some(e=>i.startsWith(e)||i.includes(e)))throw Error('Invalid diagram type. Chart must start with a valid Mermaid diagram type (e.g., graph, flowchart, sequenceDiagram, etc.). Found: "'.concat(i,'"'));if(!x){let e=(await Promise.all([r.e(12463),r.e(45330),r.e(65330)]).then(r.bind(r,65330))).default;await e.initialize({startOnLoad:!1,securityLevel:"strict",theme:"base",fontFamily:"ui-sans-serif, system-ui, sans-serif",gitGraph:{showBranches:!0,showCommitLabel:!0,mainBranchName:"main",rotateCommitLabel:!0}}),x=e,console.log("â
Mermaid initialized and cached")}let c="mermaid-".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9));console.log("\uD83C\uDFAF Rendering chart with ID:",c);try{n=await x.render(c,s)}catch(r){let e=r instanceof Error?r.message:String(r);console.error("\uD83D\uDEA8 Mermaid parsing error:",e);let t=document.getElementById(c);if(t&&t.remove(),e.includes("Parse error")||e.includes("Syntax error"))throw Error("Diagram syntax error: ".concat(e));if(e.includes("UnknownDiagramError"))throw Error("unsupported_diagram_type");throw Error("Failed to render diagram: ".concat(e))}if(!e)return;console.log("â
Chart rendered successfully, SVG length:",n.svg.length),m.set(D,n.svg),_(n.svg),setTimeout(p,100)}catch(t){if(console.error("â Mermaid rendering error:",t),setTimeout(p,50),e){let e=t instanceof Error?t.message:"Failed to render diagram";e.includes("UnknownDiagramError")||e.includes("No diagram type detected")?(console.log("\uD83D\uDD04 Unsupported Mermaid diagram type, falling back to code block"),w("unsupported_diagram_type")):w(e)}}finally{e&&(y(!1),console.log("\uD83C\uDFC1 Mermaid rendering completed"))}})(),()=>{e=!1}},[en,t]),j)?(0,n.jsx)("div",{className:(0,s.cn)("flex items-center justify-center p-8 bg-muted/30 rounded-2xl border border-dashed",f),children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-sm text-muted-foreground mb-2",children:"\uD83C\uDFA8 Rendering Mermaid diagram..."}),(0,n.jsx)(h.RgoLoader,{size:"medium"})]})}):v?"unsupported_diagram_type"===v?(0,n.jsxs)("div",{className:(0,s.cn)("my-2",f),children:[(0,n.jsxs)("div",{className:"text-xs text-muted-foreground mb-1 flex items-center gap-1",children:[(0,n.jsx)("span",{children:"â ï¸"}),(0,n.jsx)("span",{children:"Unsupported diagram type (not available in Mermaid 11.x)"})]}),(0,n.jsx)("pre",{className:"text-xs p-3 bg-muted/50 border rounded-2xl overflow-x-auto whitespace-pre-wrap font-mono",children:t})]}):(0,n.jsxs)("div",{className:(0,s.cn)("p-4 bg-destructive/10 border border-destructive/20 rounded-2xl",f),children:[(0,n.jsx)("div",{className:"text-sm text-destructive font-medium mb-2",children:"â Failed to render Mermaid diagram"}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono bg-muted/50 p-2 rounded",children:v}),(0,n.jsxs)("details",{className:"mt-2",children:[(0,n.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"\uD83D\uDCC4 Show diagram source"}),(0,n.jsx)("pre",{className:"text-xs mt-2 p-2 bg-muted/50 rounded overflow-x-auto whitespace-pre-wrap",children:t})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("style",{dangerouslySetInnerHTML:{__html:"\n .mermaid-container svg {\n max-width: 100% !important;\n height: auto !important;\n display: block !important;\n margin: 0 auto !important;\n }
1\n .mermaid-container .node {\n fill: var(--card) !important;\n stroke: var(--foreground) !important;\n }\n .mermaid-container .cluster {\n fill: var(--muted) !important;\n stroke: var(--foreground) !important;\n }\n .mermaid-container text {\n fill: var(--foreground) !important;\n font-family: var(--font-geist-sans), ui-sans-serif, system-ui, sans-serif !important;\n }\n .mermaid-container .edgePath {\n stroke: var(--foreground) !important;\n }\n .mermaid-container .marker {\n fill: var(--foreground) !important;\n }\n\n /* Fullscreen modal specific styles */\n .mermaid-fullscreen-modal svg {\n max-width: 100% !important;\n max-height: 100% !important;\n width: auto !important;\n height: auto !important;\n display: block !important;\n margin: 0 auto !important;\n }\n\n .mermaid-fullscreen-modal .mermaid-container {\n max-width: 100% !important;\n max-height: 100% !important;\n overflow: auto !important;\n padding: 1rem !important;\n }\n\n /* Ensure diagrams don't overflow their containers */\n .mermaid-fullscreen-modal {\n width: 100% !important;\n height: 100% !important;\n display: flex !important;\n align-items: flex-start !important;\n justify-content: center !important;\n }\n "}}),(0,n.jsxs)("div",{className:(0,s.cn)("mermaid-container my-4 rounded-2xl border overflow-auto bg-background relative group cursor-pointer",g&&"hover:ring-2 hover:ring-primary/20",f),style:{minHeight:"200px",width:"100%"},onClick:g?J:void 0,children:[(0,n.jsx)("div",{ref:b,dangerouslySetInnerHTML:{__html:N}}),g&&(0,n.jsx)("div",{className:"absolute inset-0 bg-black/0 hover:bg-black/5 transition-colors rounded-2xl flex items-center justify-center opacity-0 hover:opacity-100 pointer-events-none",children:(0,n.jsx)(o.$,{variant:"secondary",size:"sm",className:"h-8 w-8 p-0 bg-background/90 hover:bg-background border shadow-sm pointer-events-auto",onClick:e=>{e.stopPropagation(),J()},title:"View fullscreen",children:(0,n.jsx)(i.default,{className:"h-4 w-4"})})})]}),(0,n.jsx)(l.lG,{open:E,onOpenChange:k,children:(0,n.jsx)(l.Cf,{className:"max-w-[95vw] max-h-[95vh] w-full h-full p-0 overflow-hidden",children:(0,n.jsxs)("div",{className:"flex flex-col h-full bg-background",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 pr-16 border-b bg-background/95 backdrop-blur-sm",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(l.L3,{className:"text-base font-medium",children:"Mermaid Diagram"}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Zoom: ",Math.round(100*L),"%"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(o.$,{variant:"outline",size:"sm",onClick:q,className:"h-8 w-8 p-0",title:"Zoom out",children:(0,n.jsx)(c.default,{className:"h-4 w-4"})}),(0,n.jsx)(o.$,{variant:"outline",size:"sm",onClick:Z,className:"h-8 w-8 p-0",title:"Reset view",children:(0,n.jsx)(d.default,{className:"h-4 w-4"})}),(0,n.jsx)(o.$,{variant:"outline",size:"sm",onClick:K,className:"h-8 w-8 p-0",title:"Zoom in",children:(0,n.jsx)(u.default,{className:"h-4 w-4"})}),(0,n.jsx)(o.$,{variant:"outline",size:"sm",onClick:Q,className:"h-8 px-3",title:"Fit to viewport",children:"Fit"})]})]}),(0,n.jsxs)("div",{ref:A,className:"flex-1 min-h-0 relative overflow-hidden bg-muted/10 cursor-move touch-none select-none",onClick:e=>e.stopPropagation(),onMouseDown:e=>{e.stopPropagation(),O(e)},onMouseMove:W,onMouseUp:H,onMouseLeave:H,onTouchStart:e=>{e.stopPropagation(),V(e)},onTouchMove:X,onTouchEnd:$,style:{cursor:T?"grabbing":"grab"},children:[C?(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",style:{transform:"translate(".concat(R.x,"px, ").concat(R.y,"px) scale(").concat(L,")"),transformOrigin:"center center",transition:T?"none":"transform 0.1s ease-out"},dangerouslySetInnerHTML:{__html:C}}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full w-full",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-sm text-muted-foreground mb-2",children:"\uD83C\uDFA8 Loading fullscreen diagram..."}),(0,n.jsx)(h.RgoLoader,{size:"medium"})]})}),(0,n.jsxs)("div",{className:"absolute bottom-4 left-4 bg-background/80 backdrop-blur-sm rounded-2xl px-3 py-2 text-xs text-muted-foreground shadow-sm",children:[(0,n.jsx)("div",{children:"Drag to pan ⢠Scroll to zoom ⢠Pinch to zoom"}),(0,n.jsx)("div",{className:"mt-1 opacity-75",children:"Esc: close ⢠+/-: zoom ⢠0: reset ⢠F: fit"})]})]})]})})})]})});f.displayName="MermaidRenderer"},59652:(e,t,r)=>{r.d(t,{T:()=>s});var n=r(78542);r(18558);var a=r(72409);function s(e){let{className:t,...r}=e;return(0,n.jsx)("textarea",{"data-slot":"textarea",className:(0,a.cn)("border-input placeholder:text-muted-foreground aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-12 w-full rounded-lg border bg-transparent px-2.5 py-1.5 text-base shadow-xs transition-[color,border-color,box-shadow] outline-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus:border-gold focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--gold)_20%,transparent)]","aria-invalid:focus:border-destructive aria-invalid:focus:shadow-[0_0_0_3px_rgba(186,26,26,0.15)]",t),...r})}},75152:(e,t,r)=>{r.d(t,{Be:()=>d,OG:()=>p,R2:()=>
1x,fetchFileContent:()=>h,x2:()=>m});var n=r(18558),a=r(68432),s=r(14333),l=r(35284),o=r(26608),i=r(90350);function c(e){if(!e)return"/workspace";("workspace"===e||e.startsWith("workspace/"))&&(e="/"+e),e.startsWith("/workspace")||(e="/workspace/".concat(e.startsWith("/")?e.substring(1):e));try{e=e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16)))}catch(e){console.error("Error processing Unicode escapes in path:",e)}return e}let d={all:["files"],contents:()=>[...d.all,"content"],content:(e,t,r)=>[...d.contents(),e,c(t),r],directories:()=>[...d.all,"directory"],directory:(e,t)=>[...d.directories(),e,c(t)]};function u(e){if(!e)return"text";let t=e.toLowerCase().split(".").pop()||"";return/^(xlsx|xls|docx|pptx|ppt|pdf|png|jpg|jpeg|gif|bmp|webp|svg|ico|zip|exe|dll|bin|dat|obj|o|so|dylib|mp3|mp4|avi|mov|wmv|flv|wav|ogg)$/.test(t)?"blob":"json"===t?"json":"text"}async function h(e,t,r,n){let a=c(t),s=new URL("".concat("https://api.rationalgo.ai/v1","/sandboxes/").concat(e,"/files/content"));s.searchParams.append("path",a);let l={};n&&(l.Authorization="Bearer ".concat(n));let o=await fetch(s.toString(),{headers:l});if(!o.ok){let e=await o.text();throw Error("Failed to fetch file: ".concat(o.status," ").concat(e))}switch(r){case"json":return await o.json();case"blob":{let e=await o.blob(),r=function(e){var t;switch((null==(t=e.split(".").pop())?void 0:t.toLowerCase())||""){case"xlsx":return"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";case"xls":return"application/vnd.ms-excel";case"docx":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";case"doc":return"application/json";case"pptx":return"application/vnd.openxmlformats-officedocument.presentationml.presentation";case"ppt":return"application/vnd.ms-powerpoint";case"pdf":return"application/pdf";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"svg":return"image/svg+xml";case"zip":return"application/zip";default:return"application/octet-stream"}}(t);if(r!==e.type&&"application/octet-stream"!==r){var i;let n=new Blob([e],{type:r});return["png","jpg","jpeg","gif","svg","webp","bmp","ico"].includes((null==(i=t.split(".").pop())?void 0:i.toLowerCase())||""),n}return e}default:return await o.text()}}function m(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{session:o}=(0,l.A)(),i=t?c(t):null,m=t?u(t):"text",x=r.contentType||m,p=(0,a.I)({queryKey:e&&i?d.content(e,i,x):[],queryFn:async()=>{if(!e||!i)throw Error("Missing required parameters");return h(e,i,x,(null==o?void 0:o.accessToken)||"")},enabled:!!(e&&i&&!1!==r.enabled),staleTime:r.staleTime||("blob"===x?3e5:12e4),gcTime:r.gcTime||6e5,retry:(e,t)=>{var r,n;return!((null==t||null==(r=t.message)?void 0:r.includes("401"))||(null==t||null==(n=t.message)?void 0:n.includes("403")))&&e<15},retryDelay:e=>Math.min(1e3*Math.pow(2,e),3e4)}),f=(0,s.jE)(),g=n.useCallback(async()=>{if(!e||!t)return null;let r=c(t),n=d.content(e,r,x);return await f.invalidateQueries({queryKey:n}),f.getQueryData(n)||null},[e,t,x,f]);return{...p,refreshCache:g,failureCount:p.failureCount||0,failureReason:p.failureReason,getCachedFile:()=>Promise.resolve(p.data),getFromCache:()=>p.data,cache:new Map}}function x(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{session:s}=(0,l.A)(),u=(0,i.y3)(12e4),h=t?c(t):null;(0,n.useEffect)(()=>{e&&h&&console.log("[useDirectoryQuery] Query key:",{sandboxId:e,directoryPath:t,normalizedPath:h,queryKey:d.directory(e,h)})},[e,t,h]);let m=(0,a.I)({queryKey:e&&h?d.directory(e,h):[],queryFn:async()=>{if(!e||!h)throw Error("Missing required parameters");console.log("[useDirectoryQuery] Fetching files for path:",h);let t=await (0,o.XY)(e,h);return console.log("[useDirectoryQuery] Fetched files:",t.length,"files"),t},enabled:!!(e&&h&&!1!==r.enabled&&u),staleTime:void 0!==r.staleTime?r.staleTime:0,gcTime:3e5,retry:(e,t)=>{var r,n,a;return!((null==t||null==(r=t.message)?void 0:r.includes("401"))||(null==t||null==(n=t.message)?void 0:n.includes("403"))||(null==t||null==(a=t.message)?void 0:a.includes("404")))&&e<3},retryDelay:e=>Math.min(1e3*Math.pow(2,e),4e3),refetchOnMount:!0,refetchOnWindowFocus:!1,refetchOnReconnect:!1});return{...m,failureCount:m.failureCount||0,failureReason:m.failureReason}}function p(){let e=(0,s.jE)(),{session:t}=(0,l.A)();return{preloadFiles:n.useCallback(async(r,n)=>{if(!(null==t?void 0:t.accessToken))return void console.warn("Cannot preload files: No authentication token available");let a=[...new Set(n)].map(async n=>{let a=c(n),s=u(n),l=d.content(r,a,s),o=e.getQueryData(l);return o||e.prefetchQuery({queryKey:l,queryFn:()=>h(r,a,s,t.accessToken),staleTime:"blob"===s?3e5:12e4})});await Promise.all(a)},[e,null==t?void 0:t.accessToken])}}},76804:(e,t,r)=>{r.d(t,{I3:()=>p,KU:()=>g,e7:()=>v,ti:()=>x,v4:()=>f,w8:()=>b});var n=r(2817),a=r(12081),s=r(64951),l=r(21856),o=r(64366),i=r(86103),c=r(69534),d=r(84955),u=r(23258),h=r(54221),m=r(21528);function x(e){let t=(0,m.uQ)(e);return["png","jpg","jpeg","gif","webp","svg","bmp"].includes(t)?"image":["js","jsx","ts","tsx","html","css","json","py","java","c","cpp"].includes(t)?"code":["txt","log","env"].includes(t)?"text":["md","markdown"].includes(t)?"markdown":"pdf"===t?"pdf":["mp3","wav","ogg","flac"].includes(t)?"audio":["mp4","webm","mov","avi"].includes(t)?"video":["csv","tsv"].includes(t)?"csv":["xl
1s","xlsx"].includes(t)?"spreadsheet":["zip","rar","tar","gz"].includes(t)?"archive":["db","sqlite","sql"].includes(t)?"database":"other"}function p(e){return({image:n.default,code:a.default,text:s.default,markdown:s.default,pdf:l.default,audio:o.default,video:i.default,spreadsheet:c.default,csv:c.default,archive:d.default,database:u.default,other:h.default})[e]}function f(e,t){return"code"===e&&t?t.toUpperCase():({image:"Image",code:"Code",text:"Text",markdown:"Markdown",pdf:"PDF",audio:"Audio",video:"Video",spreadsheet:"Spreadsheet",csv:"CSV",archive:"Archive",database:"Database",other:"File"})[e]}function g(e,t){let r=(5*e.length%800+200)*({image:5,video:20,audio:10,code:.5,text:.3,markdown:.3,pdf:8,spreadsheet:3,csv:2,archive:5,database:4,other:1})[t];return r<1024?"".concat(Math.round(r)," B"):r<1048576?"".concat((r/1024).toFixed(1)," KB"):"".concat((r/1048576).toFixed(1)," MB")}function b(e,t){if(!e)return t;"workspace"===t||t.startsWith("workspace/")?t="/"+t:t.startsWith("/workspace")||(t="/workspace/".concat(t.startsWith("/")?t.substring(1):t));try{t=t.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16)))}catch(e){console.error("Error processing Unicode escapes in path:",e)}let r=new URL("".concat("https://api.rationalgo.ai/v1","/sandboxes/").concat(e,"/files/content"));return r.searchParams.append("path",t),r.toString()}function v(e){return e.split("/").pop()||"file"}},77371:(e,t,r)=>{r.d(t,{W:()=>b});var n=r(78542),a=r(18558),s=r(34298),l=r(72842),o=r(77475),i=r(83797),c=r(27732),d=r.n(c),u=r(72409),h=r(69534),m=r(78001),x=r(33591),p=r(236),f=r(24437),g=r(73511);function b(e){let{content:t,className:r,compact:c=!1,containerHeight:b=300}=e,[v,w]=(0,a.useState)(""),[j,y]=(0,a.useState)({column:"",direction:null}),[N,_]=(0,a.useState)(new Set),[E,k]=(0,a.useState)(1),[C]=(0,a.useState)(50),S=function(e){if(!e)return{data:[],headers:[],meta:null};try{let t=d().parse(e,{header:!0,skipEmptyLines:!0,dynamicTyping:!0}),r=[];return t.meta&&t.meta.fields&&(r=t.meta.fields||[]),{headers:r,data:t.data,meta:t.meta}}catch(e){return console.error("Error parsing CSV:",e),{headers:[],data:[],meta:null}}}(t),D=0===S.data.length,A=(0,a.useMemo)(()=>{let e=S.data;return v&&(e=e.filter(e=>Object.values(e).some(e=>null!=e&&String(e).toLowerCase().includes(v.toLowerCase())))),j.column&&j.direction&&(e=[...e].sort((e,t)=>{let r=e[j.column],n=t[j.column];if(null==r&&null==n)return 0;if(null==r)return"asc"===j.direction?-1:1;if(null==n)return"asc"===j.direction?1:-1;if("number"==typeof r&&"number"==typeof n)return"asc"===j.direction?r-n:n-r;let a=String(r).toLowerCase(),s=String(n).toLowerCase();return a<s?"asc"===j.direction?-1:1:a>s?"asc"===j.direction?1:-1:0})),e},[S.data,v,j]),L=Math.ceil(A.length/C),I=(E-1)*C,R=A.slice(I,I+C),P=S.headers.filter(e=>!N.has(e)),T=e=>{y(t=>{if(t.column!==e)return{column:e,direction:"asc"};{let r="asc"===t.direction?"desc":"desc"===t.direction?null:"asc";return{column:r?e:"",direction:r}}})};return D?(0,n.jsx)("div",{className:(0,u.cn)("w-full h-full flex items-center justify-center",r),children:c?(0,n.jsx)("div",{className:"text-muted-foreground text-sm",children:"No data"}):(0,n.jsxs)("div",{className:"text-center space-y-4",children:[(0,n.jsx)("div",{className:"w-16 h-16 mx-auto rounded-full bg-muted flex items-center justify-center",children:(0,n.jsx)(h.default,{className:"h-8 w-8 text-muted-foreground"})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-lg font-medium text-foreground",children:"No Data"}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:"This CSV file appears to be empty or invalid."})]})]})}):c?(0,n.jsx)("div",{className:(0,u.cn)("w-full h-full",r),children:(0,n.jsx)(i.d,{headers:P,data:A,sortConfig:j,onSort:T,containerHeight:b})}):(0,n.jsxs)("div",{className:(0,u.cn)("w-full h-full flex flex-col bg-transparent",r),children:[(0,n.jsxs)("div",{className:"flex-shrink-0 border-b bg-muted/30 p-4 space-y-3",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(h.default,{className:"h-5 w-5 text-primary"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"font-medium text-foreground",children:"CSV Data"}),(0,n.jsxs)("p",{className:"text-xs text-muted-foreground",children:["- ",A.length.toLocaleStr
1ing()," rows, ",P.length," columns",v&&" (filtered from ".concat(S.data.length.toLocaleString(),")")]})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)(o.E,{variant:"outline",className:"text-xs",children:["Page ",E," of ",L]}),(0,n.jsxs)(g.rI,{children:[(0,n.jsx)(g.ty,{asChild:!0,children:(0,n.jsxs)(l.$,{variant:"outline",size:"sm",children:[(0,n.jsx)(m.default,{className:"h-4 w-4 mr-1"}),"Columns"]})}),(0,n.jsxs)(g.SQ,{align:"end",className:"w-48",children:[(0,n.jsx)("div",{className:"px-2 py-1.5 text-sm font-medium",children:"Show/Hide Columns"}),(0,n.jsx)(g.mB,{}),S.headers.map(e=>(0,n.jsx)(g.hO,{checked:!N.has(e),onCheckedChange:()=>{_(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},children:e},e))]})]})]})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(x.default,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,n.jsx)(s.p,{placeholder:"Search data...",value:v,onChange:e=>{w(e.target.value),k(1)},className:"pl-9"})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,n.jsx)("div",{className:"w-full h-full overflow-auto scrollbar-thin scrollbar-thumb-zinc-300 dark:scrollbar-thumb-zinc-700 scrollbar-track-transparent",children:(0,n.jsx)(i.d,{headers:P,data:R,sortConfig:j,onSort:T,searchTerm:v,onClearSearch:()=>w("")})})}),L>1&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center justify-between border-t border-hairline px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"text-[11.5px] text-muted-foreground tabular-nums",children:[I+1,"â",Math.min(I+C,A.length)," of ",A.length.toLocaleString()," rows"]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:()=>k(e=>Math.max(1,e-1)),disabled:1===E,title:"Previous page",className:"flex h-6 w-6 items-center justify-center rounded-[6px] border border-border text-muted-foreground transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50 disabled:text-text-subtle disabled:hover:bg-transparent",children:(0,n.jsx)(p.default,{className:"h-[13px] w-[13px]",strokeWidth:2.5})}),(0,n.jsxs)("span",{className:"min-w-[56px] text-center text-[11.5px] font-semibold text-muted-foreground tabular-nums",children:[E," / ",L]}),(0,n.jsx)("button",{type:"button",onClick:()=>k(e=>Math.min(L,e+1)),disabled:E===L,title:"Next page",className:"flex h-6 w-6 items-center justify-center rounded-[6px] border border-border text-muted-foreground transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50 disabled:text-text-subtle disabled:hover:bg-transparent",children:(0,n.jsx)(f.default,{className:"h-[13px] w-[13px]",strokeWidth:2.5})})]})]})]})}},77738:(e,t,r)=>{r.d(t,{s:()=>h});var n=r(78542),a=r(18558),s=r(46032),l=r(2803),o=r(51591),i=r(23427),c=r(29798),d=r(25094),u=r(72842);function h(e){var t;let{presentationName:r,project:h,onFullScreenClick:m,className:x="",initialSlide:p}=e,{openPresentation:f}=(0,d.usePresentationViewerStore)(),[g,b]=(0,a.useState)(null),[v,w]=(0,a.useState)(!0),[j,y]=(0,a.useState)(null),[N,_]=(0,a.useState)(0),E=(0,a.useRef)(null),k=(0,a.useCallback)(async function(){var e;let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(!r||!(null==h||null==(e=h.sandbox)?void 0:e.sandbox_url))return void w(!1);w(!0),y(null),_(t);try{let e=r.replace(/[^a-zA-Z0-9\-_]/g,"").toLowerCase(),n=(0,l.i)(h.sandbox.sandbox_url,"presentations/".concat(e,"/metadata.json")),a="".concat(n,"?t=").concat(Date.now());console.log("[PresentationSlidePreview] Loading metadata (attempt ".concat(t+1,"):"),a);let s=await fetch(a,{cache:"no-cache",headers:{"Cache-Control":"no-cache","X-Daytona-Skip-Preview-Warning":"true"}});if(s.ok){let e=await s.json();console.log("[PresentationSlidePreview] Metadata loaded successfully:",e),b(e),w(!1),y(null)}else throw Error("HTTP ".concat(s.status,": ").concat(s.statusText))}catch(e){if(console.error("[PresentationSlidePreview] Error loading metadata (attempt ".concat(t+1,"):"),e),t<10){let e=Math.min(1e3*Math.pow(1.5,t),5e3);console.log("[PresentationSlidePreview] Retrying in ".concat(e,"ms...")),E.current=setTimeout(()=>{k(t+1)},e)}else y(e instanceof Error?e.message:"Failed to load presentation"),w(!1)}},[r,null==h||null==(t=h.sandbox)?void 0:t.sandbox_url]);if((0,a.useEffect)(()=>(k(0),()=>{E.current&&clearTimeout(E.current)}),[k]),v)return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center p-8 bg-bg-subtle rounded-lg border border-hairline ".concat(x),children:[(0,n.jsx)(c.RgoLoader,{customSize:40,className:"mb-3"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading presentation..."}),N>0&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground mt-1",children:"Still loadingâ¦"})]});if(j||!g)return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center p-6 bg-bg-subtle rounded-lg border border-hairline ".concat(x),children:[(0,n.jsx)(o.default,{className:"h-[26px] w-[26px] text-text-subtle opacity-60 mb-2"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mb-3 text-center",children:j||"Presentation not found"}),(0,n.jsxs)(u.$,{variant:"outline",size:"sm",onClick:()=>k(0),className:"gap-1.5 h-7 text-xs",children:[(0,n.jsx)(i.default,{className:"h-3 w-3"}),"Retry"]})]});let C=Object.entries(g.slides).map(e=>{let[t,r]=e;return{number:parseInt(t),...r}}).sort((e,t)=>
1e.number-t.number),S=p&&C.find(e=>e.number===p)||C[0];return S?(0,n.jsx)(s.M,{slide:S,project:h,onFullScreenClick:e=>{var t;m?m(e):f&&(null==h||null==(t=h.sandbox)?void 0:t.sandbox_url)&&f(r,h.sandbox.sandbox_url,{sandboxId:h.sandbox.id,projectId:h.id,initialSlide:e})},className:x,showFullScreenButton:!0}):null}},79634:(e,t,r)=>{r.d(t,{d:()=>m});var n=r(78542),a=r(18558),s=r(72409),l=r(72842),o=r(53401),i=r(45068),c=r(94273),d=r(39214),u=r(68628),h=r(79083);function m(e){let{url:t,className:r}=e,[m,x]=(0,a.useState)(1),[p,f]=(0,a.useState)(0),[g,b]=(0,a.useState)(!1),[v,w]=(0,a.useState)({x:0,y:0}),[j,y]=(0,a.useState)({x:0,y:0}),[N,_]=(0,a.useState)(!0),[E,k]=(0,a.useState)(!1),[C,S]=(0,a.useState)(!1),[D,A]=(0,a.useState)(null),[L,I]=(0,a.useState)(!1),R=(0,a.useRef)(null),P=(0,a.useRef)(null),T=(null==t?void 0:t.toLowerCase().endsWith(".svg"))||(null==t?void 0:t.includes("image/svg"));(0,a.useEffect)(()=>{N&&w({x:0,y:0})},[m,N]);let M=()=>{if(k(!0),S(!1),P.current){var e;A({width:P.current.naturalWidth,height:P.current.naturalHeight,type:T?"SVG":(null==(e=t.split(".").pop())?void 0:e.toUpperCase())||"Image"})}},z=()=>{k(!1),S(!0)},U="scale(".concat(m,") rotate(").concat(p,"deg)"),B="translate(".concat(v.x,"px, ").concat(v.y,"px)"),[F,O]=(0,a.useState)(!1);return(0,n.jsxs)("div",{className:(0,s.cn)("relative w-full h-full group",r),onMouseEnter:()=>I(!0),onMouseLeave:()=>I(!1),children:[(0,n.jsx)("div",{className:(0,s.cn)("absolute top-4 left-1/2 -translate-x-1/2 z-10 transition-all duration-200",L||F?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"),children:(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-card border border-border rounded-xl px-2 py-1.5 shadow-lg",children:[(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 hover:bg-muted",onClick:()=>{let e=Math.max(m-.25,.5);x(e),.5===e&&_(!0)},title:"Zoom out",disabled:C,children:(0,n.jsx)(o.default,{className:"h-4 w-4"})}),(0,n.jsxs)("span",{className:"text-xs font-medium px-2 min-w-[48px] text-center text-muted-foreground",children:[Math.round(100*m),"%"]}),(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 hover:bg-muted",onClick:()=>{x(e=>Math.min(e+.25,3)),_(!1)},title:"Zoom in",disabled:C,children:(0,n.jsx)(i.default,{className:"h-4 w-4"})}),(0,n.jsx)("div",{className:"w-px h-4 bg-border mx-1"}),(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 hover:bg-muted",onClick:()=>{f(e=>(e+90)%360)},title:"Rotate",disabled:C,children:(0,n.jsx)(c.default,{className:"h-4 w-4"})}),(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 hover:bg-muted",onClick:()=>{N?(x(1),_(!1)):(x(.5),w({x:0,y:0}),_(!0))},title:N?"Actual size":"Fit to screen",disabled:C,children:N?(0,n.jsx)(d.default,{className:"h-4 w-4"}):(0,n.jsx)(u.default,{className:"h-4 w-4"})}),(0,n.jsx)("div",{className:"w-px h-4 bg-border mx-1"}),(0,n.jsx)(l.$,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 hover:bg-muted",onClick:()=>O(!F),title:"Image information",children:(0,n.jsx)(h.default,{className:"h-4 w-4"})})]})}),F&&D&&(0,n.jsx)("div",{className:"absolute top-16 right-4 z-10 bg-card p-4 rounded-xl shadow-lg border border-border text-sm min-w-[180px]",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex justify-between gap-6",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:"Type"}),(0,n.jsx)("span",{className:"font-medium",children:D.type})]}),(0,n.jsxs)("div",{className:"flex justify-between gap-6",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:"Size"}),(0,n.jsxs)("span",{className:"font-medium",children:[D.width," \xd7 ",D.height]})]}),(0,n.jsxs)("div",{className:"flex justify-between gap-6",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:"Zoom"}),(0,n.jsxs)("span",{className:"font-medium",children:[Math.round(100*m),"%"]})]})]})}),(0,n.jsx)("div",{ref:R,className:"w-full h-full overflow-hidden relative bg-transparent",onMouseDown:e=>{m>.5&&(b(!0),y({x:e.clientX-v.x,y:e.clientY-v.y}))},onMouseMove:e=>{g&&m>.5&&w({x:e.clientX-j.x,y:e.clientY-j.y})},onMouseUp:()=>{b(!1)},onMouseLeave:()=>{b(!1)},style:{cursor:g?"grabbing":m>.5?"grab":"default"},children:C?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full p-6 text-center",children:[(0,n.jsx)("p",{className:"text-destructive font-medium mb-2",children:"Failed to load image"}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:"The image could not be displayed"})]}):(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center p-8",style:{transform:N?"none":B,transition:g?"none":"transform 0.1s ease"},children:T?(0,n.jsx)("object",{data:t,type:"image/svg+xml",className:"max-w-full max-h-full",style:{transform:U,transition:"transform 0.2s ease",width:"100%",height:"100%"},children:(0,n.jsx)("img",{ref:P,src:t,alt:"SVG preview",className:"max-w-full max-h-full object-contain",style:{transform:U,transition:"transform 0.2s ease"},draggable:!1,onLoad:M,onError:z})}):(0,n.jsx)("img",{ref:P,src:t,alt:"Image preview",className:"max-w-full max-h-full object-contain",style:{transform:U,transition:"transform 0.2s ease",boxShadow:E?"0 8px 32px -4px rgba(0, 0, 0, 0.15)":"none"},draggable:!1,onLoad:M,onError:z})})})]})}},80832:(e,t,r)=>{r.d(t,{O:()=>l});var n=r(78542),a=r(18558),s=r(8586);
1function l(e){let{content:t,className:r=""}=e,l=(0,a.useMemo)(()=>{let e=(0,s.wO)(t);try{let t=JSON.parse(e);return JSON.stringify(t,null,2)}catch(t){return e}},[t]);return(0,n.jsx)("div",{className:"h-full w-full overflow-auto px-6 py-4 ".concat(r),children:(0,n.jsx)("pre",{className:"text-xs font-mono text-zinc-700 dark:text-zinc-300 whitespace-pre-wrap break-words",children:l})})}},82117:(e,t,r)=>{r.d(t,{K:()=>h});var n=r(78542),a=r(18558),s=r(72409),l=r(72842),o=r(68580),i=r(27496),c=r(29798),d=r(40212);r(52510);var u=r(2803);function h(e){var t,r;let{binaryUrl:h,filePath:m,fileName:x,className:p,project:f,onDownload:g,isDownloading:b}=e,[v,w]=(0,a.useState)(!0),[j,y]=(0,a.useState)(null),N=(0,a.useMemo)(()=>{var e;if((null==f||null==(e=f.sandbox)?void 0:e.sandbox_url)&&m){let e=(0,u.i)(f.sandbox.sandbox_url,m);return console.log("[PptxRenderer] Public URL:",e),e||null}return h&&!h.startsWith("blob:")?h:null},[h,m,null==f||null==(t=f.sandbox)?void 0:t.sandbox_url]),_=(0,a.useMemo)(()=>N?[{uri:N,fileName:x,fileType:x.endsWith(".ppt")?"ppt":"pptx"}]:[],[N,x]);return((0,a.useEffect)(()=>{var e;N?(w(!1),y(null)):(null==f||null==(e=f.sandbox)?void 0:e.sandbox_url)||!m?!m&&(null==h?void 0:h.startsWith("blob:"))?(w(!1),y("Cannot preview local file.")):m||h?w(!0):(w(!1),y("No file available")):(w(!1),y("Waiting for computer to start..."))},[N,h,m,null==f||null==(r=f.sandbox)?void 0:r.sandbox_url]),v)?(0,n.jsx)("div",{className:(0,s.cn)("w-full h-full flex items-center justify-center",p),children:(0,n.jsx)(c.RgoLoader,{size:"medium"})}):j||!N?(0,n.jsx)("div",{className:(0,s.cn)("w-full h-full flex items-center justify-center",p),children:(0,n.jsxs)("div",{className:"text-center space-y-3 p-6",children:[(0,n.jsx)(o.default,{className:"h-8 w-8 text-amber-500 mx-auto"}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:j||"Cannot preview"}),g&&(0,n.jsxs)(l.$,{size:"sm",onClick:g,disabled:b,children:[b?(0,n.jsx)(c.RgoLoader,{customSize:22}):(0,n.jsx)(i.default,{className:"h-4 w-4 mr-2"}),"Download"]})]})}):(0,n.jsxs)("div",{className:(0,s.cn)("w-full h-full",p),style:{minHeight:"500px"},children:[(0,n.jsx)("style",{children:"\n #react-doc-viewer {\n height: 100% !important;\n min-height: 500px !important;\n }\n #react-doc-viewer > div {\n height: 100% !important;\n }\n #proxy-renderer {\n height: 100% !important;\n }\n #msdoc-renderer {\n height: 100% !important;\n }\n #msdoc-iframe {\n height: 100% !important;\n min-height: 500px !important;\n }\n "}),(0,n.jsx)(d.Ay,{documents:_,pluginRenderers:d.tu,config:{header:{disableHeader:!0,disableFileName:!0}},style:{width:"100%",height:"100%",minHeight:"500px"}})]})}},83797:(e,t,r)=>{r.d(t,{d:()=>d});var n=r(78542);r(18558);var a=r(72842),s=r(72409),l=r(58061),o=r(11105),i=r(5776),c=r(42061);function d(e){let{headers:t,data:r,sortConfig:d,onSort:u,searchTerm:h,onClearSearch:m,className:x,containerHeight:p=500}=e,{resolvedTheme:f}=(0,l.D)(),g=(()=>{let e="dark"===f;return{vertical:e?"rgb(64 64 64)":"rgb(229 229 229)",horizontal:e?"rgb(64 64 64)":"rgb(229 229 229)",background:"var(--muted)"}})(),b=e=>null==e?"":"number"==typeof e?e.toLocaleString():"boolean"==typeof e?e?"Yes":"No":"object"==typeof e?"string"==typeof e.text?e.text:"string"==typeof e.url?e.url:"string"==typeof e.hyperlink?e.hyperlink:"string"==typeof e.Target?e.Target:void 0!==e.v?String(e.v):JSON.stringify(e):String(e);return(0,n.jsx)("div",{className:(0,s.cn)("w-full relative h-full !bg-card",x),children:(0,n.jsxs)("div",{className:"w-full h-full overflow-auto relative min-h-full",style:{display:"grid",gridTemplateColumns:"repeat(".concat(t.length,", 150px)"),gridAutoRows:"48px",minHeight:"100%",backgroundColor:g.background,backgroundImage:"\n repeating-linear-gradient(\n to right,\n transparent 0px,\n transparent 149px,\n ".concat(g.vertical," 149px,\n ").concat(g.vertical," 150px\n ),\n repeating-linear-gradient(\n to bottom,\n transparent 0px,\n transparent 47px,\n ").concat(g.horizontal," 47px,\n ").concat(g.horizontal," 48px\n )\n "),backgroundSize:"".concat((t.length-1)*150+149,"px 48px, 150px 48px"),backgroundPosition:"0 0",backgroundAttachment:"local"},children:[(0,n.jsx)("div",{className:(0,s.cn)("sticky top-0 z-10 pointer-events-none","dar
1k"===f?"bg-muted":"bg-background"),style:{position:"absolute",left:"".concat(150*t.length,"px"),right:0,height:"48px",top:0}}),t.map((e,t)=>(0,n.jsx)("div",{className:(0,s.cn)("sticky top-0 z-20 flex items-center px-4 font-medium","dark"===f?"bg-muted":"bg-background"),style:{gridColumn:t+1,gridRow:1,height:"48px"},children:(0,n.jsxs)("button",{onClick:()=>u(e),className:"flex items-center gap-2 hover:text-primary transition-colors group w-full text-left",children:[(0,n.jsx)("span",{className:"truncate",children:e}),(0,n.jsx)("div",{className:"opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:d.column!==e?(0,n.jsx)(o.default,{className:"h-3 w-3 text-muted-foreground"}):"asc"===d.direction?(0,n.jsx)(i.default,{className:"h-3 w-3 text-primary"}):(0,n.jsx)(c.default,{className:"h-3 w-3 text-primary"})})]})},"header-".concat(t))),r.map((e,r)=>t.map((t,a)=>{let l=e[t];return(0,n.jsx)("div",{className:(0,s.cn)("flex items-center px-4 text-sm hover:bg-muted/30 transition-colors","number"==typeof l?"text-right font-mono":"boolean"==typeof l?l?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400":""),style:{gridColumn:a+1,gridRow:r+2,height:"48px"},children:(0,n.jsx)("div",{className:"truncate w-full",title:b(l),children:b(l)})},"".concat(r,"-").concat(a))})),0===r.length&&h&&(0,n.jsx)("div",{className:"col-span-full py-8 text-center text-muted-foreground",style:{gridColumn:"1 / ".concat(t.length+1),gridRow:2},children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("p",{children:['No results found for "',h,'"']}),m&&(0,n.jsx)(a.$,{variant:"outline",size:"sm",onClick:m,children:"Clear search"})]})})]})})}},84192:(e,t,r)=>{r.d(t,{j:()=>x});var n=r(78542),a=r(18558),s=r(8586),l=r(72409),o=r(72842),i=r(49215),c=r(61390),d=r(28519),u=r(99870),h=r(2803),m=r(40181);function x(e){var t,r;let{content:x,previewUrl:p,className:f,project:g}=e,[b,v]=(0,a.useState)("preview"),[w,j]=(0,a.useState)(0),y=(0,a.useMemo)(()=>{if(!p)return!1;let e=p.includes("://"),t=p.includes("/sandboxes/")||p.includes("/files/content");return e&&!t},[p]),N=(0,a.useRef)(null),_=(0,a.useMemo)(()=>{var e;if(N.current&&(URL.revokeObjectURL(N.current),N.current=null),x&&!(null==g||null==(e=g.sandbox)?void 0:e.sandbox_url)&&!y){let e=new Blob([x],{type:"text/html"}),t=URL.createObjectURL(e);return N.current=t,t}},[x,null==g||null==(t=g.sandbox)?void 0:t.sandbox_url,y]);(0,a.useEffect)(()=>()=>{N.current&&(URL.revokeObjectURL(N.current),N.current=null)},[]);let E=(0,a.useMemo)(()=>{if(y)return"";try{if(p.includes("/sandboxes/")&&p.includes("/files/content")){let e=p.match(/[?&]path=([^&]+)/);if(e){let t=decodeURIComponent(e[1]).replace(/^\/workspace\//,"");if(t)return t}if(p.includes("://")){let e=new URL(p).searchParams.get("path");if(e){let t=decodeURIComponent(e).replace(/^\/workspace\//,"");if(t)return t}}}if(!p.includes("://")&&!p.includes("/sandboxes/")){let e=p.replace(/^\/workspace\//,"");if(e)return e}return""}catch(e){return console.error("Error extracting file path from previewUrl:",e,{previewUrl:p}),""}},[p,y]),k=(0,a.useMemo)(()=>{var e;return y?p:(null==g||null==(e=g.sandbox)?void 0:e.sandbox_url)&&E&&!E.includes("://")&&!E.includes("/sandboxes/")?(0,h.i)(g.sandbox.sandbox_url,E):_||(!p||p.includes("/sandboxes/")||p.includes("/files/content")?"":p)},[null==g||null==(r=g.sandbox)?void 0:r.sandbox_url,E,p,y,_]);return(0,n.jsx)("div",{className:(0,l.cn)("w-full h-full flex flex-col",f),children:(0,n.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[(0,n.jsxs)("div",{className:"absolute left-2 top-2 z-10 flex items-center gap-2",children:[(0,n.jsxs)(o.$,{variant:"ghost",size:"sm",className:(0,l.cn)("flex items-center gap-2 bg-background/80 backdrop-blur-sm hover:bg-background/90","preview"===b&&"bg-background/90"),onClick:()=>v("preview"),children:[(0,n.jsx)(i.default,{className:"h-4 w-4"}),"Preview"]}),(0,n.jsxs)(o.$,{variant:"ghost",size:"sm",className:(0,l.cn)("flex items-center gap-2 bg-background/80 backdrop-blur-sm hover:bg-background/90","code"===b&&"bg-background/90"),onClick:()=>v("code"),children:[(0,n.jsx)(c.default,{className:"h-4 w-4"}),"Code"]}),(0,n.jsxs)(o.$,{variant:"ghost",size:"sm",className:"flex items-center gap-2 bg-background/80 backdrop-blur-sm hover:bg-background/90",onClick:()=>window.open(k||p,"_blank"),disabled:!k&&!p,children:[(0,n.jsx)(d.default,{className:"h-4 w-4"}),"Open"]}),(0,n.jsx)(o.$,{variant:"ghost",size:"sm",className:"flex items-center gap-2 bg-background/80 backdrop-blur-sm hover:bg-background/90",onClick:()=>j(e=>e+1),title:"Refresh preview",children:(0,n.jsx)(u.default,{className:"h-4 w-4"})})]}),"preview"===b?(0,n.jsx)("div",{className:"absolute inset-0",children:k?(0,n.jsx)(m.P,{url:k,title:"HTML Preview",className:"w-full h-full",autoRetry:!0,maxRetries:10,retryInterval:2e3,projectId:null==g?void 0:g.id,onRetry:()=>j(e=>e+1)},"preview-".concat(w)):(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center text-muted-foreground",children:"Unable to load HTML preview"})}):(0,n.jsx)("div",{className:"absolute inset-0 overflow-auto",children:(0,n.jsx)(s.BY,{content:x,fileName:"preview.html",readOnly:!0,className:"w-full min-h-full"})})]})})}},84454:(e,t,r)=>{r.d(t,{BI:()=>d,K2:()=>c,eP:()=>u});var n=r(68432),a=r(23439),s=r(87107),l=r(88003),o=r(47044),i=r(93434);r(18558);let c=(e,t)=>(0,n.I)({queryKey:l.X.details(e),queryFn:()=>(0,o.fG)(e),enabled:!!e,retry:(e,t)=>{var r;let n=(null==t||null==(r=t.message)?void 0:r.toLowerCase())||"";return!!(n.includes("404")||n.includes("not found"))&&e<5||e<1},retryDelay:(e,t)=>{var r;let n=(null==t||null==(r=t.message)?void 0:r.toLowerCase())||"";return n.includes("404")||n.includes("not found")?Math.min(500*(e+1),2e3):1e3},...t}),d=e=>{var t,r;let s=null!=(t=null==e?void 0:e.page)?t:1,o=null!=(r=null==e?void 0:e.limit)?r:20,c=null==e?void 0:e.projectMode,d=[...l.X.lists(),"paginated",s,o,null!=c?c:"all"];return(0,n.I)({queryKey:d,queryFn:async()=>await (0,i.getThreadsPaginated)(void 0,s,o,c),staleTime:3e5,gcTime:6e5,refetchOnWindowFocus:e=>"error"===e.state.status,placeholderData:a.rX,enabled:(null==e?void 0:e.enabled)!==!1})},u=()=>(0,s.n)({mutationFn:e=>{let{threadId:t,data:r}=e;return(0,o.e4)(t,r)}})},90373:(e,t,r)=>{r.d(t,{C:()=>p});var n=r(78542),a=r(18558),s=r(43728),l=r.n(s),o=r(28720),i=r(63505),c=r(54942),d=r(72409),u=r(58261),h=r(9601);
1function m(e){let{code:t}=e,[r,s]=(0,a.useState)(!1),l=(0,a.useCallback)(async()=>{try{await navigator.clipboard.writeText(t),s(!0),setTimeout(()=>s(!1),2e3)}catch(e){console.error("Failed to copy:",e)}},[t]);return(0,n.jsx)("button",{onClick:l,className:(0,d.cn)("absolute top-3 right-3 p-1.5 rounded-md","opacity-0 group-hover:opacity-100 transition-opacity duration-150","bg-muted hover:bg-muted/80","text-muted-foreground hover:text-foreground","focus:outline-none focus:ring-1 focus:ring-ring"),"aria-label":r?"Copied!":"Copy code",children:r?(0,n.jsx)(i.default,{className:"h-4 w-4 text-green-600 dark:text-green-400"}):(0,n.jsx)(c.default,{className:"h-4 w-4"})})}function x(e){let{children:t}=e,r=(0,a.useRef)(null),[s,l]=(0,a.useState)("");return(0,a.useEffect)(()=>{if(r.current){let e=r.current.querySelector("code");e&&l((e.textContent||"").trim())}},[t]),(0,n.jsxs)("div",{className:"relative group my-5",children:[(0,n.jsx)("pre",{ref:r,className:(0,d.cn)("p-4 rounded-xl overflow-x-auto","bg-zinc-100 dark:bg-zinc-900","border border-zinc-200 dark:border-zinc-800","text-[13px] font-mono leading-relaxed","text-zinc-800 dark:text-zinc-200","[&_code]:bg-transparent [&_code]:text-inherit [&_code]:p-0"),children:t}),s&&(0,n.jsx)(m,{code:s})]})}let p=a.memo(e=>{let{content:t,className:r,isStreaming:a=!1}=e,s="string"==typeof t?t:t?String(t):"";if(!s)return(0,n.jsx)("div",{className:(0,d.cn)("text-muted-foreground text-sm",r),children:"No content"});let i=(0,h.G6)(s);return(0,n.jsx)("div",{className:(0,d.cn)("rgo-markdown",r),children:(0,n.jsx)(o.jH,{isAnimating:a,components:{h1:e=>{let{children:t}=e;return(0,n.jsx)("h1",{className:"text-2xl font-semibold tracking-tight text-foreground mt-8 mb-4 first:mt-0 pb-2 border-b border-border/40",children:t})},h2:e=>{let{children:t}=e;return(0,n.jsx)("h2",{className:"text-xl font-semibold tracking-tight text-foreground mt-8 mb-3 first:mt-0",children:t})},h3:e=>{let{children:t}=e;return(0,n.jsx)("h3",{className:"text-lg font-semibold text-foreground mt-6 mb-2 first:mt-0",children:t})},h4:e=>{let{children:t}=e;return(0,n.jsx)("h4",{className:"text-base font-semibold text-foreground mt-5 mb-2 first:mt-0",children:t})},h5:e=>{let{children:t}=e;return(0,n.jsx)("h5",{className:"text-sm font-semibold text-foreground mt-4 mb-1 first:mt-0",children:t})},h6:e=>{let{children:t}=e;return(0,n.jsx)("h6",{className:"text-sm font-medium text-muted-foreground mt-4 mb-1 first:mt-0 uppercase tracking-wide",children:t})},p:e=>{let{children:t}=e;return(0,n.jsx)("p",{className:"text-sm text-foreground leading-relaxed my-4 first:mt-0 last:mb-0 [&:has(img)]:my-0",children:t})},ul:e=>{let{children:t}=e;return(0,n.jsx)("ul",{className:"my-4 ml-6 list-disc marker:text-muted-foreground/60 space-y-2 first:mt-0 last:mb-0 text-sm",children:t})},ol:e=>{let{children:t}=e;return(0,n.jsx)("ol",{className:"my-4 ml-6 list-decimal marker:text-muted-foreground/60 marker:font-medium space-y-2 first:mt-0 last:mb-0 text-sm",children:t})},li:e=>{let{children:t}=e;return(0,n.jsx)("li",{className:"text-sm text-foreground leading-relaxed pl-1",children:t})},a:e=>{let{href:t,children:r}=e,a=function(e){return!(!e||e.startsWith("http://")||e.startsWith("https://")||e.includes("://"))&&(e.startsWith("/")||e.startsWith("#"))}(t),s=null==t?void 0:t.startsWith("#"),o=(0,d.cn)("font-medium text-foreground","underline decoration-foreground/30 underline-offset-[3px] decoration-[1px]","hover:decoration-foreground/60 transition-colors duration-150");return s?(0,n.jsx)("a",{href:t,onClick:e=>(function(e,t){if(t.startsWith("#")){e.preventDefault();let r=t.substring(1),n=document.getElementById(r);n&&n.scrollIntoView({behavior:"smooth",block:"start"})}})(e,t),className:o,children:r}):a?(0,n.jsx)(l(),{href:t||"#",className:o,children:r}):(0,n.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:o,children:r})},code:e=>{let{children:t,className:r}=e,a=/language-(\w+)/.exec(r||""),s=a?a[1]:"",l=String(t).replace(/\n$/,""),o=null==r?void 0:r.includes("language-"),i=l.includes("\n");return o||i?!function(e,t){if(!(null==t?void 0:t.trim()))return!1;if("mermaid"===e)return!0;
1if(!e||"text"===e||"plain"===e){var r;let e=null==(r=t.trim().split("\n")[0])?void 0:r.toLowerCase().trim();return["graph","flowchart","sequencediagram","classdiagram","statediagram","erdiagram","journey","gantt","pie","gitgraph","mindmap","timeline","sankey","block","quadrant","requirement","c4context","c4container","c4component","c4dynamic","commit","branch","checkout","merge"].some(t=>e.startsWith(t.toLowerCase()))}return!1}(s,l)?(0,n.jsx)("code",{className:"text-[13px] font-mono leading-relaxed text-inherit whitespace-pre",children:t}):(0,n.jsx)(u.Z,{chart:l,className:"my-5"}):(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded-md text-[13px] font-mono bg-zinc-100 dark:bg-zinc-800/80 border border-zinc-200/80 dark:border-zinc-700/50 text-foreground",children:t})},pre:e=>{let{children:t}=e;return(0,n.jsx)(x,{children:t})},blockquote:e=>{let{children:t}=e;return(0,n.jsx)("blockquote",{className:(0,d.cn)("my-5 pl-4 py-1 text-sm","border-l-2 border-border","text-muted-foreground","[&>p]:my-2"),children:t})},hr:()=>(0,n.jsx)("hr",{className:"my-8 border-0 h-px bg-border/60"}),table:e=>{let{children:t}=e;return(0,n.jsx)("div",{className:"my-5 overflow-x-auto rounded-xl border border-border/60",children:(0,n.jsx)("table",{className:"w-full text-sm",children:t})})},thead:e=>{let{children:t}=e;return(0,n.jsx)("thead",{className:"bg-muted/50 dark:bg-muted/30 border-b border-border/60",children:t})},tbody:e=>{let{children:t}=e;return(0,n.jsx)("tbody",{className:"divide-y divide-border/40",children:t})},tr:e=>{let{children:t}=e;return(0,n.jsx)("tr",{className:"transition-colors hover:bg-muted/30",children:t})},th:e=>{let{children:t}=e;return(0,n.jsx)("th",{className:"px-4 py-3 text-left text-xs font-semibold text-foreground uppercase tracking-wider",children:t})},td:e=>{let{children:t}=e;return(0,n.jsx)("td",{className:"px-4 py-3 text-foreground",children:t})},img:e=>{let{src:t,alt:r}=e;return t?(0,n.jsxs)("span",{className:"block my-5",children:[(0,n.jsx)("img",{src:t,alt:r||"",className:(0,d.cn)("max-w-full h-auto rounded-xl","border border-border/40","shadow-sm"),loading:"lazy"}),r&&(0,n.jsx)("span",{className:"block mt-2 text-center text-sm text-muted-foreground",children:r})]}):null},strong:e=>{let{children:t}=e;return(0,n.jsx)("strong",{className:"font-semibold text-foreground",children:t})},em:e=>{let{children:t}=e;return(0,n.jsx)("em",{className:"italic text-foreground",children:t})},del:e=>{let{children:t}=e;return(0,n.jsx)("del",{className:"line-through text-muted-foreground decoration-muted-foreground/50",children:t})},input:e=>{let{checked:t,...r}=e;return(0,n.jsx)("input",{type:"checkbox",checked:t,readOnly:!0,className:(0,d.cn)("mr-2 h-4 w-4 rounded border-border","accent-secondary cursor-default","align-middle relative -top-[1px]"),...r})},div:e=>{let{children:t,style:r,className:a,...s}=e;return(0,n.jsx)("div",{className:(0,d.cn)("text-sm text-foreground",a),style:r,...s,children:t})},span:e=>{let{children:t,style:r,className:a,...s}=e;return(0,n.jsx)("span",{className:(0,d.cn)("text-foreground",a),style:r,...s,children:t})}},children:i})})});p.displayName="UnifiedMarkdown"},93434:(e,t,r)=>{r.d(t,{DM:()=>i,LB:()=>o,U1:()=>l,VL:()=>u,getThreadsPaginated:()=>d,vr:()=>c});var n=r(40570),a=r(25251),s=r(76524);let l=async e=>{let t=await s.H.get("/projects/".concat(e),{showErrors:!0});if(t.error)throw(0,a.hS)(t.error,{operation:"load project",resource:"project ".concat(e)}),Error(t.error.message||"Project not found: ".concat(e));if(!t.data)throw Error("Project not found: ".concat(e));let r=t.data;return{id:r.project_id,name:r.name||"",description:r.description||"",is_public:r.is_public||!1,created_at:r.created_at,updated_at:r.updated_at||r.created_at,metadata:r.metadata,sandbox:r.sandbox||{id:"",pass:"",vnc_preview:"",sandbox_url:""},icon_name:r.icon_name}},o=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:100;try{var n,a;let l=new URLSearchParams({page:t.toString(),limit:r.toString()}),o=await s.H.get("/projects/".concat(e,"/threads?").concat(l.toString()),{showErrors:!1});if(o.error)throw console.error("Error getting project threads:",o.error),o.error;if(!(null==(n=o.data)?void 0:n.threads))return{threads:[],pagination:(null==(a=o.data)?void 0:a.pagination)||{page:1,limit:20,total:0,pages:0}};let i=o.data.threads.map(e=>({thread_id:e.thread_id,project_id:e.project_id,name:e.name,created_at:e.created_at,updated_at:e.updated_at,metadata:e.metadata||{}}));return{threads:i,pagination:o.data.pagination||{page:t,limit:r,total:i.length,pages:1}}}catch(e){throw console.error("Error fetching project threads:",e),e}},i=async e=>{let t=await (0,n.getAccessTokenAsync)();if(!t)throw Error("You must be logged in to create a thread");let r=await fetch("".concat("https://api.rationalgo.ai/v1","/projects/").concat(e,"/threads"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(t)}});if(!r.ok){let e=await r.text().catch(()=>"Unknown error");throw(0,a.hS)(Error(e),{operation:"create thread in project",resource:"thread"}),Error(e)}return await r.json()},c=async(e,t)=>{var r,n,a,l,o,i,c;if(!e||""===e)throw Error("Cannot update project: Invalid project ID");let u=await d(void 0,1,20);if(!(null==u?void 0:u.threads))throw Error("Failed to find thread for project");let h=u.threads.find(t=>t.project_id===e);if(!h)throw Error("No thread found for project ".concat(e));let m={};void 0!==t.name&&(m.title=t.name),void 0!==t.is_public&&(m.is_public=t.is_public);let x=await s.H.patch("/threads/".concat(h.thread_id),m,{showErrors:!0});if(x.error)throw Error(x.error.message||"Failed to update project");return{id:e,name:void 0!==t.name?t.name:(null==(r=h.project)?void 0:r.name)||"",description:(null==(n=h.project)?void 0:n.description)||"",is_public:void 0!==t.is_public?t.is_public:(null==(a=h.project)?void 0:a.is_public)||
1!1,created_at:(null==(l=h.project)?void 0:l.created_at)||"",updated_at:null==(o=h.project)?void 0:o.updated_at,sandbox:(null==(i=h.project)?void 0:i.sandbox)||{id:"",pass:"",vnc_preview:"",sandbox_url:""},icon_name:null==(c=h.project)?void 0:c.icon_name}},d=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:20,n=arguments.length>3?arguments[3]:void 0;try{var a,l;let o=new URLSearchParams({page:t.toString(),limit:r.toString()});n&&o.set("project_mode",n);let i=await s.H.get("/threads?".concat(o.toString()),{showErrors:!1});if(i.error)throw console.error("Error getting paginated threads:",i.error),i.error;if(!(null==(a=i.data)?void 0:a.threads))return{threads:[],pagination:(null==(l=i.data)?void 0:l.pagination)||{page:1,limit:50,total:0,pages:0}};let c=i.data.threads.map(e=>({thread_id:e.thread_id,project_id:e.project_id,name:e.name,created_at:e.created_at,updated_at:e.updated_at,metadata:e.metadata||{},project:e.project}));return e&&(c=c.filter(t=>t.project_id===e)),{threads:c,pagination:i.data.pagination||{page:t,limit:r,total:c.length,pages:1}}}catch(e){throw console.error("Error fetching paginated threads:",e),e}},u=async e=>{try{let t=await (0,n.getAccessTokenAsync)(),r={"Content-Type":"application/json"};t&&(r.Authorization="Bearer ".concat(t));let a=!new URLSearchParams(window.location.search).has("debug_messages"),s=await fetch("".concat("https://api.rationalgo.ai/v1","/threads/").concat(e,"/messages?order=asc&optimized=").concat(a),{headers:r,cache:"no-store"});if(!s.ok){let e=await s.text().catch(()=>"Unknown error"),t=Error("Error getting messages: ".concat(e));throw t.status=s.status,t}return(await s.json()).messages||[]}catch(e){throw e}}},95228:(e,t,r)=>{r.d(t,{pH:()=>i,Be:()=>d.Be,R2:()=>d.R2,RP:()=>d.x2,x2:()=>d.x2,np:()=>x,OG:()=>d.OG,c:()=>p,Tp:()=>c});var n=r(18558),a=r(35284);let s=new Map,l=new Map;function o(e){if(!e)return"/workspace";("workspace"===e||e.startsWith("workspace/"))&&(e="/"+e),e.startsWith("/workspace")||(e="/workspace/".concat(e.startsWith("/")?e.substring(1):e));try{e=e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16)))}catch(e){console.error("Error processing Unicode escapes in path:",e)}return e}let i={get:e=>{var t;return(null==(t=s.get(e))?void 0:t.content)||null},set:(e,t)=>{e&&null!=t&&s.set(e,{content:t,timestamp:Date.now(),type:"string"==typeof t&&t.startsWith("blob:")?"url":"content"})},has:e=>s.has(e),clear:()=>s.clear(),delete:e=>s.delete(e),getContentTypeFromPath:e=>{if(!e)return"text";let t=e.toLowerCase().split(".").pop()||"";return/^(xlsx|xls|docx|pptx|ppt|pdf|png|jpg|jpeg|gif|bmp|webp|svg|ico|zip|exe|dll|bin|dat|obj|o|so|dylib|mp3|mp4|avi|mov|wmv|flv|wav|ogg)$/.test(t)?"blob":"json"===t?"json":"text"},isImageFile:e=>{var t;return["png","jpg","jpeg","gif","svg","webp","bmp","ico"].includes((null==(t=e.split(".").pop())?void 0:t.toLowerCase())||"")},isPdfFile:e=>e.toLowerCase().endsWith(".pdf"),isBlob:e=>e instanceof Blob,getContentType:(e,t)=>t||i.getContentTypeFromPath(e),getMimeTypeFromPath:e=>{var t;switch((null==(t=e.split(".").pop())?void 0:t.toLowerCase())||""){case"xlsx":return"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";case"xls":return"application/vnd.ms-excel";case"docx":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";case"doc":return"application/json";case"pptx":return"application/vnd.openxmlformats-officedocument.presentationml.presentation";case"ppt":return"application/vnd.ms-powerpoint";case"pdf":return"application/pdf";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"svg":return"image/svg+xml";case"zip":return"application/zip";default:return"application/octet-stream"}},preload:async(e,t,r)=>{if(!r)try{let e=localStorage.getItem("auth");e&&(r=JSON.parse(e).accessToken)}catch(e){console.error("Failed to get auth token from localStorage:",e)}return r?Promise.all([...new Set(t)].map(async t=>{let n=o(t=t.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>
1String.fromCharCode(parseInt(t,16)))),a=function(e,t){let r=o(t);return"".concat(e,":").concat(r)}(e,n);if(s.has(a)){var c;return null==(c=s.get(a))?void 0:c.content}let d="".concat(e,":").concat(n);if(l.has(d))return l.get(d);let u=(async()=>{try{var o;let l,c=new URL("".concat("https://api.rationalgo.ai/v1","/sandboxes/").concat(e,"/files/content"));c.searchParams.append("path",n);let d=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=await fetch(c.toString(),{headers:{Authorization:"Bearer ".concat(r)}});if(!t.ok){let r=await t.text(),n="Failed to preload file: ".concat(t.status);if(r.includes("Workspace is not running")&&!e)return await new Promise(e=>setTimeout(e,2e3)),d(!0);throw Error(n)}return t},u=await d(),h=null==(o=t.split(".").pop())?void 0:o.toLowerCase(),m="content";if(["png","jpg","jpeg","gif","pdf","mp3","mp4","xlsx","xls","docx","doc","pptx","ppt","zip","exe","bin"].includes(h||"")){let e=await u.blob();if(i.isImageFile(t))l=e,m="content";else if("pdf"===h||["xlsx","xls","docx","doc","pptx","ppt"].includes(h||"")){let r=i.getMimeTypeFromPath(t);l=new Blob([e],{type:r}),m="content"}else l=URL.createObjectURL(e),m="url"}else l="json"===h?await u.json():await u.text();return s.set(a,{content:l,timestamp:Date.now(),type:m}),l}catch(e){return s.set(a,{content:null,timestamp:Date.now(),type:"error"}),null}finally{l.delete(d)}})();return l.set(d,u),u})):(console.warn("Cannot preload files: No authentication token available"),[])},getMimeType:e=>i.getMimeTypeFromPath(e)};function c(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{maxRetries:r=5,initialDelay:a=1e3,timeoutMs:s=5e3}=t,[l,o]=(0,n.useState)("idle"),[i,c]=(0,n.useState)(0),d=(0,n.useRef)(null),u=(0,n.useRef)(null),h=(0,n.useRef)(!1),m=(0,n.useCallback)(e=>{if(h.current||"ready"===l)return;o("loading"),h.current=!0;let t=document.createElement("iframe");t.src=e,t.style.position="absolute",t.style.left="-9999px",t.style.top="-9999px",t.style.width="1024px",t.style.height="768px",t.style.border="0",t.title="VNC Preloader";let n=setTimeout(()=>{if(t.parentNode&&t.parentNode.removeChild(t),i<r){h.current=!1;let t=Math.min(2e3*Math.pow(1.5,i),1e4);console.log("\uD83D\uDD04 VNC preload failed, retrying in ".concat(t,"ms (attempt ").concat(i+1,"/").concat(r,")")),u.current=setTimeout(()=>{c(e=>e+1),m(e)},t)}else console.log("â VNC preload failed after ".concat(r," attempts")),o("error"),h.current=!1},s);t.onload=()=>{clearTimeout(n),console.log("â
VNC preloaded successfully"),o("ready"),c(0),h.current=!1,d.current=t},t.onerror=()=>{clearTimeout(n),t.parentNode&&t.parentNode.removeChild(t),i<r?(h.current=!1,u.current=setTimeout(()=>{c(e=>e+1),m(e)},Math.min(2e3*Math.pow(1.5,i),1e4))):(o("error"),h.current=!1)},document.body.appendChild(t)},[l,i,r,s]),x=(0,n.useCallback)(()=>{if((null==e?void 0:e.vnc_preview)&&(null==e?void 0:e.pass)){let t="".concat(e.vnc_preview,"/vnc_lite.html?password=").concat(e.pass,"&autoconnect=true&scale=local");c(0),o("idle"),m(t)}},[null==e?void 0:e.vnc_preview,null==e?void 0:e.pass,m]);return(0,n.useEffect)(()=>{if(!(null==e?void 0:e.vnc_preview)||!(null==e?void 0:e.pass)){o("idle"),c(0);return}if("loading"===l||"ready"===l)return;let t="".concat(e.vnc_preview,"/vnc_lite.html?password=").concat(e.pass,"&autoconnect=true&scale=local");c(0),h.current=!1;let r=setTimeout(()=>{m(t)},a);return()=>{clearTimeout(r),u.current&&(clearTimeout(u.current),u.current=null),d.current&&d.current.parentNode&&(d.current.parentNode.removeChild(d.current),d.current=null),h.current=!1}},[null==e?void 0:e.vnc_preview,null==e?void 0:e.pass,m,a,l]),{status:l,retryCount:i,retry:x,isPreloaded:"ready"===l,preloadedIframe:d.current}}var d=r(75152),u=r(14333),h=r(87107),m=r(36987);function x(){let{session:e}=(0,a.A)(),t=(0,u.jE)();return(0,h.n)({mutationFn:async t=>{let{sandboxId:r,filePath:n}=t;if(!(null==e?void 0:e.accessToken))throw Error("No access token available");let a=await fetch("".concat("https://api.rationalgo.ai/v1","/sandboxes/").concat(r,"/files?path=").concat(encodeURIComponent(n)),{method:"DELETE",headers:{Authorization:"Bearer ".concat(e.accessToken)}});if(!a.ok)throw Error(await a.text()||"Delete failed");return await a.json()},onSuccess:(e,r)=>{var n;let a=r.filePath.substring(0,r.filePath.lastIndexOf("/"));t.invalidateQueries({queryKey:d.Be.directory(r.sandboxId,a)}),t.invalidateQueries({queryKey:d.Be.directories()}),t.invalidateQueries({predicate:e=>{let t=e.queryKey;return t.length>=4&&"files"===t[0]&&"content"===t[1]&&t[2]===r.sandboxId&&t[3]===r.filePath}}
1),["text","blob","json"].forEach(e=>{let n=d.Be.content(r.sandboxId,r.filePath,e);t.removeQueries({queryKey:n})});let s=(n=r.filePath)?"workspace"===n||n.startsWith("workspace/")?"/"+n:n.startsWith("/workspace")?n:"/workspace/".concat(n.replace(/^\//,"")):"/workspace";["".concat(r.sandboxId,":").concat(s,":blob"),"".concat(r.sandboxId,":").concat(s,":text"),"".concat(r.sandboxId,":").concat(s,":json"),"".concat(r.sandboxId,":").concat(s),"".concat(r.sandboxId,":").concat(s.substring(1),":blob"),"".concat(r.sandboxId,":").concat(s.substring(1),":text"),"".concat(r.sandboxId,":").concat(s.substring(1),":json"),"".concat(r.sandboxId,":").concat(s.substring(1))].forEach(e=>{var t;let r=null==(t=i.cache)?void 0:t.get(e);r&&("url"===r.type&&"string"==typeof r.content&&r.content.startsWith("blob:")&&URL.revokeObjectURL(r.content),i.delete(e))})},onError:e=>{let t=e instanceof Error?e.message:String(e);m.o.error("Delete failed: ".concat(t))}})}function p(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},[a,s]=n.useState(null),{data:l,isLoading:o,error:i,failureCount:c}=(0,d.x2)(e,t,{contentType:"blob",enabled:r.enabled,staleTime:r.staleTime||3e5});return n.useEffect(()=>{if(!(l instanceof Blob))return void s(null);{let e=URL.createObjectURL(l);return s(e),()=>{URL.revokeObjectURL(e),s(null)}}},[l,t]),{data:a,isLoading:o,error:i,failureCount:c}}},99749:(e,t,r)=>{r.d(t,{eT:()=>R,ac:()=>n.ac,my:()=>n.my,D5:()=>P,S8:()=>I,qR:()=>n.qR,jD:()=>n.jD});var n=r(9601),a=r(72216),s=r(32139),l=r(68080),o=r(72860),i=r(64951),c=r(55356),d=r(2391),u=r(7614),h=r(14815),m=r(55674),x=r(33591),p=r(28519),f=r(80643),g=r(16374),b=r(61390),v=r(20025),w=r(62981),j=r(24304),y=r(34470),N=r(15294),_=r(37693),E=r(39303),k=r(84499),C=r(51591),S=r(92888),D=r(95342),A=r(24105);let L={globe:a.default,"file-edit":s.default,"file-search":l.default,"file-plus":o.default,"file-text":i.default,"file-x":c.default,list:d.default,"list-todo":u.default,terminal:h.default,computer:m.default,search:x.default,"external-link":p.default,network:f.default,table:g.default,code:b.default,phone:v.default,"phone-off":w.default,"message-question":j.default,"check-circle":y.default,wrench:N.default,"book-open":_.default,plug:E.default,clock:k.default,presentation:C.default,image:S.default,pencil:D.default,hammer:A.default};function I(e){var t;return null!=(t=L[(0,n.nM)(e)])?t:N.default}let R=!0,P=(e,t)=>{if(!t)return null;try{var r,n,a,s;let l=JSON.parse(t);if(l.query){let e=Array.isArray(l.query)?l.query[0]:l.query;return e.length>30?e.substring(0,27)+"...":e}if(null==(r=l.arguments)?void 0:r.query){let e=Array.isArray(l.arguments.query)?l.arguments.query[0]:l.arguments.query;return e.length>30?e.substring(0,27)+"...":e}if(null==e?void 0:e.toLowerCase().startsWith("browser_")){if(l.url)return l.url;if(null==(a=l.arguments)?void 0:a.url)return l.arguments.url;if(l.goal){let e=l.goal;return e.length>30?e.substring(0,27)+"...":e}return null}if(l.file_path){let e=l.file_path;return"string"==typeof e?e.split("/").pop()||e:null}if(null==(n=l.arguments)?void 0:n.file_path){let e=l.arguments.file_path;return"string"==typeof e?e.split("/").pop()||e:null}if((null==e?void 0:e.toLowerCase())==="execute-command"){if(l.command){let e=l.command;return e.length>30?e.substring(0,27)+"...":e}if(null==(s=l.arguments)?void 0:s.command){let e=l.arguments.command;return e.length>30?e.substring(0,27)+"...":e}}}catch(e){}try{if(null==e?void 0:e.toLowerCase().startsWith("browser_")){let e=t.match(/url["']?\s*[:=]\s*["']?([^"'\s]+)/i);if(e)return e[1];let r=t.match(/goal["']?\s*[:=]\s*["']?([^"'\s]+)/i);if(r){let e=r[1];return e.length>30?e.substring(0,27)+"...":e}return null}let r=t.match(/file_path["']?\s*[:=]\s*["']?([^"'\s]+)/i);if(r){let e=r[1];return e.split("/").pop()||e}if((null==e?void 0:e.toLowerCase())==="execute-command"){let e=t.match(/(?:command|cmd)["']?\s*[:=]\s*["']?([^"'\n]+)/i);if(e){let t=e[1];return t.length>30?t.substring(0,27)+"...":t}}}catch(e){}let l=null;switch(null==e?void 0:e.toLowerCase()){case"create-file":case"full-file-rewrite":case"read-file":case"delete-file":case"str-replace":return(l=t.match(/file_path["']?\s*[:=]\s*["']?([^"'\s]+)/i))?l[1].split("/").pop()||l[1]:null;case"edit-file":return(l=t.match(/target_file["']?\s*[:=]\s*["']?([^"'\s]+)/i))?(l[1].split("/").pop()||l[1]).trim():null;case"execute-command":if(l=t.match(/(?:command|cmd)["']?\s*[:=]\s*["']?([^"'\n]+)/i)){let e=l[1];return e.length>30?e.substring(0,27)+"...":e}break;case"web-search":case"image-search":return(l=t.match(/query["']?\s*[:=]\s*["']?([^"'\s]+)/i))?l[1].length>30?l[1].substring(0,27)+"...":l[1]:null;case"call-data-provider":l=t.match(/service_name["']?\s*[:=]\s*["']?([^"'\s]+)/i);let o=t.match(/route["']?\s*[:=]\s*["']?([^"'\s]+)/i);return l&&o?"".concat(l[1],"/").concat(o[1]):l?l[1]:null}return null}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.