import{a6 as w,j as e,a7 as b,a8 as v,a9 as S,r as x,aa as O,a2 as A,d as k,ab as z,ac as d,ad as L,u as i,ae as E,af as T,ag as _,ah as P,ai as R,aj as D,ak as M,al as I}from"./index-BkPfLH67.js";import{am as oe}from"./index-BkPfLH67.js";import{R as B}from"./RightPanelHeader-D6wMhtyi.js";/**
 * @license lucide-react v1.8.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const U=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],N=w("braces",U),F={url:v,markdown:b,json:N},H={url:"Web Page",markdown:"Document",json:"JSON Data"};function g({title:s,contentType:t}){const n=t?F[t]:S,o=s??(t?H[t]:"Canvas");return e.jsxs("div",{className:"border-b",children:[e.jsx(B,{}),t&&e.jsxs("div",{className:"flex items-center gap-2 border-t px-4 py-1.5",children:[e.jsx(n,{className:"text-muted-foreground size-3.5 shrink-0"}),e.jsx("span",{className:"text-muted-foreground truncate text-xs font-medium",children:o})]})]})}const J=["javascript:","data:","file:","blob:"],W=new Set(["allow-scripts","allow-same-origin","allow-popups","allow-forms","allow-downloads","allow-modals"]),Y="allow-scripts allow-same-origin allow-popups allow-forms";function $(s){return s.split(" ").filter(t=>W.has(t)).join(" ")}function K(s){try{const t=new URL(s);return!J.includes(t.protocol)}catch{return!1}}function X({content:s}){if(!x.useMemo(()=>K(s.url),[s.url]))return e.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-8 text-center",children:e.jsx("p",{children:"This URL cannot be displayed for security reasons."})});const n=s.sandbox?$(s.sandbox):Y;return e.jsx("iframe",{src:s.url,sandbox:n,className:"h-full w-full border-0",title:s.title??"Canvas content"})}function Q({content:s}){return e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none overflow-auto p-6",children:e.jsx(O,{shikiTheme:["github-light","github-dark"],children:s.content})})}function V({content:s}){return e.jsx("div",{className:"overflow-auto p-4 font-mono text-sm",children:e.jsx(C,{value:s.data,depth:0})})}const q=20;function C({value:s,depth:t,keyName:n}){const[o,l]=x.useState(t>2),r=x.useCallback(()=>l(c=>!c),[]);if(t>=q)return e.jsx(u,{keyName:n,value:"[max depth]",className:"text-muted-foreground"});if(s===null)return e.jsx(u,{keyName:n,value:"null",className:"text-muted-foreground"});if(typeof s=="boolean")return e.jsx(u,{keyName:n,value:String(s),className:"text-blue-500"});if(typeof s=="number")return e.jsx(u,{keyName:n,value:String(s),className:"text-green-500"});if(typeof s=="string")return e.jsx(u,{keyName:n,value:`"${s}"`,className:"text-amber-500"});const a=Array.isArray(s),m=a?s.map((c,f)=>[String(f),c]):Object.entries(s),y=a?"[":"{",j=a?"]":"}";return e.jsxs("div",{style:{paddingLeft:t>0?16:0},children:[e.jsxs("button",{type:"button",className:"hover:bg-muted -ml-0.5 inline-flex items-center gap-0.5 rounded px-0.5",onClick:r,children:[e.jsx(A,{className:k("size-3 transition-transform",!o&&"rotate-90")}),n!=null&&e.jsxs("span",{className:"text-foreground",children:[n,": "]}),e.jsxs("span",{className:"text-muted-foreground",children:[y,o&&` ... ${m.length} items `,o&&j]})]}),!o&&e.jsxs(e.Fragment,{children:[m.map(([c,f])=>e.jsx(C,{keyName:a?void 0:c,value:f,depth:t+1},c)),e.jsx("div",{className:"text-muted-foreground",children:j})]})]})}function u({keyName:s,value:t,className:n}){return e.jsxs("div",{style:{paddingLeft:16},children:[s!=null&&e.jsxs("span",{className:"text-foreground",children:[s,": "]}),e.jsx("span",{className:n,children:t})]})}const G=[{icon:b,label:"Markdown",description:"Render a document",action:()=>({type:"markdown",content:`# Untitled

Start writing...`,title:"Document"})},{icon:N,label:"JSON",description:"Inspect structured data",action:()=>({type:"json",data:{message:"Your data here"},title:"JSON Data"})},{icon:v,label:"Web Page",description:"Embed a URL",action:()=>({type:"url",url:"https://dorkos.ai",title:"Web Page"})}];function p(s,t,n,o){return s.split("").reduce((r,a)=>r+a.charCodeAt(0),0)*(t+1)*7%(o-n)+n}function Z({onAction:s}){const t=z(),n=x.useId(),o=x.useMemo(()=>Array.from({length:6},(l,r)=>({x:p(n,r*3,10,90),y:p(n,r*3+1,10,80),size:p(n,r*3+2,24,56),delay:r*.4})),[n]);return e.jsxs("div",{className:"relative flex h-full flex-col items-center justify-center overflow-hidden px-6",children:[!t&&o.map((l,r)=>e.jsx(d.div,{className:"border-border/40 absolute rounded-lg border",style:{left:`${l.x}%`,top:`${l.y}%`,width:l.size,height:l.size},initial:{opacity:0,scale:.6,rotate:-10},animate:{opacity:[0,.15,.08,.15],scale:[.6,1,.9,1],rotate:[-10,0,5,0]},transition:{duration:8,delay:l.delay,repeat:1/0,repeatType:"reverse",ease:"easeInOut"}},r)),e.jsxs(d.div,{className:"relative z-10 flex max-w-sm flex-col items-center gap-6 text-center",initial:t?!1:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,ease:"easeOut"},children:[e.jsx(d.div,{className:"bg-muted/50 text-muted-foreground flex size-14 items-center justify-center rounded-2xl",initial:t?!1:{opacity:0,scale:.8},animate:{opacity:1,scale:1},transition:{duration:.3,delay:.1},children:e.jsx(L,{className:"size-7"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-tight",children:"A blank canvas"}),e.jsxs("p",{className:"text-muted-foreground text-sm leading-relaxed",children:["Your agent can render documents, data, and web pages here.",e.jsx("br",{}),"Or pick a starting point below."]})]}),e.jsx(d.div,{className:"mt-2 flex w-full flex-col gap-2",initial:"hidden",animate:"visible",variants:t?{}:{visible:{transition:{staggerChildren:.08,delayChildren:.25}}},children:G.map(({icon:l,label:r,description:a,action:m})=>e.jsxs(d.button,{variants:t?{}:{hidden:{opacity:0,y:8},visible:{opacity:1,y:0}},transition:{duration:.25},className:"border-border hover:bg-accent/50 flex items-center gap-3 rounded-lg border px-4 py-3 text-left transition-colors",onClick:()=>s(m()),children:[e.jsx(l,{className:"text-muted-foreground size-4 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-sm font-medium",children:r}),e.jsx("span",{className:"text-muted-foreground ml-2 text-xs",children:a})]})]},r))})]})]})}function h({canvasContent:s,onSetContent:t}){return s?e.jsxs(e.Fragment,{children:[e.jsx(g,{title:s.title,contentType:s.type}),e.jsxs("div",{className:"flex-1 overflow-auto",children:[s.type==="url"&&e.jsx(X,{content:s}),s.type==="markdown"&&e.jsx(Q,{content:s}),s.type==="json"&&e.jsx(V,{content:s})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(g,{}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsx(Z,{onAction:t})})]})}function te(){const s=i(n=>n.canvasContent);i(n=>n.setCanvasOpen);const t=i(n=>n.setCanvasContent);return e.jsx(h,{canvasContent:s,onSetContent:t})}function ne(){const s=i(a=>a.canvasOpen),t=i(a=>a.canvasContent),n=i(a=>a.setCanvasOpen),o=i(a=>a.setCanvasContent),l=E();if(!s)return null;const r=()=>n(!1);return l?e.jsx(T,{open:!0,onOpenChange:a=>!a&&r(),children:e.jsxs(_,{side:"right",showCloseButton:!1,className:"bg-sidebar text-sidebar-foreground flex w-full flex-col gap-0 p-0 sm:max-w-full",children:[e.jsxs(P,{className:"sr-only",children:[e.jsx(R,{children:"Canvas"}),e.jsx(D,{children:"Agent-driven content pane."})]}),e.jsx(h,{canvasContent:t,onSetContent:o})]})}):e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"group relative flex w-2 items-center justify-center",children:e.jsx("div",{className:"bg-border group-hover:bg-ring h-full w-px transition-colors"})}),e.jsx(I,{id:"agent-canvas",order:2,defaultSize:50,minSize:20,collapsible:!0,onCollapse:r,children:e.jsx("div",{className:"bg-sidebar text-sidebar-foreground flex h-full flex-col overflow-hidden rounded-lg border",children:e.jsx(h,{canvasContent:t,onSetContent:o})})})]})}export{ne as AgentCanvas,te as CanvasContent,oe as useCanvasPersistence};
