1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[10835],{6989:(e,t,a)=>{a.d(t,{b:()=>P});var s=a(68987),r=a(2315),l=a(63283),n=a(19304),i=a(35163),o=a(81211),d=a(25196),c=a(90755),x=a(64094),m=a(63434),g=a(93210),h=a(80605),u=a(25002),p=a(96117),b=a(19753),f=a(75472),y=a(76843),j=a(32821),v=a(76348);function w({id:e,artifact:t,cardWidth:a,onUpdate:l,onMoveForward:n,onMoveBackward:i,onDelete:o}){let d,x=t.metadata||{},{updateNodePosition:m}=(0,j.y)(),{getNode:h,flowToScreenPosition:w}=(0,v.VH)(),N=h(e),C=N?.position??{x:t.x??0,y:t.y??0},{getHandleProps:k}=function(e){let{width:t,position:a,onResize:s,onPositionChange:l}=e,{screenToFlowPosition:n}=(0,v.VH)(),i=(0,r.useRef)(null),o=(0,r.useCallback)(e=>{let t=i.current;if(!t)return;let r=10*Math.round((n({x:e.clientX,y:e.clientY}).x-t.startX)/10),o=t.startW,d=t.startPosX;"e"===t.handle?o=Math.min(600,Math.max(120,t.startW+r)):(o=Math.min(600,Math.max(120,t.startW-r)),d=t.startPosX+(t.startW-o)),s({width:o}),d!==t.startPosX&&l(d,a.y)},[n,s,l,a.y]),d=(0,r.useCallback)(()=>{i.current=null,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",d)},[o]);return{getHandleProps:(0,r.useCallback)(e=>({onMouseDown:s=>{s.preventDefault(),s.stopPropagation(),i.current={startX:n({x:s.clientX,y:s.clientY}).x,startW:t,startPosX:a.x,handle:e},window.addEventListener("mousemove",o),window.addEventListener("mouseup",d)}}),[t,a.x,n,o,d])}}({nodeId:e,width:a,position:C,onResize:e=>l({metadata:{...x,cardWidth:e.width??a}}),onPositionChange:(t,a)=>m(e,{x:t,y:a})}),A="nodrag absolute w-3 h-3 rounded-full bg-white border border-gray-400 cursor-ew-resize";return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:(0,g.cn)(A,"top-1/2 -left-1.5 -translate-y-1/2 -translate-x-1/2"),...k("w")}),(0,s.jsx)("div",{className:(0,g.cn)(A,"top-1/2 -right-1.5 -translate-y-1/2 translate-x-1/2"),...k("e")}),(0,s.jsxs)("div",{className:"nodrag absolute left-1/2 -translate-x-1/2 top-full mt-1 px-2 py-0.5 rounded bg-blue-500 text-white text-[10px] font-medium whitespace-nowrap",children:[Math.round(a)," px"]}),"undefined"!=typeof document&&(0,u.createPortal)((d=w({x:C.x+a,y:C.y}),(0,s.jsxs)("div",{className:"nodrag fixed w-56 bg-white border border-gray-200 rounded-lg shadow-xl text-xs overflow-hidden",style:{left:d.x+12,top:d.y,zIndex:9999},onMouseDown:e=>e.stopPropagation(),children:[(0,s.jsx)("div",{className:"px-3 py-2 bg-gray-50 border-b border-gray-200 font-bold text-gray-800 uppercase tracking-tight text-[11px]",children:"Media Card"}),(0,s.jsxs)("div",{className:"px-3 py-2 border-b border-gray-100",children:[(0,s.jsx)("p",{className:"text-[10px] font-bold text-gray-500 uppercase mb-1.5",children:"Width"}),(0,s.jsxs)("label",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-[10px] text-gray-400",children:"W"}),(0,s.jsx)(y.p,{type:"number",defaultValue:a,onBlur:e=>{let t;return t={cardWidth:Math.min(600,Math.max(120,Number(e.target.value)||360))},l({metadata:{...x,...t}})},className:"h-7 text-xs flex-1"},`w-${a}`)]}),(0,s.jsxs)("p",{className:"text-[10px] text-gray-500 mt-2 flex items-center gap-1",children:[(0,s.jsx)(p.A,{className:"w-3 h-3"})," Lock aspect â image scales with card"]})]}),(0,s.jsxs)("div",{className:"px-3 py-2 flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex gap-1",children:[(0,s.jsx)("button",{onClick:n,className:"p-1 rounded hover:bg-gray-100",title:"Bring forward",children:(0,s.jsx)(b.A,{className:"w-3.5 h-3.5 text-gray-600"})}),(0,s.jsx)("button",{onClick:i,className:"p-1 rounded hover:bg-gray-100",title:"Send backward",children:(0,s.jsx)(f.A,{className:"w-3.5 h-3.5 text-gray-600"})})]}),(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),o?.(t.id)},className:"p-1 rounded hover:bg-red-50 text-red-500 hover:text-red-600",title:"Remove",children:(0,s.jsx)(c.A,{className:"w-3.5 h-3.5"})})]})]})),document.body)]})}var N=a(64600),C=a(99974),k=a(58033),A=a(1925),I=a(40151),S=a(28363),_=a(49405);function P({id:e,artifact:t,selected:a,onUpdate:u,onDelete:p,onSettingsOpen:b,onMoveForward:f,onMoveBackward:y,widthMode:j="fixed"}){let[v,P]=(0,r.useState)(!1),[T,$]=(0,r.useState)(0),[M,E]=(0,r.useState)(!1),[L,D]=(0,r.useState)(!1),F=(0,r.useMemo)(()=>{let e=t.metadata||{},a=e.image_paths||e.imagePaths||[],s=t.storagePath&&/\.(png|jpg|jpeg|webp|gif|svg)$/i.test(t.storagePath),r=a.length>0?a.map(e=>(0,N.Sj)(e)).filter(e=>!!e):s&&t.storagePath?[(0,N.Sj)(t.storagePath)].filter(e=>!!e):[];return{display:r,hasImages:r.length>0}},[t.metadata,t.storagePath]),O=(0,r.useMemo)(()=>(0,N.SX)({storage_path:t.storagePath,metadata:t.metadata}),[t.storagePath,t.metadata]),R=t.metadata||{},U=R.cardWidth||360,z=F.hasImages&&!!e&&!!u&&a,B=R.modelId||R.model_id,H=B?h.zN.getModelById(B):null,W=H?.icon||null,X=F.display[T]||F.display[0],K=O.find(e=>"video"===e.type),V=K?.url||K?.previewUrl,G=!!V,Y=!F.hasImages&&!G&&(0,C.s)(t.storagePath,t.sourceType),J=(e,t)=>
1{e.stopPropagation(),t()},q="fluid"===j?{width:"100%",maxWidth:U,minWidth:0}:{width:U};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:(0,g.cn)("relative","fluid"===j&&"min-w-0 w-full"),children:[(0,s.jsxs)("div",{style:q,className:(0,g.cn)("relative bg-white rounded-lg border border-gray-200 shadow-md hover:shadow-lg transition-all duration-200 group overflow-hidden",a&&"ring-2 ring-blue-400 ring-offset-1"),children:[F.hasImages?(0,s.jsxs)("div",{className:"relative w-full overflow-hidden bg-gray-100",children:[(0,s.jsx)("img",{src:X,alt:t.title,draggable:!1,onLoad:()=>E(!0),className:(0,g.cn)("block w-full h-auto transition-transform duration-500 group-hover:scale-[1.03]",!M&&"min-h-[200px]")}),(0,s.jsxs)("div",{className:"absolute top-2 left-2 z-10 flex gap-1",children:[(0,s.jsxs)(x.E,{variant:"secondary",className:"bg-white/90 backdrop-blur-sm text-[10px] px-1.5 py-0 h-5 border-gray-200 shadow-sm font-bold",children:[(0,s.jsx)(l.A,{className:"h-3 w-3 mr-1"})," IMAGE"]}),F.display.length>1&&(0,s.jsxs)(x.E,{variant:"outline",className:"bg-white/90 text-[10px] px-1.5 py-0 h-5 border-gray-200 font-medium",children:[T+1,"/",F.display.length]})]}),F.display.length>1&&(0,s.jsx)("div",{className:"absolute bottom-2 right-2 z-10 flex gap-1",children:F.display.map((e,t)=>(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),$(t)},className:(0,g.cn)("w-2 h-2 rounded-full transition-all",T===t?"bg-white shadow-sm scale-125":"bg-white/50 hover:bg-white/80")},t))})]}):G?(0,s.jsxs)("div",{className:"relative w-full overflow-hidden bg-black",style:{height:180},children:[(0,s.jsx)(k.Q,{src:V,containerClassName:"absolute inset-0",objectFit:"contain",playPosition:"center"}),(0,s.jsx)("button",{type:"button",className:"absolute inset-0 z-20 flex items-center justify-center bg-black/10",onClick:e=>{e.stopPropagation(),D(!0)},title:"Play video",children:(0,s.jsx)(I.A,{className:"h-8 w-8 text-white drop-shadow"})})]}):(0,s.jsx)("div",{className:"w-full flex flex-col items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 p-6",style:{height:Y?270:180},children:Y?(0,s.jsx)("div",{className:"h-full w-full overflow-hidden rounded-md border border-gray-200 bg-white",children:(0,s.jsx)(C.a,{storagePath:t.storagePath,sourceType:t.sourceType,className:"h-full w-full"})}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"w-14 h-14 rounded-lg bg-white border-2 border-gray-200 flex items-center justify-center mb-3 shadow-sm group-hover:border-gray-300 transition-colors",children:(0,s.jsx)(n.A,{className:"w-7 h-7 text-gray-400"})}),(0,s.jsx)("p",{className:"text-xs font-medium text-gray-700 line-clamp-2 text-center leading-relaxed px-2",children:t.title})]})}),(0,s.jsxs)("div",{className:"border-t border-gray-200 bg-white px-3 py-2 space-y-1",children:[(0,s.jsx)("p",{className:"text-[12px] font-semibold text-gray-900 truncate",children:t.title}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] text-gray-600 font-medium",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-gray-400"}),(0,s.jsx)("span",{className:"uppercase",children:t.sourceType||"Document"})]}),B&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] text-gray-600 font-medium",children:[W?(0,s.jsx)(W,{className:"w-3 h-3"}):(0,s.jsx)(i.A,{className:"w-3 h-3 text-gray-400"}),(0,s.jsx)("span",{className:"truncate",children:B})]})]}),(0,s.jsxs)("div",{className:"absolute top-2 right-2 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200 z-20",children:[t.knowledgeItemId&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{onClick:e=>J(e,()=>b?.(t)),className:"p-1.5 bg-white border border-gray-200 rounded-[5px] shadow-sm hover:bg-gray-50 transition-all",title:"Settings",children:(0,s.jsx)(o.A,{className:"w-3.5 h-3.5 text-gray-700"})}),(0,s.jsx)("button",{onClick:e=>J(e,()=>window.open(`/knowledge-base?itemId=${t.knowledgeItemId}`,"_blank")),className:"p-1.5 bg-white border border-gray-200 rounded-[5px] shadow-sm hover:bg-gray-50 transition-all",title:"View in Knowledge Base",children:(0,s.jsx)(d.A,{className:"w-3.5 h-3.5 text-gray-700"})})]}),(0,s.jsx)("button",{onClick:e=>J(e,()=>P(!0)),className:"p-1.5 bg-white border border-gray-200 rounded-[5px] shadow-sm hover:bg-red-50 hover:text-red-600 hover:border-red-200 transition-all",title:"Remove from canvas",children:(0,s.jsx)(c.A,{className:"w-3.5 h-3.5"})})]})]}),z&&e&&u&&(0,s.jsx)(w,{id:e,artifact:t,cardWidth:U,onUpdate:u,onMoveForward:f,onMoveBackward:y,onDelete:p})]}),(0,s.jsx)(m.Lt,{open:v,onOpenChange:P,children:(0,s.jsxs)(m.EO,{onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)(m.wd,{children:[(0,s.jsx)(m.r7,{children:"Remove from canvas?"}),(0,s.jsx)(m.$v,{children:"This artifact will be removed from the canvas. It will remain in the knowledge base."})]}),(0,s.jsxs)(m.ck,{children:[(0,s.jsx)(m.Zr,{children:"Cancel"}),(0,s.jsx)(m.Rx,{className:"bg-red-600 hover:bg-red-700 text-white",onClick:()=>p?.(t.id),children:"Remove"})]})]})}),(0,s.jsx)(A.lG,{open:L,onOpenChange:D,children:(0,s.jsxs)(A.Cf,{className:"max-w-4xl border-gray-200 bg-white p-4",children:[(0,s.jsx)(A.c7,{className:"mb-3",children:(0,s.jsx)(A.L3,{className:"truncate text-sm font-semibold text-gray-900",children:t.title})}),(0,s.jsx)("div",{className:"mb-3 flex items-center justify-end",children:V&&(0,s.jsxs)(_.$,{variant:"outline",size:"sm",className:"h-8 gap-1 text-xs",onClick:()=>window.open(V,"_blank"),children:[(0,s.jsx)(S.A,{className:"h-3 w-3"}),"Open"]})}
1),V?(0,s.jsx)("video",{src:V,controls:!0,autoPlay:!0,playsInline:!0,className:"h-[70vh] w-full rounded-md bg-black object-contain"}):(0,s.jsx)("div",{className:"flex h-52 items-center justify-center rounded-md border border-gray-200 bg-gray-50 text-sm text-gray-500",children:"Video unavailable"})]})})]})}},10835:(e,t,a)=>{a.d(t,{ArtifactCanvasBoard:()=>am});var s=a(68987),r=a(2315),l=a(73248),n=a(86020),i=a(76348);a(53255);var o=a(68963),d=a(1203),c=a(49405),x=a(71350);function m({onSave:e,disabled:t=!1}){let[a,n]=(0,r.useState)(!1),[i,m]=(0,r.useState)(!1),{toast:g}=(0,x.dj)(),h=async()=>{if(a||t)return void console.warn("[CanvasSaveButton] L1: INPUT - Save blocked",{isSaving:a,disabled:t});try{n(!0),m(!1),await e(),m(!0),g({title:"Canvas Saved",description:"Your canvas changes have been saved successfully.",variant:"default"}),setTimeout(()=>{m(!1)},2e3)}catch(e){console.error("[CanvasSaveButton] â L4: EXECUTION - Save error:",e),g({title:"Save Failed",description:e instanceof Error?e.message:"Failed to save canvas. Please try again.",variant:"destructive"}),m(!1)}finally{n(!1)}};return(0,s.jsx)(c.$,{onClick:h,disabled:t||a,className:"rounded-[5px] border border-gray-300 bg-white hover:bg-gray-50 text-gray-700 shadow-sm gap-2",size:"sm",children:a?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(l.A,{className:"h-4 w-4 animate-spin"}),"Saving..."]}):i?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(o.A,{className:"h-4 w-4 text-green-600"}),"Saved"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(d.A,{className:"h-4 w-4"}),"Save Canvas"]})})}var g=a(31629),h=a(1994),u=a(64094),p=a(51374),b=a(76843),f=a(38193),y=a(72961),j=a(88958);let v={txt:{format:"txt",label:"TXT",extension:"txt",mimeType:"text/plain; charset=utf-8"},csv:{format:"csv",label:"CSV",extension:"csv",mimeType:"text/csv; charset=utf-8"},pdf:{format:"pdf",label:"PDF",extension:"pdf",mimeType:"application/pdf"},png:{format:"png",label:"PNG",extension:"png",mimeType:"image/png"},jpg:{format:"jpg",label:"JPG",extension:"jpg",mimeType:"image/jpeg"},webp:{format:"webp",label:"WebP",extension:"webp",mimeType:"image/webp"},mp4:{format:"mp4",label:"MP4",extension:"mp4",mimeType:"video/mp4"}},w={text:["txt"],csv:["csv"],pdf:["pdf"],image:["png","jpg","webp"],video:["mp4"],unsupported:[]};function N(e){return w[e].map(e=>v[e])}var C=a(21719),k=a(19304),A=a(63283);function I({item:e,isActive:t,selected:a,selectionLimitReached:r,onActivate:l,onToggle:n}){let i=!!e.previewUrl&&("image"===e.itemType||"video"===e.itemType);return(0,s.jsxs)(C.Zp,{role:"button",tabIndex:0,className:`flex w-full min-w-0 cursor-pointer flex-row items-start gap-3 border p-2 text-left shadow-sm transition-all hover:shadow-md ${t?"border-blue-300 bg-blue-50":"border-gray-200 bg-white hover:bg-gray-50"}`,onClick:()=>l(e.itemId),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),l(e.itemId))},children:[(0,s.jsx)(p.S,{checked:a,disabled:!a&&r,onCheckedChange:()=>n(e.itemId),onClick:e=>e.stopPropagation(),className:"mt-0.5 shrink-0"}),(0,s.jsx)("div",{className:"mt-0.5 h-12 w-12 shrink-0 overflow-hidden rounded-[5px] border border-gray-200 bg-white",children:i?(0,s.jsx)("img",{src:e.previewUrl,alt:e.title,className:"h-full w-full object-cover"}):(0,s.jsx)("div",{className:"flex h-full w-full items-center justify-center bg-gray-50",children:"pdf"===e.itemType?(0,s.jsx)(k.A,{className:"h-4 w-4 text-red-600"}):"text"===e.itemType||"csv"===e.itemType?(0,s.jsx)(k.A,{className:"h-4 w-4 text-blue-600"}):(0,s.jsx)(A.A,{className:"h-4 w-4 text-gray-400"})})}),(0,s.jsxs)("div",{className:"min-w-0 flex-1 overflow-hidden",children:[(0,s.jsx)("p",{className:"truncate text-[13px] font-medium text-gray-900",children:e.title}),(0,s.jsx)("p",{className:"truncate text-[11px] font-semibold uppercase tracking-tight text-gray-500",children:e.itemType})]})]})}function S({open:e,onOpenChange:t,items:a,selectedItemIds:n,activeItemId:i,itemConfigs:o,bundle:d,loading:x,error:m,isGenerating:v,isSavingPreferences:w,progress:C,lastErrors:k,status:A,onToggleItem:S,onSetActiveItem:_,onConfigChange:P,onBundleChange:T,onSavePreferences:$,onExport:M}){let E=(0,r.useMemo)(()=>a.filter(e=>e.exportable),[a]),L=E.find(e=>e.itemId===i)||E[0],D=L?o[L.itemId]:null,F=n.length>A.maxExportItems,O=n.length>=A.maxExportItems;return(0,s.jsx)(j.cj,{open:e,onOpenChange:t,children:(0,s.jsx)(j.h,{side:"right",className:"w-[760px] sm:max-w-[760px] p-0",children:(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[(0,s.jsxs)(j.Fm,{className:"border-b px-6 py-4",children:[(0,s.jsx)(j.qp,{className:"text-xl",children:"Export"}),(0,s.jsx)(j.Qs,{children:"Select canvas layers, choose output formats, and export files or ZIP bundles."})]}),(0,s.jsxs)("div",{className:"grid min-h-0 flex-1 grid-cols-[1.25fr_1fr] overflow-hidden",children:[(0,s.jsxs)("div",{className:"flex min-w-0 flex-col overflow-hidden border-r p-4",children:[(0,s.jsxs)("div",{className:"mb-3 flex shrink-0 items-center justify-between gap-2",children:[(0,s.jsx)("h3",{className:"truncate text-sm font-semibold text-gray-900",children:"Items & Layers"}),(0,s.jsxs)(u.E,{variant:"outline",className:"shrink-0",children:[A.exportableCount," exportable"]})]}),x?(0,s.jsxs)("div",{className:"flex h-[220px] items-center justify-center gap-2 text-sm text-gray-500",children:[(0,s.jsx)(l.A,{className:"h-4 w-4 animate-spin"}),"Loading export items..."]}):m?(0,s.jsx)("div",{className:"rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-700",children:m}):0===E.length?(0,s.jsxs)("div",{className:"flex h-[220px] flex-col items-center justify-center gap-2 rounded-md border border-dashed border-gray-200 text-sm text-gray-500",children:[(0,s.jsx)(g.A,{className:"h-5 w-5"}),"No exportable knowledge items found on this canvas."]}):(0,s.jsx)("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto pr-1 custom-scrollbar",children:E.map(e=>{let t=n.includes(e.itemId);return(0,s.jsx)(I,{item:e,isActive:L?.itemId===e.itemId,selected:t,selectionLimitReached:O,onActivate:_,onToggle:S},e.itemId)})})]}),(0,s.jsxs)("div",{className:"flex min-w-0 flex-col overflow-hidden p-4",children:[(0,s.jsx)("h3",{className:"mb-3 shrink-0 text-sm font-semibold text-gray-900",children:"Export Options"}),L&&D?(0,s.jsxs)("div",{className:"min-w-0 space-y-3 overflow-hidden",children:[(0,s.jsxs)("div",{className:"min-w-0 overflow-hidden rounded-md border border-gray-200 bg-gray-50 p-3",children:[(0,s.jsx)("p",{className:"truncate text-xs font-semibold text-gray-900",title:L.title,children:L.title}),(0,s.jsx)("p",{className:"text-[10px] uppercase text-gray-500",children:L.itemType})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(f.J,{className:"text-xs",children:"Format"}),(0,s.jsxs)(y.l6,{value:D.format,onValueChange:e=>P(L.itemId,{format:e}),children:[(0,s.jsx)(y.bq,{className:"h-8 text-xs",children:(0,s.jsx)(y.yv,{})}),(0,s.jsx)(y.gC,{children:N(L.itemType).map(e=>(0,s.jsx)(y.eb,{value:e.format,children:e.label},e.format))})]})]}),"image"===L.itemType&&(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(f.J,{className:"text-xs",children:"Scale"}),(0,s.jsxs)(y.l6,{value:String(D.scale||1),onValueChange:e=>P(L.itemId,{scale:Number(e)}),children:[(0,s.jsx)(y.bq,{className:"h-8 text-xs",children:(0,s.jsx)(y.yv,{})}),(0,s.jsxs)(y.gC,{children:[(0,s.jsx)(y.eb,{value:"1",children:"1x"}),(0,s.jsx)(y.eb,{value:"2",children:"2x"}),(0,s.jsx)(y.eb,{value:"3",children:"3x"})]})]})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(f.J,{className:"text-xs",children:"Suffix"}),(0,s.jsx)(b.p,{value:D.suffix||"",className:"h-8 text-xs",placeholder:"Optional suffix",onChange:e=>P(L.itemId,{suffix:e.target.value})})]})]}):(0,s.jsx)("div",{className:"rounded-md border border-dashed border-gray-200 p-3 text-xs text-gray-500",children:"Select an exportable item to configure per-item options."}),(0,s.jsx)("div",{className:"mt-4 rounded-md border border-gray-200 p-3",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(p.S,{checked:d,onCheckedChange:e=>T(!!e)}),(0,s.jsx)(f.J,{className:"text-xs",children:"Bundle selected files as ZIP"})]})}),(v||C.total>0)&&(0,s.jsxs)("div",{className:"mt-3 rounded-md border border-blue-200 bg-blue-50 px-3 py-2 text-xs text-blue-700",children:["Export progress: ",C.current,"/",Math.max(C.total,1)]}),F&&(0,s.jsxs)("div",{className:"mt-3 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:["Maximum export batch size is ",A.maxExportItems," items."]}),O&&!F&&(0,s.jsx)("div",{className:"mt-3 rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-700",children:"Selection limit reached. Deselect an item to choose another."}),k.length>0&&(0,s.jsx)("div",{className:"mt-3 space-y-1 rounded-md border border-amber-200 bg-amber-50 p-2 text-[11px] text-amber-700",children:k.slice(0,3).map(e=>(0,s.jsxs)("p",{children:[e.itemId,": ",e.error]},`${e.itemId}-${e.error}`))}),(0,s.jsxs)("div",{className:"mt-auto flex shrink-0 items-center justify-between gap-2 border-t pt-3",children:[(0,s.jsxs)("div",{className:"flex min-w-0 shrink items-center gap-2 text-xs text-gray-500",children:[(0,s.jsx)(h.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,s.jsxs)("span",{className:"truncate",children:[n.length," selected"]})]}),(0,s.jsxs)("div",{className:"flex shrink-0 gap-2",children:[(0,s.jsx)(c.$,{variant:"outline",size:"sm",disabled:w||x,onClick:()=>void $(),children:w?"Saving...":"Save Preferences"}),(0,s.jsx)(c.$,{size:"sm",disabled:!A.canExport||!n.length||F||v||x,onClick:()=>void M(),children:v?"Exporting...":"Export Selected"})]})]})]})]})]})})})}let _=["txt","csv","pdf","png","mp4"];function P(e){if("string"!=typeof e)return null;let t=e.trim();return!t||t.length>200?null:t}async function T(e,t){let a=await fetch(e);if(!a.ok)throw Error(`Download failed for ${t}`);let s=await a.blob(),r=URL.createObjectURL(s),l=document.createElement("a");l.href=r,l.download=t,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(r)}function $({open:e,onOpenChange:t,canvasId:a,canvasSlug:l}){let{toast:n}=(0,x.dj)(),i=function({open:e,canvasId:t,canvasSlug:a}){let s=(0,r.useRef)(0),[l,n]=(0,r.useState)([]),[i,o]=(0,r.useState)({canExport:!1,exportableCount:0,totalItems:0,maxExportItems:50}),[d,c]=(0,r.useState)([]),[x,m]=(0,r.useState)(null),[g,h]=(0,r.useState)({}),[u,p]=(0,r.useState)(!1),[b,f]=(0,r.useState)(!1),[y,j]=(0,r.useState)(null),[v,C]=(0,r.useState)(!1),[k,A]=(0,r.useState)(!1),[I,S]=(0,r.useState)({current:0,total:0}),[$,M]=(0,r.useState)([]),[E,L]=(0,r.useState)(null),D=(0,r.useMemo)(()=>{let e,s,r;return e=new URLSearchParams,s=P(t),r=P(a),s&&e.set("canvasId",s),r&&e.set("canvasSlug",r),e.toString()},[t,a]),F=(0,r.useCallback)((e,t,a)=>{let s,r,l,n=e.filter(e=>e.exportable),i=(s=new Set(n.map(e=>e.itemId)),r=t?.selectedItemIds.filter(e=>s.has(e))||[],l=n.map(e=>e.itemId),(r.length?r:l).slice(0,a)),o={};for(let e of n){let a=N(e.itemType).map(e=>e.format),s=t?.itemConfigs?.[e.itemId],r=s?.format,l=r&&a.includes(r)?r:w[e.itemType][0]||null;l&&(o[e.itemId]={itemId:e.itemId,format:l,scale:s?.scale,suffix:"string"==typeof s?.suffix?s.suffix:void 0})}h(o),c(i),m(i[0]||null),p(t?.bundle||!1)},[]),O=(0,r.useCallback)(async()=>
1{if(!D)return;let e=++s.current;f(!0),j(null);try{let[r,l,i]=await Promise.all([fetch(`/api/canvas/export/status?${D}`),fetch(`/api/canvas/export/items?${D}`),fetch(`/api/artifact-canvas?${t?`id=${t}`:`slug=${a}`}`)]);if(!r.ok||!l.ok||!i.ok)throw Error("Failed to load export state");let d=await r.json(),c=await l.json(),x=await i.json(),m=c.items||[],g=function(e){if(!e||"object"!=typeof e)return null;let t=e.metadata;if(!t||"object"!=typeof t)return null;let a=t.export_config;if(!a||"object"!=typeof a)return null;let s=[],r=new Set;if(Array.isArray(a.selectedItemIds))for(let e of a.selectedItemIds){let t=P(e);!t||r.has(t)||(r.add(t),s.push(t))}let l={};if(a.itemConfigs&&"object"==typeof a.itemConfigs)for(let[e,t]of Object.entries(a.itemConfigs)){let a=P(e);a&&t&&"object"==typeof t&&(l[a]={itemId:a,format:function(e){if("string"!=typeof e)return;let t=e.trim().toLowerCase();return _.includes(t)?t:void 0}(t.format),scale:function(e){if("string"==typeof e&&/^\d+$/.test(e.trim())){let t=Number(e.trim());if(1===t||2===t||3===t)return t}if(1===e||2===e||3===e)return e}(t.scale),suffix:function(e){if("string"!=typeof e)return;let t=e.trim();if(t)return t.replace(/[^a-zA-Z0-9._-]+/g,"_").slice(0,40)}(t.suffix)})}return{selectedItemIds:s,itemConfigs:l,bundle:function(e){if("boolean"==typeof e)return e;if("string"==typeof e){let t=e.trim().toLowerCase();if("true"===t)return!0}return!1}(a.bundle)}}(x.canvas_data);if(e!==s.current)return;n(m),o({canExport:!!d.can_export,exportableCount:Number(d.exportable_count||0),totalItems:Number(d.total_items||0),maxExportItems:Number(d.max_export_items||c.max_export_items||50)}),F(m,g,Number(d.max_export_items||c.max_export_items||50))}catch(t){if(e!==s.current)return;j(t instanceof Error?t.message:"Failed to load export state")}finally{if(e!==s.current)return;f(!1)}},[D,t,a,F]);(0,r.useEffect)(()=>{if(!e){S({current:0,total:0}),M([]);return}O()},[e,O]);let R=(0,r.useCallback)(e=>{c(t=>{var a;return a=i.maxExportItems,t.includes(e)?t.filter(t=>t!==e):t.length>=a?t:[...t,e]})},[i.maxExportItems]),U=(0,r.useCallback)((e,t)=>{h(a=>{let s=a[e];return s?{...a,[e]:{...s,...t,itemId:e}}:a})},[]),z=(0,r.useCallback)(async()=>{if(t||a){A(!0);try{let e=await fetch(`/api/artifact-canvas?${t?`id=${t}`:`slug=${a}`}`);if(!e.ok)throw Error("Failed to load canvas before saving preferences");let s=await e.json(),r=s.canvas_data?.metadata||{},l=await fetch("/api/artifact-canvas",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:s.id,canvas_data:{metadata:{...r,export_config:{selectedItemIds:d,itemConfigs:g,bundle:u,updatedAt:new Date().toISOString()}}}})});if(!l.ok)throw Error("Failed to save export preferences");let n=await l.json();L("number"==typeof n.record_version?n.record_version:null)}finally{A(!1)}}},[t,a,d,g,u]),B=(0,r.useCallback)(async()=>{if(!d.length||!D)return{exported_count:0,file_urls:[],errors:[]};C(!0),S({current:0,total:d.length}),M([]);try{await z();let e=d.map(e=>g[e]).filter(e=>!!e),s=await fetch("/api/canvas/export/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({canvasId:t,canvasSlug:a,items:e,bundle:u})}),r=await s.json();if(!s.ok)throw Error(r.error||"Export failed");if(u&&r.bundle_url&&r.bundle_file_name)S({current:0,total:1}),await T(r.bundle_url,r.bundle_file_name),S({current:1,total:1});else if(u)throw Error(r.errors.find(e=>"bundle"===e.itemId)?.error||"ZIP bundle generation failed");else{S({current:0,total:r.file_urls.length});for(let e=0;e<r.file_urls.length;e+=1){let t=r.file_urls[e];await T(t.url,t.fileName),S({current:e+1,total:r.file_urls.length})}}return M(r.errors||[]),r}finally{C(!1)}},[d,g,u,t,a,D,z]);return{items:l,status:i,selectedItemIds:d,activeItemId:x,itemConfigs:g,bundle:u,loading:b,error:y,isGenerating:v,isSavingPreferences:k,progress:I,lastErrors:$,lastSavedVersion:E,setActiveItemId:m,setBundle:p,toggleItem:R,updateItemConfig:U,savePreferences:z,exportSelected:B,refresh:O}}({open:e,canvasId:a,canvasSlug:l}),o=async()=>{try{await i.savePreferences(),n({title:"Export preferences saved",description:i.lastSavedVersion?`Canvas version updated to ${i.lastSavedVersion}.`:"Your export configuration has been persisted."})}catch(e){n({title:"Failed to save preferences",description:e instanceof Error?e.message:"Unexpected error while saving preferences.",variant:"destructive"})}},d=async()=>{try{let e=await i.exportSelected();n({title:"Export completed",description:e.errors.length?`Exported ${e.exported_count} item(s) with ${e.errors.length} warning(s).`:`Exported ${e.exported_count} item(s) successfully.`})}catch(e){n({title:"Export failed",description:e instanceof Error?e.message:"Unexpected error while exporting files.",variant:"destructive"})}};return(0,s.jsx)(S,{open:e,onOpenChange:t,items:i.items,selectedItemIds:i.selectedItemIds,activeItemId:i.activeItemId,itemConfigs:i.itemConfigs,bundle:i.bundle,loading:i.loading,error:i.error,isGenerating:i.isGenerating,isSavingPreferences:i.isSavingPreferences,progress:i.progress,lastErrors:i.lastErrors,status:i.status,onToggleItem:i.toggleItem,onSetActiveItem:i.setActiveItemId,onConfigChange:i.updateItemConfig,onBundleChange:i.setBundle,onSavePreferences:o,onExport:d})}var M=a(35163),E=a(971),L=a(11299),D=a(60559),F=a(53e3),O=a(98081),R=a(47366);function U({isArtifactPaletteOpen:e,onToggleArtifactPalette:t,isBoardPaletteOpen:a,onToggleBoardPalette:r,isAgentPaletteOpen:l,onToggleAgentPalette:n,isUtilityPaletteOpen:i,onToggleUtilityPalette:o,isLayersPanelOpen:d,onToggleLayersPanel:x,onFitView:m}){return(0,s.jsx)("div",{className:"flex flex-col gap-2 p-1.5 bg-white/90 backdrop-blur-md border border-gray-200 rounded-[8px] shadow-lg pointer-events-auto",children:(0,s.jsxs)(R.Bc,{delayDuration:200,children:[n&&(0,s.jsxs)(R.m_,{children:[(0,s.jsx)(R.k$,{asChild:!0,children:(0,s.jsx)(c.$,{variant:l?"secondary":"ghost",size:"icon",className:`h-9 w-9 rounded-[6px] transition-all ${l?"bg-white border border-gray-200 shadow-sm text-black":"hover:bg-gray-100"}`,onClick:n,children:(0,s.jsx)(M.A,{className:`h-4 w-4 ${l?"text-black":"text-gray-600"}`})})}),(0,s.jsx)(R.ZI,{side:"right",className:"text-[11px] font-bold",children:"Agents"})]}),(0,s.jsxs)(R.m_,{children:[(0,s.jsx)(R.k$,{asChild:!0,children:(0,s.jsx)(c.$,{variant:e?"secondary":"ghost",size:"icon",className:`h-9 w-9 rounded-[6px] transition-all ${e?"bg-blue-50 text-blue-600 border border-blue-100":"hover:bg-gray-100"}`,onClick:t,children:(0,s.jsx)(E.A,{className:`h-4 w-4 ${e?"scale-110":""}`})})}),(0,s.jsx)(R.ZI,{side:"right",className:"text-[11px] font-bold",children:e?"Close Artifacts":"Artifacts"})]}),(0,s.jsxs)(R.m_,{children:[(0,s.jsx)(R.k$,{asChild:!0,children:(0,s.jsx)(c.$,{variant:a?"secondary":"ghost",size:"icon",className:`h-9 w-9 rounded-[6px] transition-all ${a?"bg-purple-50 text-purple-600 border border-purple-100":"hover:bg-gray-100"}`,onClick:r,children:(0,s.jsx)(L.A,{className:`h-4 w-4 ${a?"scale-110":""}`})})}),(0,s.jsx)(R.ZI,{side:"right",className:"text-[11px] font-bold",children:a?"Close Boards":"Boards"})]}),o&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"h-px bg-gray-100 mx-1"}),(0,s.jsxs)(R.m_,{children:[(0,s.jsx)(R.k$,{asChild:!0,children:(0,s.jsx)(c.$,{variant:i?"secondary":"ghost",size:"icon",className:`h-9 w-9 rounded-[6px] transition-all ${i?"bg-orange-50 text-orange-600 border border-orange-100":"hover:bg-gray-100"}`,onClick:o,children:(0,s.jsx)(D.A,{className:`h-4 w-4 ${i?"scale-110":""}`})})}),(0,s.jsx)(R.ZI,{side:"right",className:"text-[11px] font-bold",children:i?"Close Utilities":"Utilities"})]})]}),(0,s.jsx)("div",{className:"h-px bg-gray-100 mx-1"}),x&&(0,s.jsxs)(R.m_,{children:[(0,s.jsx)(R.k$,{asChild:!0,children:(0,s.jsx)(c.$,{variant:d?"secondary":"ghost",size:"icon",className:`h-9 w-9 rounded-[6px] transition-all ${d?"bg-gray-100 border border-gray-200 shadow-sm":"hover:bg-gray-100"}`,onClick:x,children:(0,s.jsx)(F.A,{className:`h-4 w-4 ${d?"text-black":"text-gray-600"}`})})}),(0,s.jsx)(R.ZI,{side:"right",className:"text-[11px] font-bold",children:d?"Close Layers":"Layers"})]}),(0,s.jsxs)(R.m_,{children:[(0,s.jsx)(R.k$,{asChild:!0,children:(0,s.jsx)(c.$,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-[6px] hover:bg-gray-100",onClick:m,children:(0,s.jsx)(O.A,{className:"h-4 w-4 text-gray-600"})})}),(0,s.jsx)(R.ZI,{side:"right",className:"text-[11px] font-bold",children:"Fit View"})]})]})})}var z=a(77058),B=a(70862),H=a(32589),W=a(13424);let X=["document","markdown","research","aeo_output"];var K=a(45991),V=a(40151),G=a(28363),Y=a(39144),J=a(58033),q=a(64600),Z=a(99974),Q=a(1925);function ee({item:e,onSelect:t}){let a=(0,r.useMemo)(()=>(0,q.SX)(e),[e])[0],l=a?.type,[n,i]=(0,r.useState)(!1),[o,d]=(0,r.useState)(!1),x=(0,r.useRef)(null),m=e.storage_path,g=(0,Z.s)(m,e.source_type),h="pdf"===l||"markdown"===e.source_type?k.A:K.A,p="pdf"===l?"bg-red-50 text-red-600":"bg-blue-50 text-blue-600",b=(l||e.source_type||"document").toString(),f=a?.url||a?.previewUrl,y=()=>{x.current&&(window.clearTimeout(x.current),x.current=null),d(!1)};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(C.Zp,{className:"cursor-pointer border border-gray-200 bg-white p-2 shadow-sm transition-all hover:bg-gray-50 hover:shadow-md",onClick:()=>t(e),children:(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsxs)(Y.jc,{open:o,onOpenChange:d,openDelay:0,closeDelay:120,children:[(0,s.jsx)(Y.d0,{asChild:!0,children:(0,s.jsx)("div",{className:"mt-0.5 h-12 w-12 flex-shrink-0 overflow-hidden rounded-[5px] border border-gray-200 bg-white",onMouseEnter:()=>{x.current&&window.clearTimeout(x.current),x.current=window.setTimeout(()=>{d(!0)},3e3)},onMouseLeave:y,children:"image"===l&&a?.previewUrl?(0,s.jsx)("img",{src:a.previewUrl,alt:a.label,className:"h-full w-full object-cover"}):"video"===l&&a?.previewUrl?(0,s.jsxs)("div",{className:"relative h-full w-full",children:[(0,s.jsx)(J.Q,{src:a.previewUrl,containerClassName:"absolute inset-0"}),(0,s.jsx)("button",{type:"button",className:"absolute inset-0 z-10 flex items-center justify-center bg-black/15",onClick:e=>{e.stopPropagation(),x.current&&(window.clearTimeout(x.current),x.current=null),i(!0)},onMouseDown:e=>e.stopPropagation(),title:"Play video",children:(0,s.jsx)(V.A,{className:"h-4 w-4 text-white"})})]}):(0,s.jsx)("div",{className:`flex h-full w-full items-center justify-center ${p}`,children:(0,s.jsx)(h,{className:"h-4 w-4"})})})}),(0,s.jsxs)(Y.Et,{side:"right",align:"start",sideOffset:10,className:"w-[360px] rounded-lg border border-gray-200 bg-white p-3 shadow-xl",onMouseEnter:()=>{x.current&&(window.clearTimeout(x.current),x.current=null),d(!0)},onMouseLeave:y,children:[(0,s.jsxs)("div",{className:"mb-2 flex items-center justify-between",children:[(0,s.jsx)("p",{className:"truncate text-xs font-semibold text-gray-900",children:e.file_name||e.title||"Preview"}),(0,s.jsx)(u.E,{variant:"outline",className:"h-5 text-[10px] uppercase",children:b})]}),"image"===l&&a?.previewUrl?(0,s.jsx)("div",{className:"h-[280px] w-full overflow-hidden rounded-md border border-gray-200 bg-gray-50",children:(0,s.jsx)("img",{src:a.previewUrl,alt:a.label,className:"h-full w-full object-contain"})}):"video"===l&&a?.previewUrl?(0,s.jsx)("div",{className:"h-[280px] w-full overflow-hidden rounded-md border border-gray-200 bg-black",children:(0,s.jsx)("video",{src:a.previewUrl,controls:!0,preload:"metadata",className:"h-full w-full object-contain"})}):"pdf"===l||g?(0,s.jsx)("div",{className:"h-[320px] w-full overflow-hidden rounded-md border border-gray-200 bg-white",children:(0,s.jsx)(Z.a,{storagePath:m,sourceType:e.source_type,className:"h-full w-full"})}):(0,s.jsx)("div",{className:"flex h-[220px] w-full items-center justify-center rounded-md border border-gray-200 bg-gray-50",children:(0,s.jsx)(k.A,{className:"h-8 w-8 text-gray-400"})})]})]}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"mb-0.5 flex items-center justify-between gap-2",children:[(0,s.jsx)("h4",{className:"truncate text-[13px] font-medium text-gray-900",children:e.file_name||e.title||"Untitled"}),l&&(0,s.jsx)(u.E,{variant:"outline",className:"h-4 border-gray-200 bg-gray-100 px-1 py-0 text-[9px] font-bold uppercase text-gray-700",children:l})]}),(0,s.jsx)("p",{className:"truncate text-[11px] font-semibold uppercase tracking-tight text-gray-500",children:b})]})]})}),(0,s.jsx)(Q.lG,{open:n,onOpenChange:i,children:(0,s.jsxs)(Q.Cf,{className:"max-w-3xl border-gray-200 bg-white p-4",children:[(0,s.jsxs)("div",{className:"mb-3 flex items-center justify-between",children:[(0,s.jsx)("p",{className:"truncate text-sm font-semibold text-gray-900",children:e.file_name||e.title||"Video"}),f&&(0,s.jsxs)(c.$,{variant:"outline",size:"sm",className:"h-8 gap-1 text-xs",onClick:()=>window.open(f,"_blank"),children:[(0,s.jsx)(G.A,{className:"h-3 w-3"}),"Open"]})]}
1),f?(0,s.jsx)("video",{src:f,controls:!0,autoPlay:!0,playsInline:!0,className:"h-[65vh] w-full rounded-md bg-black object-contain"}):(0,s.jsx)("div",{className:"flex h-52 items-center justify-center rounded-md border border-gray-200 bg-gray-50 text-sm text-gray-500",children:"Video unavailable"})]})})]})}var et=a(42148);let ea=[{value:"all",label:"All"},{value:"image",label:"Image",icon:A.A},{value:"video",label:"Video"},{value:"pdf",label:"PDF"},{value:"document",label:"Doc"}],es=[{value:"all",label:"All Time"},{value:"today",label:"Today"},{value:"7d",label:"7 Days"},{value:"30d",label:"30 Days"}],er=["all","16:9","1:1","4:5","9:16"];function el({mediaFilter:e,dateFilter:t,dateSort:a,ratioFilter:r,showRatioFilter:l,onMediaFilterChange:n,onDateFilterChange:i,onDateSortChange:o,onRatioFilterChange:d}){let c=ea.find(t=>t.value===e)?.label||"All",x=es.find(e=>e.value===t)?.label||"All Time";return(0,s.jsxs)("div",{className:"mt-3 space-y-3",children:[(0,s.jsxs)(y.l6,{value:e,onValueChange:e=>n(e),children:[(0,s.jsx)(y.bq,{className:"h-9 rounded-md border-gray-200 text-xs",children:(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)(A.A,{className:"h-3.5 w-3.5 text-gray-500"}),(0,s.jsx)("span",{className:"text-[11px] font-semibold uppercase tracking-tight text-gray-600",children:"Format"}),(0,s.jsx)(y.yv,{placeholder:c})]})}),(0,s.jsx)(y.gC,{className:"rounded-md border-gray-200",children:ea.map(e=>(0,s.jsx)(y.eb,{value:e.value,className:"text-xs",children:e.label},e.value))})]}),(0,s.jsxs)(y.l6,{value:t,onValueChange:e=>i(e),children:[(0,s.jsx)(y.bq,{className:"h-9 rounded-md border-gray-200 text-xs",children:(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)(et.A,{className:"h-3.5 w-3.5 text-gray-500"}),(0,s.jsx)("span",{className:"text-[11px] font-semibold uppercase tracking-tight text-gray-600",children:"Created"}),(0,s.jsx)(y.yv,{placeholder:x})]})}),(0,s.jsx)(y.gC,{className:"rounded-md border-gray-200",children:es.map(e=>(0,s.jsx)(y.eb,{value:e.value,className:"text-xs",children:e.label},e.value))})]}),(0,s.jsxs)(y.l6,{value:a,onValueChange:e=>o(e),children:[(0,s.jsx)(y.bq,{className:"h-9 rounded-md border-gray-200 text-xs",children:(0,s.jsx)(y.yv,{})}),(0,s.jsxs)(y.gC,{className:"rounded-md border-gray-200",children:[(0,s.jsx)(y.eb,{value:"newest",className:"text-xs",children:"Newest First"}),(0,s.jsx)(y.eb,{value:"oldest",className:"text-xs",children:"Oldest First"})]})]}),l&&(0,s.jsxs)(y.l6,{value:r,onValueChange:e=>d(e),children:[(0,s.jsx)(y.bq,{className:"h-9 rounded-md border-gray-200 text-xs",children:(0,s.jsx)(y.yv,{placeholder:"Ratio"})}),(0,s.jsx)(y.gC,{className:"rounded-md border-gray-200",children:er.map(e=>(0,s.jsx)(y.eb,{value:e,className:"text-xs",children:"all"===e?"All Ratios":e},e))})]})]})}function en({onSelect:e,onClose:t}){let{items:a,loading:n,searchQuery:i,setSearchQuery:o}=function(){let[e,t]=(0,r.useState)(null),[a,s]=(0,r.useState)("");(0,r.useEffect)(()=>{let e=!0;return H.supabase.auth.getUser().then(({data:a})=>{e&&a.user&&t(a.user.id)}),()=>{e=!1}},[]);let{items:l,loading:n}=(0,W.G)(e||void 0,{},!!e),i=(0,r.useMemo)(()=>l.filter(e=>X.includes(e.source_type)&&e.is_active&&"lead_capture"!==e.source_type),[l]);return{items:(0,r.useMemo)(()=>{if(!a)return i;let e=a.toLowerCase();return i.filter(t=>t.file_name?.toLowerCase().includes(e)||t.title?.toLowerCase().includes(e))},[i,a]),loading:n,searchQuery:a,setSearchQuery:s}}(),[d,x]=(0,r.useState)("all"),[m,g]=(0,r.useState)("all"),[h,u]=(0,r.useState)("all"),[p,f]=(0,r.useState)("newest"),y=(0,r.useMemo)(()=>{let e="all"===d?a:a.filter(e=>{let t,a;return t=(0,q.SX)(e),("image"===(a=t[0]?.type)||"video"===a||"pdf"===a?a:"document")===d});return[...(("image"===d||"video"===d)&&"all"!==m?e.filter(e=>(e=>{let t=e?.metadata;if(!t)return null;let a=t.width||t.image_width||t.imageWidth||t?.image?.width||t?.dimensions?.width,s=t.height||t.image_height||t.imageHeight||t?.image?.height||t?.dimensions?.height;if(!a||!s)return null;let r=a/s,l=[{label:"16:9",value:16/9},{label:"1:1",value:1},{label:"4:5",value:.8},{label:"9:16",value:9/16}];return l.reduce((e,t)=>
1Math.abs(t.value-r)<Math.abs(e.value-r)?t:e,l[0]).label})(e)===m):e).filter(e=>((e,t="all")=>{if("all"===t)return!0;if(!e)return!1;let a=new Date,s=new Date(e);if(Number.isNaN(s.getTime()))return!1;let r=a.getTime()-s.getTime();return"today"===t?a.toDateString()===s.toDateString():"7d"===t?r<=6048e5:"30d"!==t||r<=2592e6})(e.created_at,h))].sort((e,t)=>{let a=new Date(e.created_at||0).getTime(),s=new Date(t.created_at||0).getTime();return"oldest"===p?a-s:s-a})},[a,d,m,h,p]),j="image"===d||"video"===d;return(0,s.jsxs)("div",{className:"w-80 h-full flex flex-col bg-white border-l border-gray-200 shadow-xl animate-in slide-in-from-right duration-200",children:[(0,s.jsxs)("div",{className:"p-4 border-b border-gray-200 flex items-center justify-between bg-gray-50/50",children:[(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("h2",{className:"text-sm font-bold text-gray-900 uppercase tracking-tight",children:"Artifact Palette"}),(0,s.jsx)("p",{className:"text-[11px] text-gray-500 font-medium",children:"Add knowledge to your canvas"})]}),(0,s.jsx)(c.$,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:t,children:(0,s.jsx)(z.A,{className:"h-4 w-4 text-gray-400"})})]}),(0,s.jsxs)("div",{className:"p-3 border-b border-gray-100",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(B.A,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-gray-400"}),(0,s.jsx)(b.p,{placeholder:"Search artifacts...",className:"pl-9 h-9 text-xs border-gray-200 focus-visible:ring-blue-500",value:i,onChange:e=>o(e.target.value)})]}),(0,s.jsx)(el,{mediaFilter:d,dateFilter:h,dateSort:p,ratioFilter:m,showRatioFilter:j,onMediaFilterChange:x,onDateFilterChange:u,onDateSortChange:f,onRatioFilterChange:g})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-3 space-y-2 custom-scrollbar",children:n?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 gap-2",children:[(0,s.jsx)(l.A,{className:"h-5 w-5 animate-spin text-blue-500"}),(0,s.jsx)("p",{className:"text-[11px] text-gray-500 font-medium",children:"Loading artifacts..."})]}):0===y.length?(0,s.jsxs)("div",{className:"text-center py-12",children:[(0,s.jsx)(E.A,{className:"h-10 w-10 text-gray-200 mx-auto mb-3"}),(0,s.jsx)("p",{className:"text-xs text-gray-500 font-medium px-4",children:i?"No artifacts match your search.":"No knowledge items found."})]}):y.map(t=>(0,s.jsx)(ee,{item:t,onSelect:e},t.id))}),(0,s.jsx)("div",{className:"p-4 bg-gray-50 border-t border-gray-200 text-center",children:(0,s.jsx)("p",{className:"text-[10px] text-gray-400 font-medium leading-relaxed",children:"Select an item to add it to the active stage board or current drag position."})})]})}var ei=a(36866),eo=a(7586),ed=a(80605);function ec({onSelect:e,onClose:t,userId:a}){let{items:n,loading:i,searchQuery:o,setSearchQuery:d}=function(e){let[t,a]=(0,r.useState)(""),{data:s,isLoading:l,error:n}=(0,eo.I)({queryKey:["canvas-user-agents",e],queryFn:async()=>{let t=await fetch(`/api/agents/list?user_id=${e}`,{credentials:"include"});if(!t.ok){let e=await t.json().catch(()=>({error:"Failed to fetch"}));throw console.error("[useAgentPalette] â L4: EXECUTION - Fetch failed",{status:t.status,error:e}),Error(e.error||"Failed to fetch agents")}return await t.json()},enabled:!!e,staleTime:3e5,gcTime:18e5,refetchOnWindowFocus:!1});return{items:(0,r.useMemo)(()=>{let e=(s?.agents||[]).map(e=>({id:e.slug,slug:e.slug,title:e.agent_name||e.slug,description:e.instructions?.substring(0,100)||null,content_metadata:{modelId:e.modelId,status:"active",linkedKnowledgeCount:e.knowledge?.length||0,linkedToolCount:e.workflow_nodes?.length||0}}));if(!t)return e;let a=t.toLowerCase();return e.filter(e=>e.title?.toLowerCase().includes(a)||e.slug?.toLowerCase().includes(a)||e.description?.toLowerCase().includes(a))},[s?.agents,t]),loading:l,error:n?.message,searchQuery:t,setSearchQuery:a}}(a),[x,m]=(0,r.useState)(null);return(0,s.jsxs)("div",{className:"w-80 h-full flex flex-col bg-white border-l border-gray-200 shadow-xl animate-in slide-in-from-right duration-200",children:[(0,s.jsxs)("div",{className:"p-4 border-b border-gray-200 flex items-center justify-between bg-gray-50/50",children:[(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("h2",{className:"text-sm font-bold text-black uppercase tracking-tight",children:"Agent Registry"}),(0,s.jsx)("p",{className:"text-[11px] text-gray-500 font-medium",children:"Add agents to your board"})]}),(0,s.jsx)(c.$,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:t,children:(0,s.jsx)(z.A,{className:"h-4 w-4 text-gray-400"})})]}),(0,s.jsx)("div",{className:"p-3 border-b border-gray-100",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(B.A,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-gray-400"}),(0,s.jsx)(b.p,{placeholder:"Search agents...",className:"pl-9 h-9 text-xs border-gray-200 focus-visible:ring-gray-500",value:o,onChange:e=>d(e.target.value)})]})}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-3 space-y-2 custom-scrollbar",children:i?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 gap-2",children:[(0,s.jsx)(l.A,{className:"h-5 w-5 animate-spin text-gray-500"}),(0,s.jsx)("p",{className:"text-[11px] text-gray-500 font-medium",children:"Loading agents..."})]}):0===n.length?(0,s.jsxs)("div",{className:"text-center py-12",children:[(0,s.jsx)(M.A,{className:"h-10 w-10 text-gray-200 mx-auto mb-3"}),(0,s.jsx)("p",{className:"text-xs text-gray-500 font-medium px-4",children:o?"No agents match your search.":"No agents found. Create one in Agent Builder."})]}):n.map(a=>{let r=(e=>{if(!e)return null;let t=ed.zN.getModelById(e);return t?.icon||null})(a.content_metadata?.modelId),l=x===a.id;return(0,s.jsxs)(C.Zp,{className:"p-3 border border-gray-200 bg-white hover:bg-gray-50 cursor-pointer transition-all group relative",onMouseEnter:()=>m(a.id),onMouseLeave:()=>m(null),onClick:()=>{e(a),t()},children:[l&&(0,s.jsx)("div",{className:"absolute top-2 right-2 z-10",children:(0,s.jsx)("div",{className:"w-6 h-6 rounded-full bg-gray-900 text-white flex items-center justify-center shadow-md",children:(0,s.jsx)(ei.A,{className:"w-3.5 h-3.5"})})}),(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)("div",{className:"w-9 h-9 rounded-lg bg-gray-100 flex items-center justify-center flex-shrink-0",children:r?(0,s.jsx)(r,{className:"w-5 h-5"}):(0,s.jsx)(M.A,{className:"w-5 h-5 text-gray-500"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("h4",{className:"text-xs font-semibold text-black truncate",children:a.title}),(0,s.jsx)("p",{className:"text-[10px] text-gray-500 font-mono truncate mt-0.5",children:a.slug}),a.description&&(0,s.jsx)("p",{className:"text-[10px] text-gray-600 line-clamp-2 mt-1",children:a.description}),(0,s.jsxs)("div",{className:"flex flex-col gap-1 mt-2 pt-2 border-t border-gray-100",children:[a.content_metadata?.status&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:`w-1.5 h-1.5 rounded-full ${"active"===a.content_metadata.status?"bg-green-500":"bg-gray-400"}`}),(0,s.jsx)("span",{className:"text-[10px] text-gray-600 font-medium",children:a.content_metadata.status})]}),a.content_metadata?.modelId&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[r?(0,s.jsx)(r,{className:"w-3 h-3"}):(0,s.jsx)(M.A,{className:"w-3 h-3 text-gray-400"}),(0,s.jsx)("span",{className:"text-[10px] text-gray-600 font-medium truncate",children:a.content_metadata.modelId})]}),(a.content_metadata?.linkedKnowledgeCount??0)>0&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)(E.A,{className:"w-3 h-3 text-gray-400"}),(0,s.jsxs)("span",{className:"text-[10px] text-gray-600 font-medium",children:[a.content_metadata.linkedKnowledgeCount," KB"]})]}),(a.content_metadata?.linkedToolCount??0)>0&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)(D.A,{className:"w-3 h-3 text-gray-400"}),(0,s.jsxs)("span",{className:"text-[10px] text-gray-600 font-medium",children:[a.content_metadata.linkedToolCount," tools"]})]})]})]})]})]},a.id)})}),(0,s.jsx)("div",{className:"p-4 bg-gray-50 border-t border-gray-200 text-center",children:(0,s.jsx)("p",{className:"text-[10px] text-gray-400 font-medium leading-relaxed",children:"Click an agent to add it to your board."})})]})}var ex=a(70099),em=a(11891),eg=a(21178),eh=a(78324),eu=a(89707),ep=a(32821);function eb({onClose:e}){let{boards:t,addBoard:a,removeBoard:r}=(0,ep.y)(),l=[{type:"stage",title:"Awareness Stage",stage:"awareness",icon:ex.A,color:"text-blue-600",bg:"bg-blue-50"},{type:"stage",title:"Interest Stage",stage:"interest",icon:ex.A,color:"text-purple-600",bg:"bg-purple-50"},{type:"stage",title:"Desire Stage",stage:"desire",icon:ex.A,color:"text-orange-600",bg:"bg-orange-50"},{type:"stage",title:"Action Stage",stage:"action",icon:ex.A,color:"text-red-600",bg:"bg-red-50"},{type:"stage",title:"Loyalty Stage",stage:"loyalty",icon:ex.A,color:"text-pink-600",bg:"bg-pink-50"},{type:"freeform",title:"Freeform Board",icon:em.A,color:"text-gray-600",bg:"bg-gray-50"},{type:"kanban",title:"Kanban View",icon:O.A,color:"text-emerald-600",bg:"bg-emerald-50"},{type:"agent_knowledge_table",title:"Agent Board",icon:eg.A,color:"text-gray-600",bg:"bg-gray-50"},{type:"social_calendar",title:"Social Calendar",icon:eh.A,color:"text-cyan-600",bg:"bg-cyan-50"},{type:"analytics_reporting",title:"Analytics Reporting",icon:eu.A,color:"text-indigo-600",bg:"bg-indigo-50"}];return(0,s.jsxs)("div",{className:"w-80 h-full flex flex-col bg-white border-l border-gray-200 shadow-xl animate-in slide-in-from-right duration-200",children:[(0,s.jsxs)("div",{className:"p-4 border-b border-gray-200 flex items-center justify-between bg-gray-50/50",children:[(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("h2",{className:"text-sm font-bold text-gray-900 uppercase tracking-tight",children:"Board Registry"}),(0,s.jsx)("p",{className:"text-[11px] text-gray-500 font-medium",children:"Manage canvas containers"})]}),(0,s.jsx)(c.$,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:e,children:(0,s.jsx)(z.A,{className:"h-4 w-4 text-gray-400"})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-3 space-y-6 custom-scrollbar",children:[(0,s.jsxs)("section",{children:[(0,s.jsx)("h3",{className:"text-[10px] font-bold text-gray-400 uppercase tracking-widest px-1 mb-2",children:"Available Containers"}),(0,s.jsx)("div",{className:"grid grid-cols-1 gap-2",children:l.map((e,t)=>(0,s.jsx)(C.Zp,{className:"p-2.5 border border-gray-200 bg-white hover:bg-gray-50 cursor-pointer transition-all group",onClick:()=>a(e.type,e.title,e.stage),children:(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:`p-2 rounded-[5px] ${e.bg} ${e.color}`,children:(0,s.jsx)(e.icon,{className:"w-4 h-4"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("h4",{className:"text-xs font-semibold text-gray-900 truncate",children:e.title}),(0,s.jsxs)("p",{className:"text-[10px] text-gray-500 uppercase tracking-tighter font-bold opacity-70",children:[e.type," Container"]})]}),(0,s.jsx)(ei.A,{className:"w-3.5 h-3.5 text-gray-300 group-hover:text-blue-500 transition-colors"})]})},t))})]}),t.length>0&&(0,s.jsxs)("section",{children:[(0,s.jsx)("h3",{className:"text-[10px] font-bold text-gray-400 uppercase tracking-widest px-1 mb-2",children:"Active on Canvas"}),(0,s.jsx)("div",{className:"space-y-1.5",children:t.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-2 rounded-[5px] bg-gray-50 border border-gray-100 group",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,s.jsx)("div",{className:"w-1.5 h-1.5 rounded-full bg-blue-500"}),(0,s.jsx)("span",{className:"text-[11px] font-medium text-gray-700 truncate",children:e.title})]}),(0,s.jsx)(c.$,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>r(e.id),children:(0,s.jsx)(z.A,{className:"h-3 w-3 text-red-400"})})]},e.id))})]})]}),(0,s.jsx)("div",{className:"p-4 bg-gray-50 border-t border-gray-200",children:(0,s.jsx)("p",{className:"text-[10px] text-gray-400 font-medium text-center italic",children:"Boards persist their position and state automatically."})})]})}var ef=a(42196),ey=a(83793);function ej({onAddStickyNote:e,onAddRectangle:t,onClose:a}){return(0,s.jsxs)("div",{className:"w-72 h-full flex flex-col bg-white border-l border-gray-200 shadow-xl animate-in slide-in-from-right duration-200",children:[(0,s.jsxs)("div",{className:"p-4 border-b border-gray-200 flex items-center justify-between bg-gray-50/50",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(D.A,{className:"w-4 h-4 text-orange-500"}),(0,s.jsx)("h2",{className:"text-sm font-bold text-gray-900 uppercase tracking-tight",children:"Utilities"})]}),(0,s.jsx)(c.$,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:a,children:(0,s.jsx)(z.A,{className:"h-4 w-4 text-gray-400"})})]}),(0,s.jsxs)("div",{className:"p-4 space-y-3",children:[(0,s.jsxs)("button",{onClick:e,className:"w-full flex items-center gap-3 p-3 rounded-lg border border-gray-200 bg-white hover:bg-amber-50 hover:border-amber-200 transition-all group text-left",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-amber-100 flex items-center justify-center flex-shrink-0 group-hover:bg-amber-200 transition-colors",children:(0,s.jsx)(ef.A,{className:"w-5 h-5 text-amber-600"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-gray-900",children:"Sticky Note"}),(0,s.jsx)("p",{className:"text-[11px] text-gray-500",children:"Add an editable note with formatting"})]})]}),(0,s.jsxs)("button",{onClick:t,className:"w-full flex items-center gap-3 p-3 rounded-lg border border-gray-200 bg-white hover:bg-blue-50 hover:border-blue-200 transition-all group text-left",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-blue-100 flex items-center justify-center flex-shrink-0 group-hover:bg-blue-200 transition-colors",children:(0,s.jsx)(ey.A,{className:"w-5 h-5 text-blue-600"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-gray-900",children:"Rectangle"}),(0,s.jsx)("p",{className:"text-[11px] text-gray-500",children:"Add a shape for grouping elements"})]})]})]}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("div",{className:"p-4 bg-gray-50 border-t border-gray-200 text-center",children:(0,s.jsx)("p",{className:"text-[10px] text-gray-400 font-medium leading-relaxed",children:"Add elements directly to the canvas. Drag to reposition."})})]})}
1var ev=a(75035),ew=a(32265),eN=a(15695),eC=a(19992),ek=a(87485),eA=a(63434),eI=a(76432);let eS={is_public:!0,allow_unauthenticated_downloads:!1,collaborators:[]};function e_({canvasId:e,canvasSlug:t,onClose:a}){let[l,n]=(0,r.useState)(eS),[i,o]=(0,r.useState)(!0),[d,x]=(0,r.useState)(!1),[m,g]=(0,r.useState)(""),[h,u]=(0,r.useState)(!0),[p,f]=(0,r.useState)(!1),[y,j]=(0,r.useState)(null),[v,w]=(0,r.useState)(null),[N,C]=(0,r.useState)(null),[k,A]=(0,r.useState)(null),I=(0,r.useMemo)(()=>t?`${window.location.origin}/f/canvas/${t}`:"",[t]),S=(0,r.useMemo)(()=>e?`id=${encodeURIComponent(e)}`:t?`slug=${encodeURIComponent(t)}`:"",[e,t]),_=(0,r.useCallback)(async()=>{if(!S)return void o(!1);o(!0);try{let e=await fetch(`/api/artifact-canvas?${S}`);if(!e.ok)throw Error("Failed to load sharing settings");let t=await e.json(),a=t?.share_config||{};n({is_public:t?.visibility!=="authenticated",allow_unauthenticated_downloads:!!a.allow_unauthenticated_downloads,collaborators:Array.isArray(a.collaborators)?a.collaborators:[]})}catch(e){console.error("[CanvasSharingPalette] Failed to load state",e),A("Could not load sharing settings")}finally{o(!1)}},[S]);(0,r.useEffect)(()=>{_()},[_]);let P=(0,r.useCallback)(async t=>{if(!e)return;let a={...l,...t};n(a),x(!0),A(null);try{if(!(await fetch("/api/artifact-canvas",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,is_public:a.is_public,share_config:{allow_unauthenticated_downloads:a.allow_unauthenticated_downloads,collaborators:a.collaborators}})})).ok)throw Error("Failed to save sharing settings")}catch(e){console.error("[CanvasSharingPalette] Failed to save settings",e),A("Failed to save sharing settings")}finally{x(!1)}},[e,l]),T=(0,r.useCallback)(async()=>{if(e&&m.trim()){f(!0),A(null),j(null);try{let t=await fetch("/api/canvas/share/invite",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({canvasId:e,email:m.trim(),canEdit:h})}),a=await t.json();if(!t.ok)throw Error(a?.error||"Failed to invite user");let s=[...l.collaborators.filter(e=>e.email!==a.collaborator.email),a.collaborator];await P({collaborators:s}),g(""),j({email:a?.collaborator?.email||m.trim().toLowerCase(),inviteUrl:a?.invite_url||"",invitationSent:!!a?.invitation_sent,warning:a?.warning||null}),A(a?.invitation_sent?"Invitation sent":"Collaborator added. Email was not delivered.")}catch(e){console.error("[CanvasSharingPalette] Invite failed",e),A(e instanceof Error?e.message:"Failed to invite user")}finally{f(!1)}}},[e,m,h,l.collaborators,P]),$=(0,r.useCallback)(async(e,t)=>{w(e),A(null);try{let a=l.collaborators.map(a=>a.email===e?{...a,can_edit:t}:a);await P({collaborators:a}),A("Collaborator permissions updated")}catch(e){console.error("[CanvasSharingPalette] Failed to update collaborator permission",e),A("Failed to update collaborator permissions")}finally{w(null)}},[l.collaborators,P]),M=(0,r.useCallback)(async e=>{w(e),A(null);try{let t=l.collaborators.filter(t=>t.email!==e);await P({collaborators:t}),A("Collaborator removed")}catch(e){console.error("[CanvasSharingPalette] Failed to remove collaborator",e),A("Failed to remove collaborator")}finally{w(null)}},[l.collaborators,P]);return(0,s.jsxs)("div",{className:"w-80 h-full flex flex-col bg-white border-l border-gray-200 shadow-xl animate-in slide-in-from-right duration-200",children:[(0,s.jsxs)("div",{className:"p-4 border-b border-gray-200 flex items-center justify-between bg-gray-50/50",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(ev.A,{className:"w-4 h-4 text-indigo-500"}),(0,s.jsx)("h2",{className:"text-sm font-bold text-gray-900 uppercase tracking-tight",children:"Public Sharing"})]}),(0,s.jsx)(c.$,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:a,children:(0,s.jsx)(z.A,{className:"h-4 w-4 text-gray-400"})})]}),(0,s.jsx)("div",{className:"p-4 space-y-4 overflow-y-auto",children:i?(0,s.jsx)("p",{className:"text-xs text-gray-500",children:"Loading sharing settings..."}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 p-3 space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-gray-900",children:"Public Link"}),(0,s.jsx)("p",{className:"text-xs text-gray-500",children:"Allow non-auth users to view this canvas."})]}),(0,s.jsx)(ek.d,{checked:l.is_public,disabled:d,onCheckedChange:e=>P({is_public:e})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-gray-900",children:"Guest Downloads"}),(0,s.jsx)("p",{className:"text-xs text-gray-500",children:"Expose export downloads for public visitors."})]}),(0,s.jsx)(ek.d,{checked:l.allow_unauthenticated_downloads,disabled:d||!l.is_public,onCheckedChange:e=>P({allow_unauthenticated_downloads:e})})]}),I&&(0,s.jsx)("button",{className:"w-full rounded-md border border-gray-200 px-2 py-1.5 text-left text-xs text-gray-600 hover:bg-gray-50",onClick:()=>navigator.clipboard.writeText(I),children:(0,s.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,s.jsx)(ew.A,{className:"h-3 w-3"}),I]})})]}),(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 p-3 space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(eN.A,{className:"h-4 w-4 text-gray-500"}),(0,s.jsx)("p",{className:"text-sm font-semibold text-gray-900",children:"Invite Editor"})]}),(0,s.jsx)(b.p,{value:m,placeholder:"[email protected]",onChange:e=>g(e.target.value)}),(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs text-gray-600",children:[(0,s.jsx)("input",{type:"checkbox",checked:h,onChange:e=>u(e.target.checked)}),"Grant edit access"]}),(0,s.jsxs)(c.$,{className:"w-full",disabled:p||!m.trim(),onClick:T,children:[(0,s.jsx)(eC.A,{className:"h-4 w-4 mr-2"}),p?"Inviting...":"Invite User"]}),y&&(0,s.jsxs)("div",{className:"rounded-md border border-gray-200 bg-gray-50 p-2 space-y-2",children:[(0,s.jsx)("p",{className:`text-xs font-medium ${y.invitationSe
1nt?"text-green-700":"text-amber-700"}`,children:y.invitationSent?`Email sent to ${y.email}`:`Email not sent to ${y.email}`}),y.warning&&(0,s.jsx)("p",{className:"text-[11px] text-gray-600",children:y.warning}),y.inviteUrl&&(0,s.jsx)("button",{className:"w-full rounded border border-gray-200 bg-white px-2 py-1 text-left text-[11px] text-gray-700 hover:bg-gray-100",onClick:()=>navigator.clipboard.writeText(y.inviteUrl),children:"Copy invite link"})]})]}),l.collaborators.length>0&&(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("p",{className:"text-xs font-semibold text-gray-700 uppercase tracking-wide",children:"Collaborators"}),l.collaborators.map(e=>(0,s.jsxs)("div",{className:"rounded-md border border-gray-200 p-2",children:[(0,s.jsx)("p",{className:"text-xs font-medium text-gray-900",children:e.email}),(0,s.jsxs)("p",{className:"text-[11px] text-gray-500 mb-2",children:[e.can_edit?"Can edit":"View only"," \xb7 ",e.status||"active"]}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsxs)("span",{className:"text-[11px] text-gray-500",children:["Access: ",e.can_edit?"Can edit":"Can view"]}),(0,s.jsx)(eI.G,{canEdit:!!e.can_edit,disabled:v===e.email,onSetCanEdit:t=>{$(e.email,t)},onRequestRemove:()=>C(e.email)})]})]},e.email))]}),k&&(0,s.jsx)("p",{className:"text-xs text-gray-600",children:k})]})}),(0,s.jsx)(eA.Lt,{open:!!N,onOpenChange:e=>{e||C(null)},children:(0,s.jsxs)(eA.EO,{children:[(0,s.jsxs)(eA.wd,{children:[(0,s.jsx)(eA.r7,{children:"Remove collaborator?"}),(0,s.jsx)(eA.$v,{children:N?`${N} will lose access to this canvas.`:"This user will lose access to this canvas."})]}),(0,s.jsxs)(eA.ck,{children:[(0,s.jsx)(eA.Zr,{children:"Cancel"}),(0,s.jsx)(eA.Rx,{className:"bg-red-600 hover:bg-red-700",onClick:()=>{N&&(M(N),C(null))},children:"Remove"})]})]})})]})}var eP=a(19753),eT=a(75472),e$=a(84635),eM=a(31987),eE=a(93210);let eL={stickyNote:ef.A,rectangleShape:ey.A,canvasArtifactCard:A.A,canvasAgentCard:M.A,stageBoard:F.A,agentKnowledgeTableBoard:M.A,socialCalendarBoard:F.A};function eD({nodes:e,onClose:t,onSelectNode:a,onMoveForward:r,onMoveBackward:l,onToggleVisibility:n,selectedNodeId:i}){let o=[...e].reverse();return(0,s.jsxs)("div",{className:"w-64 h-full flex flex-col bg-white border-r border-gray-200 shadow-xl animate-in slide-in-from-left duration-200",children:[(0,s.jsxs)("div",{className:"p-3 border-b border-gray-200 flex items-center justify-between bg-gray-50/50",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(F.A,{className:"w-4 h-4 text-gray-600"}),(0,s.jsx)("h2",{className:"text-sm font-bold text-gray-900 uppercase tracking-tight",children:"Layers"})]}),(0,s.jsx)(c.$,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full",onClick:t,children:(0,s.jsx)(z.A,{className:"h-3.5 w-3.5 text-gray-400"})})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===o.length?(0,s.jsxs)("div",{className:"p-6 text-center",children:[(0,s.jsx)(F.A,{className:"w-8 h-8 text-gray-200 mx-auto mb-2"}),(0,s.jsx)("p",{className:"text-xs text-gray-400",children:"No elements on canvas"})]}):o.map(e=>{let t,o=eL[e.type||""]||k.A,d=e.id===i,c=e.hidden;return(0,s.jsxs)("div",{className:(0,eE.cn)("flex items-center gap-2 px-3 py-2 border-b border-gray-50 cursor-pointer transition-colors group",d?"bg-blue-50":"hover:bg-gray-50",c&&"opacity-40"),onClick:()=>a(e.id),children:[(0,s.jsx)(o,{className:(0,eE.cn)("w-3.5 h-3.5 flex-shrink-0",d?"text-blue-600":"text-gray-400")}),(0,s.jsx)("span",{className:(0,eE.cn)("flex-1 text-xs truncate",d?"font-semibold text-blue-700":"text-gray-700"),children:(t=e.data,t?.artifact?.title?t.artifact.title:t?.board?.title?t.board.title:"stickyNote"===e.type?"Sticky Note":"rectangleShape"===e.type?"Rectangle":e.id)}),(0,s.jsxs)("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),r(e.id)},className:"p-0.5 rounded hover:bg-gray-200",title:"Bring forward",children:(0,s.jsx)(eP.A,{className:"w-3 h-3 text-gray-500"})}),(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),l(e.id)},className:"p-0.5 rounded hover:bg-gray-200",title:"Send backward",children:(0,s.jsx)(eT.A,{className:"w-3 h-3 text-gray-500"})}),(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),n(e.id)},className:"p-0.5 rounded hover:bg-gray-200",title:"Toggle visibility",children:c?(0,s.jsx)(e$.A,{className:"w-3 h-3 text-gray-400"}):(0,s.jsx)(eM.A,{className:"w-3 h-3 text-gray-500"})})]})]},e.id)})}),(0,s.jsx)("div",{className:"p-3 bg-gray-50 border-t border-gray-200 text-center",children:(0,s.jsxs)("p",{className:"text-[10px] text-gray-400 font-medium",children:[e.length," element",1!==e.length?"s":""]})})]})}var eF=a(90923),eO=a(44433),eR=a(24422),eU=a(80223);let ez=e=>e.trim().replace(/^#+/,"").replace(/[^\x20-\x7E\u00A0-\uFFFF]/g,"").replace(/\s+/g," ").trim();function eB({tags:e,onChange:t,disabled:a}){let[l,n]=(0,r.useState)(""),i=(0,r.useMemo)(()=>{let t=new Set;
1return e.map(ez).filter(Boolean).filter(e=>{let a=e.toLowerCase();return!t.has(a)&&(t.add(a),!0)})},[e]),o=e=>{let a=e.split(",").map(ez).filter(Boolean);if(0===a.length)return void n("");let s=new Set(i.map(e=>e.toLowerCase())),r=[];for(let e of a){let t=e.toLowerCase();s.has(t)||(s.add(t),r.push(e))}r.length>0&&t([...i,...r]),n("")};return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-gray-500 uppercase",children:"Tags"}),(0,s.jsxs)("div",{className:"mt-2 flex gap-2",children:[(0,s.jsx)(b.p,{value:l,onChange:e=>n(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),o(l))},placeholder:"Add a tag",disabled:a}),(0,s.jsx)(c.$,{type:"button",variant:"secondary",onClick:()=>o(l),disabled:a,children:"Add"})]})]}),i.length>0?(0,s.jsx)("div",{className:"flex flex-wrap gap-2",children:i.map(e=>(0,s.jsxs)(u.E,{variant:"secondary",className:"flex items-center gap-1 text-xs",children:["#",e,(0,s.jsx)("button",{type:"button",onClick:()=>{t(i.filter(t=>t.toLowerCase()!==e.toLowerCase()))},className:"rounded-full p-0.5 hover:bg-gray-200","aria-label":`Remove ${e}`,disabled:a,children:(0,s.jsx)(z.A,{className:"h-3 w-3"})})]},e))}):(0,s.jsx)("p",{className:"text-sm text-gray-500",children:"No tags yet. Add tags to improve filtering and AI recall."})]})}function eH({knowledgeItemId:e,open:t,onOpenChange:a,userId:l,onSave:n,initialData:i}){let{tableOptions:o,loadingTables:d,saving:x,handleUpdate:m}=function(e,t){let[a,s]=(0,r.useState)(!1),{items:l,loading:n}=(0,W.G)(t,{type:"table"},!!t&&!!e);return{tableOptions:(0,r.useMemo)(()=>{let e=[{value:"none",label:"No table"}];return l.forEach(t=>{e.push({value:t.id,label:t.file_name||t.id})}),e},[l]),loadingTables:n,saving:a,handleUpdate:(0,r.useCallback)(async t=>{if(!e)return!1;s(!0);try{let a=await fetch("/api/knowledge-base/update",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,...t})});return(await a.json()).success}catch(e){return console.error("[useArtifactSettings] Update error:",e),!1}finally{s(!1)}},[e])}}(e,l),g=i?.storage_path||i?.storagePath,h=i?.source_type||i?.sourceType,p=(0,q.Sj)(g),f=!!g&&/\.(png|jpg|jpeg|webp|gif|svg|bmp|tiff?)$/i.test(g),j=!!g&&/\.(mp4|mov|webm|avi|mkv|m4v)$/i.test(g),v=!!g&&/\.(mp3|wav|m4a|aac|flac|ogg)$/i.test(g),w=(0,Z.s)(g,h),[N,C]=(0,r.useState)({fileName:i?.file_name||"",notes:i?.metadata?.notes||"",stage:i?.metadata?.stage||null,tableId:i?.metadata?.table_id||"none",tags:Array.isArray(i?.metadata?.tags)?i?.metadata?.tags:[]}),k=async()=>{await m(N)&&(n?.(),a(!1))};return t?(0,s.jsx)(Q.lG,{open:t,onOpenChange:a,children:(0,s.jsxs)(Q.Cf,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[(0,s.jsx)(Q.c7,{children:(0,s.jsxs)("div",{className:"flex items-start justify-between gap-3 pr-12",children:[(0,s.jsx)(Q.L3,{className:"text-xl font-medium",children:"Knowledge Item Details"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(c.$,{variant:"outline",size:"sm",onClick:()=>a(!1),disabled:x,children:"Cancel"}),(0,s.jsx)(c.$,{size:"sm",onClick:k,disabled:x,children:x?"Saving...":"Save"})]})]})}),(0,s.jsxs)(eO.tU,{defaultValue:"properties",className:"w-full",children:[(0,s.jsxs)(eO.j7,{className:"grid w-full grid-cols-6",children:[(0,s.jsx)(eO.Xi,{value:"properties",children:"Properties"}),(0,s.jsx)(eO.Xi,{value:"sharing",children:"Sharing"}),(0,s.jsx)(eO.Xi,{value:"notes",children:"Notes"}),(0,s.jsx)(eO.Xi,{value:"tags",children:"Tags"}),(0,s.jsx)(eO.Xi,{value:"metadata",children:"Metadata"}),(0,s.jsx)(eO.Xi,{value:"preview",children:"Preview"})]}),(0,s.jsx)(eO.av,{value:"properties",className:"space-y-6 mt-4",children:(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-gray-500 uppercase",children:"File Name"}),(0,s.jsx)(b.p,{value:N.fileName,onChange:e=>C(t=>({...t,fileName:e.target.value})),disabled:x,className:"mt-1"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-gray-500 uppercase",children:"Agent Slug"}),(0,s.jsx)(b.p,{value:i?.agent_slug||"system",disabled:!0,className:"mt-1"})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-gray-500 uppercase",children:"Knowledge Table"}),(0,s.jsxs)(y.l6,{value:N.tableId,onValueChange:e=>C(t=>({...t,tableId:e})),disabled:d||x,children:[(0,s.jsx)(y.bq,{className:"mt-1",children:(0,s.jsx)(y.yv,{})}),(0,s.jsx)(y.gC,{children:o.map(e=>(0,s.jsx)(y.eb,{value:e.value,children:e.label},e.value))})]})]}),(0,s.jsx)(eR.O,{value:N.stage,onChange:e=>C(t=>({...t,stage:e})),disabled:x,showLabel:!0}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-gray-500 uppercase",children:"Source Type"}),(0,s.jsx)("div",{className:"mt-1",children:(0,s.jsx)(u.E,{children:i?.source_type||"Unknown"})})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-gray-500 uppercase",children:"Item Count"}),(0,s.jsx)(b.p,{value:i?.item_count||1,disabled:!0,className:"mt-1"})]})]})]})}),(0,s.jsx)(eO.av,{value:"sharing",className:"mt-4",children:l&&i&&(0,s.jsx)(eU.J,{item:i,userId:l,onUpdate:()=>n?.()})}),(0,s.jsx)(eO.av,{value:"notes",className:"mt-4",children:(0,s.jsx)(eF.T,{value:N.notes,onChange:e=>C(t=>({...t,notes:e.target.value})),placeholder:"Add notes...",className:"min-h-[300px] font-mono text-sm",disabled:x})}),(0,s.jsx)(eO.av,{value:"tags",className:"mt-4",children:(0,s.jsx)(eB,{tags:N.tags,onChange:e=>C(t=>({...t,tags:e})),disabled:x})}),(0,s.jsx)(eO.av,{value:"metadata",className:"mt-4",children:(0,s.jsx)("pre",{className:"p-4 bg-gray-100 rounded text-xs overflow-x-auto border",children:JSON.stringify(i?.metadata,null,2)})}),(0,s.jsx)(eO.av,{value:"preview",className:"mt-4",children:f&&p?(0,s.jsx)("div",{className:"overflow-hidden rounded-md border border-gray-200 bg-white",children:(0,s.jsx)("img",{src:p,alt:N.fileName||"Preview",className:"h-auto max-h-[520px] w-full object-contain"})}):j&&p?(0,s.jsx)("div",{className:"overflow-hidden rounded-md border border-gray-200 bg-black",children:(0,s.jsx)("video",{src:p,controls:!0,className:"h-auto max-h-[520px] w-full object-contain"})}):v&&p?(0,s.jsx)("div",{className:"rounded-md border border-gray-200 bg-white p-4",children:(0,s.jsx)("audio",{src:p,controls:!0,className:"w-full"})}):w?(0,s.jsx)("div",{className:"h-[520px] overflow-hidden rounded-md border border-gray-200 bg-white",children:(0,s.jsx)(Z.a,{storagePath:g,sourceType:h,className:"h-full w-full"})}):(0,s.jsx)("div",{className:"rounded-md border border-gray-200 bg-gray-50 p-4 text-sm text-gray-600",children:"Preview unavailable for this file type."})})]})]})}):null}var eW=a(92169);function eX({open:e,onOpenChange:t,boardTitle:a,artifactCount:r,onConfirm:l,isLoading:n=!1}){return(0,s.jsx)(Q.lG,{open:e,onOpenChange:t,children:(0,s.jsxs)(Q.Cf,{className:"sm:max-w-[425px]",children:[(0,s.jsx)(Q.c7,{children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(eW.A,{className:"h-5 w-5 text-amber-600"}),(0,s.jsx)(Q.L3,{children:"Delete Board?"})]})}),(0,s.jsx)(Q.rr,{asChild:!0,children:(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("p",{className:"text-sm font-medium text-gray-900",children:["You're about to delete ",(0,s.jsxs)("span",{className:"font-semibold",children:['"',a,'"']})]}),(0,s.jsxs)("div",{className:"bg-amber-50 border border-amber-200 rounded-[5px] p-3",children:[(0,s.jsxs)("p",{className:"text-sm text-amber-900",children:["â ï¸ This will remove ",(0,s.jsx)("span",{className:"font-semibold",children:r})," knowledge item",1!==r?"s":""," grouped in this board."]}),(0,s.jsx)("p",{className:"text-xs text-amber-700 mt-2",children:"This action will clear all artifacts from the canvas data and sync to the database."})]}),(0,s.jsx)("p",{className:"text-xs text-gray-600",children:"Are you sure you want to proceed?"})]})}),(0,s.jsxs)(Q.Es,{className:"gap-2 sm:gap-0",children:[(0,s.jsx)(c.$,{variant:"outline",onClick:()=>t(!1),disabled:n,children:"Cancel"}),(0,s.jsx)(c.$,{variant:"destructive",onClick:()=>{l(),t(!1)},disabled:n,children:n?"Deleting...":"Delete Board"})]})]})})}var eK=a(81211),eV=a(93425);function eG({open:e,onOpenChange:t,templateId:a,userId:n,onSuccess:i,onError:d}){let[x,m]=(0,r.useState)(!1),[g,h]=(0,r.useState)(!1),[p,j]=(0,r.useState)(null),[v,w]=(0,r.useState)(null),[N,C]=(0,r.useState)("idle"),k=p?.content_metadata?.modelId?ed.zN.getModelById(p.content_metadata.modelId):null,A=k?.icon||null;(0,r.useEffect)(()=>{e&&a&&n&&(m(!0),C("idle"),fetch(`/api/agents/list?user_id=${n}&agent_slug=${a}`).then(e=>{if(!e.ok)throw Error("Failed to fetch agent");return e.json()}).then(e=>{if(!e.success||!e.agents?.length)throw Error("Agent not found");let t=e.agents[0];w(t),j({id:t.slug,title:t.agent_name||t.slug,slug:t.slug,description:t.instructions?.substring(0,200)||"",content_type:"agent_c
1onfig",content_metadata:{modelId:t.modelId,status:"active",instructions:t.instructions,linkedKnowledgeCount:t.knowledge?.length||0,linkedToolCount:t.workflow_nodes?.length||0},visibility:"public",is_active:!0})}).catch(e=>{console.error("[AgentCanvasSettingsModal] L4: Fetch failed",e),d?.(e.message||"Failed to load agent settings"),t(!1)}).finally(()=>m(!1)))},[e,a,n,d,t]);let I=(0,r.useCallback)((e,t)=>{j(a=>a?{...a,[e]:t}:null)},[]),S=(0,r.useCallback)((e,t)=>{j(a=>a?{...a,content_metadata:{...a.content_metadata,[e]:t}}:null)},[]),_=async()=>{if(!p||!p.title||!v||!n)return void d?.("Title is required");h(!0),C("idle");try{let e=await fetch("/api/agents/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...v,agent_name:p.title,instructions:p.content_metadata?.instructions||v.instructions,user_id:n})}),a=await e.json();if(!e.ok)throw Error(a.error||"Failed to save changes");C("success"),i?.(p),setTimeout(()=>t(!1),800)}catch(e){console.error("[AgentCanvasSettingsModal] L4: Save failed",e),C("error"),d?.(e instanceof Error?e.message:"Failed to save")}finally{h(!1)}};if(x||!p)return(0,s.jsx)(Q.lG,{open:e,onOpenChange:t,children:(0,s.jsxs)(Q.Cf,{className:"max-w-md",children:[(0,s.jsx)(Q.c7,{children:(0,s.jsxs)(Q.L3,{className:"flex items-center gap-2",children:[(0,s.jsx)(eK.A,{className:"h-5 w-5"}),"Agent Settings"]})}),(0,s.jsx)("div",{className:"flex items-center justify-center h-48",children:(0,s.jsx)(l.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})})]})});let P=p.content_metadata||{};return(0,s.jsx)(Q.lG,{open:e,onOpenChange:t,children:(0,s.jsxs)(Q.Cf,{className:"max-w-md",children:[(0,s.jsx)(Q.c7,{children:(0,s.jsxs)(Q.L3,{className:"flex items-center gap-2",children:[(0,s.jsx)("div",{className:"w-8 h-8 rounded-lg bg-gray-100 border border-gray-200 flex items-center justify-center",children:A?(0,s.jsx)(A,{className:"h-4 w-4"}):(0,s.jsx)(M.A,{className:"h-4 w-4 text-gray-500"})}),"Agent Settings"]})}),(0,s.jsxs)("div",{className:"space-y-4 py-2",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(f.J,{htmlFor:"title",className:"text-sm font-medium",children:"Agent Name *"}),(0,s.jsx)(b.p,{id:"title",value:p.title,onChange:e=>I("title",e.target.value),placeholder:"e.g. Content Writer Agent",className:"h-9"})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(f.J,{className:"text-sm font-medium text-muted-foreground",children:"Slug"}),(0,s.jsx)("div",{className:"px-3 py-2 bg-muted rounded-md text-sm font-mono text-muted-foreground",children:p.slug})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(f.J,{htmlFor:"description",className:"text-sm font-medium",children:"Description"}),(0,s.jsx)(eF.T,{id:"description",value:p.description||"",onChange:e=>I("description",e.target.value),placeholder:"Brief description of agent capabilities...",rows:2,className:"resize-none"})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(f.J,{className:"text-sm font-medium",children:"Status"}),(0,s.jsxs)(y.l6,{value:P.status||"active",onValueChange:e=>S("status",e),children:[(0,s.jsx)(y.bq,{className:"h-9",children:(0,s.jsx)(y.yv,{})}),(0,s.jsx)(y.gC,{children:["active","draft","archived"].map(e=>(0,s.jsx)(y.eb,{value:e,children:(0,s.jsxs)("span",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:(0,eE.cn)("w-2 h-2 rounded-full","active"===e&&"bg-green-500","draft"===e&&"bg-yellow-500","archived"===e&&"bg-gray-400")}),e.charAt(0).toUpperCase()+e.slice(1)]})},e))})]})]}),P.modelId&&(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(f.J,{className:"text-sm font-medium text-muted-foreground",children:"Model"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(u.E,{variant:"secondary",className:"text-xs",children:P.modelId}),(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:"(edit in Agent Builder)"})]})]}),P.categoryLabel&&(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(f.J,{className:"text-sm font-medium text-muted-foreground",children:"Category"}),(0,s.jsx)(u.E,{variant:"outline",className:"text-xs",children:P.categoryLabel})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between pt-2 border-t",children:[(0,s.jsx)(f.J,{className:"text-sm font-medium",children:"Active"}),(0,s.jsx)("button",{type:"button",onClick:()=>I("is_active",!p.is_active),className:(0,eE.cn)("relative inline-flex h-6 w-11 items-center rounded-full transition-colors",p.is_active?"bg-blue-600":"bg-gray-200"),children:(0,s.jsx)("span",{className:(0,eE.cn)("inline-block h-4 w-4 transform rounded-full bg-white transition-transform",p.is_active?"translate-x-6":"translate-x-1")})})]})]}),(0,s.jsxs)(Q.Es,{className:"gap-2",children:["success"===N&&(0,s.jsxs)("div",{className:"flex items-center gap-1 text-sm text-green-600 mr-auto",children:[(0,s.jsx)(o.A,{className:"h-4 w-4"}),"Saved"]}),"error"===N&&(0,s.jsxs)("div",{className:"flex items-center gap-1 text-sm text-red-600 mr-auto",children:[(0,s.jsx)(eV.A,{className:"h-4 w-4"}),"Failed"]}),(0,s.jsx)(c.$,{variant:"outline",onClick:()=>t(!1),disabled:g,children:"Cancel"}),(0,s.jsxs)(c.$,{onClick:_,disabled:g||!p.title,children:[g&&(0,s.jsx)(l.A,{className:"h-4 w-4 mr-2 animate-spin"}),"Save Changes"]})]})]})})}let eY=(0,r.createContext)(null);function eJ(){return(0,r.useContext)(eY)}function eq({children:e,hoveredBoardId:t}){return(0,s.jsx)(eY.Provider,{value:t,children:e})}var eZ=a(6989),eQ=a(50810),e0=a(25196),e1=a(90755),e2=a(42934);function e5({agent:e,isSelected:t,onSelect:a,onOpenModal:l,onOpenBuilder:n,onRemove:i,className:o}){let[d,x]=(0,r.useState)(!1),m=e.modelId?ed.zN.getModelById(e.modelId):null,g=m?.icon||null;return(0,s.jsxs)("div",{className:(0,eE.cn)("relative bg-white rounded-lg border border-gray-200 shadow-md transition-all duration-200 cursor-pointer group","hover:shadow-lg hover:border-gray-300",t&&"ring-2 ring-gray-500 border-gray-400",o),style:{width:280,minHeight:180},onClick:a,children:[(0,s.jsx)("div",{className:"p-4 pb-2",children:(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)("div",{className:"w-11 h-11 rounded-lg bg-white flex items-center justify-center flex-shrink-0 border border-gray-200 shadow-sm",children:e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-full h-full rounded-lg object-cover"}):g?(0,s.jsx)(g,{className:"w-6 h-6"}):(0,s.jsx)(M.A,{className:"w-6 h-6 text-gray-500"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 pr-8",children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-gray-900 truncate",children:e.name}),(0,s.jsx)("p",{className:"text-[10px] text-gray-500 font-mono truncate",children:e.slug})]})]})}),e.description&&(0,s.jsx)("p",{className:"px-4 text-xs text-gray-600 line-clamp-2 leading-relaxed",children:e.description}),(0,s.jsxs)("div",{className:"px-4 pt-2 pb-3 space-y-1.5 mt-1 border-t border-gray-100 mx-4",children:[e.status&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:(0,eE.cn)("w-1.5 h-1.5 rounded-full","active"===e.status&&"bg-green-500","draft"===e.status&&"bg-yellow-500","archived"===e.status&&"bg-gray-400")}),(0,s.jsx)("span",{className:"text-[10px] text-gray-600 font-medium",children:e.status})]}),e.modelId&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[g?(0,s.jsx)(g,{className:"w-3 h-3"}):(0,s.jsx)(M.A,{className:"w-3 h-3 text-gray-400"}),(0,s.jsx)("span",{className:"text-[10px] text-gray-600 font-medium truncate",children:e.modelId})]}),(e.linkedKnowledgeCount??0)>0&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)(E.A,{className:"w-3 h-3 text-gray-400"}),(0,s.jsxs)("span",{className:"text-[10px] text-gray-600 font-medium",children:[e.linkedKnowledgeCount," KB"]})]}),(e.linkedToolCount??0)>0&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)(D.A,{className:"w-3 h-3 text-gray-400"}),(0,s.jsxs)("span",{className:"text-[10px] text-gray-600 font-medium",children:[e.linkedToolCount," tools"]})]})]}),(0,s.jsx)("div",{className:(0,eE.cn)("absolute top-3 right-3 flex items-center gap-1 transition-opacity duration-200 ease-in-out","opacity-0 group-hover:opacity-100",d&&"opacity-100"),children:(0,s.jsxs)(e2.rI,{open:d,onOpenChange:x,children:[(0,s.jsx)(e2.ty,{asChild:!0,children:(0,s.jsx)(c.$,{variant:"ghost",size:"icon",className:"h-7 w-7 bg-white border border-gray-200 shadow-sm hover:bg-gray-50",children:(0,s.jsx)(eQ.A,{className:"h-3.5 w-3.5 text-gray-600"})})}),(0,s.jsxs)(e2.SQ,{align:"end",className:"w-40",children:[l&&(0,s.jsxs)(e2._2,{onClick:e=>{e.stopPropagation(),l()},children:[(0,s.jsx)(eK.A,{className:"h-3.5 w-3.5 mr-2"}),"Configure"]}),n&&(0,s.jsxs)(e2._2,{onClick:e=>{e.stopPropagation(),n()},children:[(0,s.jsx)(e0.A,{className:"h-3.5 w-3.5 mr-2"}),"Open Builder"]}),i&&(0,s.jsxs)(e2._2,{onClick:e=>{e.stopPropagation(),i()},className:"text-red-600 focus:text-red-600",children:[(0,s.jsx)(e1.A,{className:"h-3.5 w-3.5 mr-2"}),"Remove"]})]})]})})]})}var e3=a(39735),e4=a(37182),e6=a(80444);let e9=[{label:"16:9",value:16/9,className:"aspect-video"},{label:"1:1",value:1,className:"aspect-square"},{label:"4:5",value:.8,className:"aspect-[4/5]"},{label:"9:16",value:9/16,className:"aspect-[9/16]"}];function e8({images:e,title:t,aspectLabel:a,aspectClass:l}){let[n,i]=(0,r.useState)(0);return e&&0!==e.length?1===e.length?(0,s.jsxs)("div",{className:(0,eE.cn)("relative w-full h-full group/image",l),children:[(0,s.jsx)(e4.default,{src:e[0],alt:t,fill:!0,className:"object-cover transition-transform duration-500 group-hover/image:scale-105",sizes:"400px",unoptimized:!0}),(0,s.jsx)("div",{className:"absolute top-2 left-2 z-20",children:(0,s.jsxs)(u.E,{variant:"secondary",className:"bg-white/90 backdrop-blur-sm text-[10px] px-1.5 py-0 h-5 border-gray-200 shadow-sm font-bold",children:[(0,s.jsx)(A.A,{className:"h-3 w-3 mr-1"})," IMAGE"]})}),a&&(0,s.jsx)("div",{className:"absolute top-2 right-2 z-20",children:(0,s.jsx)(u.E,{variant:"outline",className:"bg-white/90 text-[10px] px-1.5 py-0 h-5 border-gray-200 font-medium",children:a})})]}):(0,s.jsxs)("div",{className:(0,eE.cn)("flex w-full h-full bg-background overflow-hidden",l),children:[(0,s.jsxs)("div",{className:"flex-1 relative bg-gray-50 border-r border-gray-100 group/main",children:[(0,s.jsx)(e4.default,{src:e[n],alt:`${t} - ${n+1}`,fill:!0,className:"object-contain p-2 transition-all duration-300",unoptimized:!0}),(0,s.jsxs)("div",{className:"absolute top-2 left-2 z-20 flex gap-1",children:[(0,s.jsxs)(u.E,{variant:"secondary",className:"bg-white/90 backdrop-blur-sm text-[10px] px-1.5 py-0 h-5 border-gray-200 shadow-sm font-bold",children:[(0,s.jsx)(A.A,{className:"h-3 w-3 mr-1"})," GALLERY"]}),(0,s.jsxs)(u.E,{variant:"outline",className:"bg-white/90 text-[10px] px-1.5 py-0 h-5 border-gray-200 font-medium",children:[n+1,"/",e.length]})]}),a&&(0,s.jsx)("div",{className:"absolute top-2 right-2 z-20",children:(0,s.jsx)(u.E,{variant:"outline",className:"bg-white/90 text-[10px] px-1.5 py-0 h-5 border-gray-200 font-medium",children:a})})]}),(0,s.jsx)("div",{className:"w-[80px] overflow-y-auto custom-scrollbar p-1.5
1space-y-1.5 bg-gray-50/50 flex-shrink-0",children:e.map((e,t)=>(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),i(t)},className:(0,eE.cn)("w-full aspect-square rounded-[4px] overflow-hidden border-2 transition-all duration-200",n===t?"border-blue-500 ring-2 ring-blue-500/10 shadow-sm":"border-transparent opacity-60 hover:opacity-100 hover:border-gray-300"),children:(0,s.jsx)("img",{src:e,alt:`Thumb ${t+1}`,className:"w-full h-full object-cover"})},t))})]}):null}function e7({artifact:e,linkConfirmOpen:t,onConfirmOpen:a,onDelete:l,onSettingsOpen:n}){let[i,o]=(0,r.useState)(!1),[d,x]=(0,r.useState)(!1),m=e.metadata?.modelId||e.metadata?.model_id,g=m?ed.zN.getModelById(m):null,h=g?.icon||null,u=(0,r.useCallback)(e=>{if(!e)return null;let t=e.width||e.image_width||e.imageWidth||e?.image?.width||e?.dimensions?.width,a=e.height||e.image_height||e.imageHeight||e?.image?.height||e?.dimensions?.height;if(!t||!a)return null;let s=t/a;return e9.reduce((e,t)=>Math.abs(t.value-s)<Math.abs(e.value-s)?t:e,e9[0])},[]),p=(0,r.useMemo)(()=>{let t=e.metadata||{},a=t.image_paths||t.imagePaths||[],s=e.storagePath&&/\.(png|jpg|jpeg|webp|gif|svg)$/i.test(e.storagePath),r=a.length>0?a.map(e=>(0,q.Sj)(e)).filter(e=>!!e):s&&e.storagePath?[(0,q.Sj)(e.storagePath)].filter(e=>!!e):[];return{display:r,hasImages:r.length>0,aspect:u(t)}},[e.metadata,e.storagePath,e.id,u]),b=(0,r.useMemo)(()=>(0,q.SX)({storage_path:e.storagePath,metadata:e.metadata}),[e.storagePath,e.metadata]),f=e.knowledgeItemId&&t===e.id,y=b.find(e=>"video"===e.type),j=y?.url||y?.previewUrl,v=!!j,w=!p.hasImages&&!v&&(0,Z.s)(e.storagePath,e.sourceType),N=(e,t)=>{e.stopPropagation(),t()};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:(0,eE.cn)("relative w-full bg-gray-50 rounded-[5px] overflow-hidden group hover:shadow-md transition-shadow cursor-pointer border border-gray-200 flex flex-col",w?"h-[390px]":"h-[260px]"),onClick:()=>e.knowledgeItemId&&a(e.id),children:[(0,s.jsx)("div",{className:"flex-1 min-h-0 relative",children:p.hasImages?(0,s.jsx)(e8,{images:p.display,title:e.title,aspectLabel:p.aspect?.label,aspectClass:p.aspect?.className}):v?(0,s.jsxs)("div",{className:"relative h-full w-full overflow-hidden bg-black",children:[(0,s.jsx)(J.Q,{src:j,containerClassName:"absolute inset-0",objectFit:"contain",playPosition:"center"}),(0,s.jsx)("button",{type:"button",className:"absolute inset-0 z-20 flex items-center justify-center bg-black/10",onClick:e=>{e.stopPropagation(),x(!0)},title:"Play video",children:(0,s.jsx)(V.A,{className:"h-8 w-8 text-white drop-shadow"})})]}):(0,s.jsx)("div",{className:"w-full h-full flex flex-col items-center justify-center p-6 bg-gradient-to-br from-gray-50 to-gray-100",children:w?(0,s.jsx)("div",{className:"h-full w-full overflow-hidden rounded-md border border-gray-200 bg-white",children:(0,s.jsx)(Z.a,{storagePath:e.storagePath,sourceType:e.sourceType,className:"h-full w-full"})}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"w-20 h-20 rounded-lg bg-white border-2 border-gray-200 flex items-center justify-center mb-5 shadow-sm group-hover:border-gray-300 transition-colors",children:(0,s.jsx)(k.A,{className:"w-10 h-10 text-gray-400"})}),(0,s.jsxs)("div",{className:"text-center px-4 w-full",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-gray-700 line-clamp-3 mb-2 leading-relaxed",children:e.title}),(0,s.jsx)("p",{className:"text-xs text-gray-500 uppercase tracking-tight font-bold",children:e.sourceType||"Document"})]})]})})}),(0,s.jsxs)("div",{className:"border-t border-gray-200 bg-white px-3 py-2 space-y-1.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] text-gray-600 font-medium",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-gray-400"}),(0,s.jsx)("span",{className:"uppercase",children:e.sourceType||"Document"})]}),p.aspect&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] text-gray-600 font-medium",children:[(0,s.jsx)(A.A,{className:"w-3 h-3 text-gray-400"}),(0,s.jsxs)("span",{children:[p.aspect.label," aspect"]})]}),m&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] text-gray-600 font-medium",children:[h?(0,s.jsx)(h,{className:"w-3 h-3"}):(0,s.jsx)(M.A,{className:"w-3 h-3 text-gray-400"}),(0,s.jsx)("span",{className:"truncate",children:m})]})]}),(0,s.jsxs)("div",{className:"absolute top-2 right-2 flex gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity z-20",children:[e.knowledgeItemId&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{onClick:t=>N(t,()=>n?.(e)),className:"p-1.5 bg-white border border-gray-200 rounded-[5px] shadow-sm hover:bg-gray-50 transition-all",title:"Settings",children:(0,s.jsx)(eK.A,{className:"w-3.5 h-3.5 text-gray-700"})}),(0,s.jsx)("button",{onClick:t=>N(t,()=>window.open(`/knowledge-base?itemId=${e.knowledgeItemId}`,"_blank")),className:"p-1.5 bg-white border border-gray-200 rounded-[5px] shadow-sm hover:bg-gray-50 transition-all",title:"View in KB",children:(0,s.jsx)(e0.A,{className:"w-3.5 h-3.5 text-gray-700"})})]}),(0,s.jsx)("button",{onClick:e=>N(e,()=>o(!0)),className:"p-1.5 bg-white border border-gray-200 rounded-[5px] shadow-sm hover:bg-red-50 hover:text-red-600 hover:border-red-200 transition-all",title:"Remove from board",children:(0,s.jsx)(e1.A,{className:"w-3.5 h-3.5"})})]}),(0,s.jsx)(e6.AM,{open:!!f,onOpenChange:e=>!e&&a(null),children:(0,s.jsx)(e6.hl,{className:"w-64 p-3 z-50",children:(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-gray-900",children:"Configure Connection"}),(0,s.jsx)("p",{className:"text-xs text-gray-500 leading-relaxed",children:"Adjust how this artifact is referenced by agents."})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(c.$,{variant:"outline",size:"sm",className:"flex-1 h-8 text-xs",onClick:()=>a(null),children:"Close"}),(0,s.jsx)(c.$,{size:"sm",className:"flex-1 h-8 text-xs bg-blue-600 hover:bg-blue-700",onClick:()=>{n?.(e),a(null)},children:"Configure"})]})]})})})]}),(0,s.jsx)(eA.Lt,{open:i,onOpenChange:o,children:(0,s.jsxs)(eA.EO,{onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)(eA.wd,{children:[(0,s.jsx)(eA.r7,{children:"Remove from board?"}),(0,s.jsx)(eA.$v,{children:"This artifact will be removed from the canvas. It will remain in the knowledge base."})]}),(0,s.jsxs)(eA.ck,{children:[(0,s.jsx)(eA.Zr,{children:"Cancel"}),(0,s.jsx)(eA.Rx,{className:"bg-red-600 hover:bg-red-700 text-white",onClick:()=>l?.(e.id),children:"Remove"})]})]})}),(0,s.jsx)(Q.lG,{open:d,onOpenChange:x,children:(0,s.jsxs)(Q.Cf,{className:"max-w-4xl border-gray-200 bg-white p-4",children:[(0,s.jsx)(Q.c7,{className:"mb-3",children:(0,s.jsx)(Q.L3,{className:"truncate text-sm font-semibold text-gray-900",children:e.title})}),(0,s.jsx)("div",{className:"mb-3 flex items-center justify-end",children:j&&(0,s.jsxs)(c.$,{variant:"outline",size:"sm",className:"h-8 gap-1 text-xs",onClick:()=>window.open(j,"_blank"),children:[(0,s.jsx)(G.A,{className:"h-3 w-3"}),"Open"]})}
1),j?(0,s.jsx)("video",{src:j,controls:!0,autoPlay:!0,playsInline:!0,className:"h-[70vh] w-full rounded-md bg-black object-contain"}):(0,s.jsx)("div",{className:"flex h-52 items-center justify-center rounded-md border border-gray-200 bg-gray-50 text-sm text-gray-500",children:"Video unavailable"})]})})]})}var te=a(45664);function tt({id:e,data:t,onAddArtifact:a,onDeleteBoard:l,onSettingsOpen:n}){let i=eJ(),{removeArtifact:o,updateArtifact:d,saveCanvas:c,artifacts:x}=(0,ep.y)(),[m,g]=(0,r.useState)(null),h=(0,r.useRef)(null),u=(0,r.useRef)(null),{board:p,stage:b}=t,f=(te.L[b]||{label:p.title,icon:e3.A}).icon,y=p.positioningMode||"freeform",j=(0,r.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),h.current={artifactId:t.id,startX:e.clientX,startY:e.clientY,initialX:t.x||0,initialY:t.y||0};let a=e=>{if(!h.current)return;let t=e.clientX-h.current.startX,a=e.clientY-h.current.startY;d(h.current.artifactId,{x:10*Math.round((h.current.initialX+t)/10),y:10*Math.round((h.current.initialY+a)/10)})},s=()=>{h.current=null,window.removeEventListener("pointermove",a),window.removeEventListener("pointerup",s),u.current&&clearTimeout(u.current),u.current=window.setTimeout(()=>c(),120)};window.addEventListener("pointermove",a),window.addEventListener("pointerup",s)},[d,c]),v=t.artifacts||[];return(0,s.jsx)("div",{className:"cursor-move",children:(0,s.jsxs)("div",{className:"bg-white border border-gray-200 rounded-[5px] shadow-md hover:shadow-lg transition-shadow min-w-[900px] w-fit min-h-[400px] relative",children:[(0,s.jsxs)("div",{className:"absolute top-2 left-2 right-2 z-10 flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-white/90 backdrop-blur-sm border border-gray-300 rounded-[5px] shadow-sm",children:[(0,s.jsx)(f,{className:"w-3 h-3 text-gray-700"}),(0,s.jsx)("span",{className:"text-xs font-semibold text-gray-700 uppercase tracking-tight",children:p.title})]}),i===e&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),a()},className:"flex items-center justify-center p-1.5 rounded-[4px] border border-gray-300 bg-white hover:bg-gray-50 text-gray-700 transition-all shadow-sm cursor-pointer",title:"Add artifacts",children:(0,s.jsx)(ei.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),l(p.title,v.length)},className:"flex items-center justify-center p-1.5 rounded-[4px] border border-red-200 bg-red-50 hover:bg-red-100 text-red-600 transition-all shadow-sm cursor-pointer",title:"Delete board",children:(0,s.jsx)(e1.A,{className:"h-3.5 w-3.5"})})]})]}),(0,s.jsx)("div",{className:"pt-12 pb-6 px-6",children:"freeform"===y?(0,s.jsx)("div",{className:"relative min-h-[260px] min-w-[900px]",children:v.map(e=>(0,s.jsx)("div",{className:"absolute",style:{left:e.x??24,top:e.y??0,width:462},onPointerDown:t=>j(t,e),children:(0,s.jsx)(e7,{artifact:e,linkConfirmOpen:m,onConfirmOpen:g,onSettingsOpen:n,onDelete:o})},e.id))}):(0,s.jsx)("div",{className:"grid gap-6 min-h-[260px]",style:{gridTemplateColumns:v.length>0?`repeat(${Math.min(v.length,4)}, 462px)`:"462px",width:"fit-content"},children:v.map(e=>(0,s.jsx)(e7,{artifact:e,linkConfirmOpen:m,onConfirmOpen:g,onSettingsOpen:n,onDelete:o},e.id))})})]})})}function ta({id:e,data:t,onAddAgent:a,onDeleteBoard:r,onOpenAgentSettings:l}){let n=eJ(),{removeArtifact:i}=(0,ep.y)(),o=t.artifacts||[];return(0,s.jsx)("div",{className:"cursor-move",children:(0,s.jsxs)("div",{className:"bg-white border border-gray-200 rounded-[5px] shadow-md hover:shadow-lg transition-shadow min-w-[700px] w-fit min-h-[300px] relative",children:[(0,s.jsxs)("div",{className:"absolute top-2 left-2 right-2 z-10 flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2.5 py-1 bg-white border border-gray-300 rounded-[5px] shadow-sm",children:[(0,s.jsx)(eg.A,{className:"w-3 h-3 text-gray-700"}),(0,s.jsx)("span",{className:"text-xs font-semibold text-gray-700 uppercase tracking-tight",children:"Agent Board"})]}),n===e&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),a()},className:"flex items-center justify-center p-1.5 rounded-[4px] border border-gray-300 bg-white hover:bg-gray-50 text-gray-700 transition-all shadow-sm cursor-pointer",title:"Add agents",children:(0,s.jsx)(ei.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),r("Agent Board",o.length)},className:"flex items-center justify-center p-1.5 rounded-[4px] border border-red-200 bg-red-50 hover:bg-red-100 text-red-600 transition-all shadow-sm cursor-pointer",title:"Delete board",children:(0,s.jsx)(e1.A,{className:"h-3.5 w-3.5"})})]})]}),(0,s.jsx)("div",{className:"pt-12 pb-6 px-6",children:(0,s.jsx)("div",{className:"flex flex-wrap gap-4 min-h-[200px]",style:{maxWidth:"900px"},children:0===o.length?(0,s.jsx)("div",{className:"w-full flex items-center justify-center text-gray-400 text-sm py-8",children:(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)(eg.A,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),(0,s.jsx)("p",{children:"Add agents to organize your multi-agent system"})]})}):o.map(e=>(0,s.jsx)(e5,{agent:{id:e.id,slug:e.metadata?.agentSlug||e.title,name:e.title,de
1scription:e.metadata?.description,avatarUrl:e.thumbnailUrl,modelId:e.metadata?.modelId,status:e.metadata?.status||"active",linkedKnowledgeCount:e.metadata?.knowledgeCount,linkedToolCount:e.metadata?.toolCount},onOpenModal:()=>l(e.metadata?.agentSlug),onOpenBuilder:()=>window.open(`/agent-builder/${e.metadata?.agentSlug}`,"_blank"),onRemove:()=>i(e.id)},e.id))})})]})})}function ts(e){if(!e)return null;if(e.includes("/node_documents/")){let t=e.split("/node_documents/")[1];return`/api/secure-image?bucket=node_documents&path=${encodeURIComponent(t)}`}return e.startsWith("/api/secure-image"),e}let tr={scheduled:"bg-blue-500",published:"bg-green-500",failed:"bg-red-500",draft:"bg-gray-400",deleted:"bg-gray-300"},tl=(0,r.memo)(function({post:e,onClick:t,onSettingsOpen:a}){let l=r.useMemo(()=>ts(e.thumbnailUrl||e.mediaUrls?.[0]),[e.thumbnailUrl,e.mediaUrls]),n=new Date(e.scheduledAtUtc).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});return(0,s.jsxs)("div",{className:"relative bg-white border border-gray-200 rounded cursor-pointer hover:bg-gray-50 group",onClick:t,children:[l&&(0,s.jsx)("img",{src:l,alt:"",className:"w-full rounded-t",loading:"lazy"}),(0,s.jsxs)("div",{className:"p-1.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1 mb-0.5",children:[(0,s.jsx)("span",{className:(0,eE.cn)("w-1.5 h-1.5 rounded-full shrink-0",tr[e.status]||tr.draft)}),(0,s.jsx)("span",{className:"text-[9px] text-gray-400",children:n})]}),(0,s.jsx)("p",{className:"text-[10px] text-gray-600 line-clamp-2 leading-tight",children:e.title||"Untitled"}),e.tags&&e.tags.length>0&&(0,s.jsx)("div",{className:"flex flex-wrap gap-0.5 mt-1",children:e.tags.map(e=>(0,s.jsx)("span",{className:"inline-block text-[8px] leading-[14px] text-gray-900 bg-white border border-gray-300 rounded-[5px] px-1 shadow-[0_1px_2px_rgba(0,0,0,0.05)]",children:e},e))})]}),e.knowledgeItemId&&a&&(0,s.jsx)("div",{className:"absolute top-1 right-1 opacity-0 group-hover:opacity-100 transition-opacity z-20",children:(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),a(e)},className:"p-1 bg-white border border-gray-200 rounded shadow-sm hover:bg-gray-50 transition-all",title:"Knowledge Settings",children:(0,s.jsx)(eK.A,{className:"w-3 h-3 text-gray-600"})})})]})}),tn=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],ti=(0,r.memo)(function({day:e,onPostClick:t,onPostSettingsOpen:a}){let r=new Date(e.dateKey+"T12:00:00");return(0,s.jsxs)("div",{className:(0,eE.cn)("flex-1 min-w-0 flex flex-col",e.isPast&&"opacity-50"),children:[(0,s.jsxs)("div",{className:(0,eE.cn)("py-2 text-center",e.isToday&&"bg-gray-50"),children:[(0,s.jsx)("div",{className:"text-[10px] font-medium text-gray-400 uppercase",children:tn[e.dayOfWeek]}),(0,s.jsx)("div",{className:(0,eE.cn)("text-sm font-medium",e.isToday?"text-gray-900":"text-gray-500"),children:r.getDate()})]}),(0,s.jsx)("div",{className:"flex-1 p-2 space-y-2 overflow-y-auto max-h-[280px]",children:0===e.posts.length?(0,s.jsx)("div",{className:"h-24 flex items-center justify-center text-gray-300 text-[10px]",children:"â"}):e.posts.map(e=>(0,s.jsx)(tl,{post:e,onClick:()=>t?.(e),onSettingsOpen:a},e.id))})]})}),to={scheduled:"Scheduled",published:"Published",failed:"Failed",draft:"Draft",deleted:"Deleted"};function td({post:e,onClose:t,onDelete:a}){let[n,i]=(0,r.useState)(!1),o=r.useMemo(()=>ts(e.thumbnailUrl||e.mediaUrls?.[0]),[e.thumbnailUrl,e.mediaUrls]),d=async()=>{a&&!n&&(i(!0),await a(),i(!1))};return(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",onClick:t,children:(0,s.jsxs)("div",{className:"bg-white border border-gray-200 rounded max-w-md w-full mx-4 max-h-[80vh] overflow-y-auto",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-gray-200",children:[(0,s.jsx)("span",{className:"text-xs text-gray-500",children:to[e.status]||"Post"}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[a&&(0,s.jsx)(c.$,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-gray-400 hover:text-red-500",onClick:d,disabled:n,children:n?(0,s.jsx)(l.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(e1.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(c.$,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-gray-400",onClick:t,children:(0,s.jsx)(z.A,{className:"h-3.5 w-3.5"})})]})]}),o&&(0,s.jsx)("div",{className:"aspect-video w-full overflow-hidden bg-gray-100",children:(0,s.jsx)("img",{src:o,alt:"",className:"w-full h-full object-cover"})}),(0,s.jsxs)("div",{className:"p-3 space-y-3",children:[(0,s.jsx)("h2",{className:"text-sm font-medium text-gray-900",children:e.title||"Untitled Post"}),e.summaryPreview&&(0,s.jsx)("p",{className:"text-xs text-gray-500 whitespace-pre-wrap line-clamp-6",children:e.summaryPreview}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3 text-xs pt-2 border-t border-gray-200",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-gray-400 text-[10px] uppercase mb-0.5",children:"Scheduled"}),(0,s.jsx)("div",{className:"text-gray-600",children:new Date(e.scheduledAtUtc).toLocaleStr
1ing()})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-gray-400 text-[10px] uppercase mb-0.5",children:"Platforms"}),(0,s.jsx)("div",{className:"text-gray-600 capitalize",children:e.platforms.join(", ")||"None"})]})]}),e.mediaUrls&&e.mediaUrls.length>1&&(0,s.jsxs)("div",{className:"pt-2 border-t border-gray-200",children:[(0,s.jsxs)("div",{className:"text-gray-400 text-[10px] uppercase mb-1",children:["Media (",e.mediaUrls.length,")"]}),(0,s.jsx)("div",{className:"grid grid-cols-4 gap-1",children:e.mediaUrls.slice(0,4).map((e,t)=>(0,s.jsx)("div",{className:"aspect-square rounded overflow-hidden bg-gray-100",children:(0,s.jsx)("img",{src:ts(e)||e,alt:"",className:"w-full h-full object-cover"})},t))})]})]})]})})}function tc({id:e,data:t,onDelete:a,userId:n}){let{calendarId:i,calendarSlug:o,knowledgeTableId:d}=t,{loading:x,days:m,stats:g,refetch:h}=function({calendarId:e,calendarSlug:t,knowledgeTableId:a}){let[s,l]=(0,r.useState)(!0),[n,i]=(0,r.useState)([]),[o,d]=(0,r.useState)({total:0,scheduled:0,published:0,failed:0}),c=(0,r.useRef)(!1);(0,r.useRef)(0);let x=(0,r.useCallback)(async()=>{try{if(l(!0),t||e){let a=new URLSearchParams;e&&a.set("id",e),t&&a.set("slug",t);let s=await fetch(`/api/social-calendar?${a.toString()}`);if(!s.ok)return void l(!1);let r=await s.json(),n=r.calendar_data||r;if(n?.days){let e=Object.values(n.days).sort((e,t)=>e.dateKey.localeCompare(t.dateKey));i(e);let t=e.flatMap(e=>e.posts);d({total:t.length,scheduled:t.filter(e=>"scheduled"===e.status).length,published:t.filter(e=>"published"===e.status).length,failed:t.filter(e=>"failed"===e.status).length})}l(!1);return}let s=new URLSearchParams;a&&s.set("tableId",a),s.set("origin","social_post_scheduler");let r=await fetch(`/api/social-calendar/posts?${s.toString()}`);if(!r.ok)return void l(!1);let n=(await r.json()).posts||[],o=new Date,c=o.toISOString().split("T")[0],x={},m=new Date(o);m.setDate(o.getDate()-o.getDay());for(let e=0;e<7;e++){let t=new Date(m);t.setDate(t.getDate()+e);let a=t.toISOString().split("T")[0];x[a]={dateKey:a,label:t.toLocaleDateString("en-US",{month:"short",day:"numeric"}),dayOfWeek:t.getDay(),isToday:a===c,isPast:a<c,isFuture:a>c,posts:[]}}for(let e of n){let t=e.scheduledAtUtc?.split("T")[0];t&&x[t]&&x[t].posts.push(e)}Object.values(x).forEach(e=>{e.posts.sort((e,t)=>new Date(e.scheduledAtUtc).getTime()-new Date(t.scheduledAtUtc).getTime())}),i(Object.values(x).sort((e,t)=>e.dateKey.localeCompare(t.dateKey))),d({total:n.length,scheduled:n.filter(e=>"scheduled"===e.status).length,published:n.filter(e=>"published"===e.status).length,failed:n.filter(e=>"failed"===e.status).length})}catch(e){console.error("[useSocialCalendarData] Error:",e)}finally{l(!1)}},[e,t,a]);return(0,r.useEffect)(()=>{c.current||(c.current=!0,x())},[]),{loading:s,days:n,stats:o,refetch:(0,r.useCallback)(()=>{x()},[x])}}({calendarId:i,calendarSlug:o,knowledgeTableId:d}),[u,p]=(0,r.useState)(null),[b,f]=(0,r.useState)({open:!1,knowledgeItemId:null,initialData:null}),y=(0,r.useCallback)(async e=>{try{(await fetch(`/api/knowledge/delete?id=${e}`,{method:"DELETE"})).ok&&(p(null),h())}catch(e){console.error("[SocialCalendarBoard] Delete failed:",e)}},[h]),j=(0,r.useCallback)(e=>{if(!e.knowledgeItemId)return;let t=e._knowledgeRow;f({open:!0,knowledgeItemId:e.knowledgeItemId,initialData:t?{id:e.knowledgeItemId,...t}:{id:e.knowledgeItemId,file_name:e.title||"Untitled Post",storage_path:e.thumbnailUrl||e.mediaUrls?.[0],source_type:"document",metadata:{tags:e.tags},item_count:1}})},[]);return(0,s.jsxs)("div",{className:"cursor-move",children:[(0,s.jsxs)("div",{className:"bg-white border border-gray-200 rounded w-[1050px]",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-gray-200",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(eh.A,{className:"w-4 h-4 text-gray-400"}),(0,s.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Social Calendar"}),(0,s.jsxs)("span",{className:"text-xs text-gray-400",children:[g.total," posts"]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[o&&(0,s.jsx)(c.$,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>window.open(`/f/social-calendar/${o}`,"_blank"),children:(0,s.jsx)(e0.A,{className:"h-3.5 w-3.5 text-gray-400"})}),a&&(0,s.jsx)(c.$,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-gray-400 hover:text-red-500",onClick:a,children:(0,s.jsx)(e1.A,{className:"h-3.5 w-3.5"})})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-4 px-3 py-1.5 border-b border-gray-200 text-[10px] text-gray-400",children:[(0,s.jsxs)("span",{className:"flex items-center gap-1",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-500"}),g.scheduled," scheduled"]}),(0,s.jsxs)("span",{className:"flex items-center gap-1",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500"}),g.published," published"]}),(0,s.jsxs)("span",{className:"flex items-center gap-1",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-red-500"}),g.failed," failed"]})]}),x?(0,s.jsx)("div",{className:"flex items-center justify-center h-[340px]",children:(0,s.jsx)(l.A,{className:"h-5 w-5 animate-spin text-gray-300"})}):0===m.length?(0,s.jsx)("div",{className:"flex items-center justify-center h-[340px] text-gray-300 text-sm",children:"No posts"}):(0,s.jsx)("div",{className:"grid grid-cols-7 divide-x divide-gray-200",children:m.map(e=>(0,s.jsx)(ti,{day:e,onPostClick:p,onPostSettingsOpen:j},e.dateKey))})]}),u&&(0,s.jsx)(td,{post:u,onClose:()=>p(null),onDelete:()=>y(u.knowledgeItemId||u.id)}),(0,s.jsx)(eH,{knowledgeItemId:b.knowledgeItemId,open:b.open,onOpenChange:e=>f(t=>({...t,open:e})),userId:n||void 0,onSave:()=>h(),initialData:b.initialData},b.knowledgeItemId||"none")]})}var tx=a(51482),tm=a(67486),tg=a(81629),th=a(7935),tu=a(71680),tp=a(58407),tb=a(39156),tf=a(5881),ty=a(17234),tj=a(78942),tv=a(55753),tw=a(34103),tN=a(21291),tC=a(12784),tk=a(85280),tA=a(19915);let tI=["hsl(220, 13%, 18%)","hsl(220, 10%, 40%)","hsl(220, 8%, 58%)","hsl(220, 6%, 72%)","hsl(220, 5%, 84%)"],tS=[{id:"comparison",label:"LLM vs Other",icon:tg.A},{id:"llm",label:"LLM Only",icon:th.A},{id:"all",label:"All Traffic",icon:F.A},{id:"platforms",label:"Platforms",icon:eu.A}];function t_(){return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-100 p-3 animate-pulse space-y-2",children:[(0,s.jsx)("div",{className:"h-3 bg-gray-100 rounded w-1/2"}),(0,s.jsx)("div",{className:"h-6 bg-gray-50 rounded w-2/3"})]})}function tP({label:e,value:t,sub:a,icon:r}){return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 bg-white p-3 space-y-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] text-gray-500",children:[(0,s.jsx)(r,{className:"h-3 w-3"}),e]}),(0,s.jsx)("div",{className:"text-lg font-bold text-gray-900 tabular-nums",children:"number"==typeof t?t.toLocaleStr
1ing():t}),a&&(0,s.jsx)("div",{className:"text-[10px] text-gray-400",children:a})]})}function tT({loading:e,saving:t,snapshot:a,propertyLabel:n,provider:i}){let[o,d]=(0,r.useState)("comparison");if(e||t)return(0,s.jsxs)("div",{className:"p-4 space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 pb-2",children:[(0,s.jsx)(l.A,{className:"h-3.5 w-3.5 animate-spin text-gray-300"}),(0,s.jsx)("span",{className:"text-xs text-gray-400",children:t?`Fetching ${i.label} baseline...`:`Loading data for ${n}...`})]}),(0,s.jsx)("div",{className:"grid grid-cols-4 gap-3",children:Array.from({length:4}).map((e,t)=>(0,s.jsx)(t_,{},t))}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,s.jsx)("div",{className:"h-[180px] bg-gray-50 rounded-lg animate-pulse"}),(0,s.jsx)("div",{className:"h-[180px] bg-gray-50 rounded-lg animate-pulse"})]})]});if(!a)return(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-[280px] gap-2 text-center",children:[(0,s.jsx)("p",{className:"text-xs text-gray-300",children:"No baseline data yet."}),(0,s.jsx)("p",{className:"text-[11px] text-gray-300",children:"Click the refresh icon or re-save configuration to fetch data."})]});if(a.meta_metrics){let e=a.meta_metrics;return(0,s.jsxs)("div",{className:"p-4 space-y-4 nodrag nowheel",onPointerDown:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[(0,s.jsx)(tP,{icon:eu.A,label:"Spend",value:`$${e.spend.toFixed(2)}`}),(0,s.jsx)(tP,{icon:th.A,label:"Impressions",value:e.impressions.toLocaleString()}),(0,s.jsx)(tP,{icon:tu.A,label:"Clicks",value:e.clicks.toLocaleString()}),(0,s.jsx)(tP,{icon:tp.A,label:"CTR",value:`${e.ctr.toFixed(2)}%`})]}),(0,s.jsxs)("div",{className:"text-[10px] text-gray-300 text-right pt-1 border-t border-gray-100",children:["Snapshot: ",new Date(a.snapshot_timestamp).toLocaleString()," \xb7 ",a.dateRange??"â"," \xb7 ",a.propertyName??"Meta Ads"]})]})}let{overall_llm:c,non_llm:x,platform_breakdown:m}=a,g=c.sessions+(x?.sessions||0),h=g>0?(c.sessions/g*100).toFixed(1):"0";return(0,s.jsxs)("div",{className:"p-4 space-y-4 nodrag nowheel",onPointerDown:e=>e.stopPropagation(),children:[(0,s.jsx)("div",{className:"flex items-center gap-1",children:tS.map(e=>{let t=o===e.id;return(0,s.jsxs)("button",{onClick:()=>d(e.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] font-medium transition-all ${t?"bg-gray-900 text-white shadow-sm":"bg-gray-50 text-gray-500 hover:bg-gray-100 hover:text-gray-700"}`,children:[(0,s.jsx)(e.icon,{className:"h-3 w-3"}),e.label]},e.id)})}),(0,s.jsx)(t$,{view:o,snapshot:a,llmPct:h,totalSessions:g}),(0,s.jsx)(tM,{view:o,snapshot:a,provider:i,llmPct:h,totalSessions:g}),(0,s.jsxs)("div",{className:"text-[10px] text-gray-300 text-right pt-1 border-t border-gray-100",children:["Snapshot: ",new Date(a.snapshot_timestamp).toLocaleString()," \xb7 ",a.dateRange??"â"," \xb7 ",a.propertyName??"Meta Ads"]})]})}function t$({view:e,snapshot:t,llmPct:a,totalSessions:r}){let{overall_llm:l,non_llm:n}=t;if("llm"===e)return(0,s.jsxs)("div",{className:"grid grid-cols-4 gap-3",children:[(0,s.jsx)(tP,{icon:th.A,label:"LLM Sessions",value:l.sessions,sub:`${a}% of total`}),(0,s.jsx)(tP,{icon:tb.A,label:"Engaged Sessions",value:l.engaged_sessions}),(0,s.jsx)(tP,{icon:tb.A,label:"Engagement Rate",value:`${l.engagement_rate}%`}),(0,s.jsx)(tP,{icon:tu.A,label:"Conversions",value:l.conversions})]});if("all"===e){let e={sessions:r,engaged_sessions:l.engaged_sessions+(n?.engaged_sessions||0),conversions:l.conversions+(n?.conversions||0),engagement_rate:r>0?Math.round((l.engaged_sessions+(n?.engaged_sessions||0))/r*1e4)/100:0};return(0,s.jsxs)("div",{className:"grid grid-cols-4 gap-3",children:[(0,s.jsx)(tP,{icon:eg.A,label:"Total Sessions",value:e.sessions,sub:`${t.total_sources_analyzed} sources`}),(0,s.jsx)(tP,{icon:tb.A,label:"Engaged Sessions",value:e.engaged_sessions}),(0,s.jsx)(tP,{icon:tb.A,label:"Engagement Rate",value:`${e.engagement_rate}%`}),(0,s.jsx)(tP,{icon:tu.A,label:"Total Conversions",value:e.conversions})]})}if("platforms"===e){let e=[...t.platform_breakdown].sort((e,t)=>
1t.sessions-e.sessions).slice(0,4);return(0,s.jsxs)("div",{className:"grid grid-cols-4 gap-3",children:[e.map(e=>(0,s.jsx)(tP,{icon:eu.A,label:e.platform,value:e.sessions,sub:e.sessions>0?`${(e.engaged_sessions/e.sessions*100).toFixed(1)}% engaged`:void 0},e.platform)),e.length<4&&Array.from({length:4-e.length}).map((e,t)=>(0,s.jsx)("div",{className:"rounded-lg border border-dashed border-gray-100 p-3"},`empty-${t}`))]})}return(0,s.jsxs)("div",{className:"grid grid-cols-4 gap-3",children:[(0,s.jsx)(tP,{icon:th.A,label:"LLM Sessions",value:l.sessions,sub:`${a}% of total traffic`}),(0,s.jsx)(tP,{icon:eg.A,label:"Total Sessions",value:r,sub:`${t.total_sources_analyzed} sources`}),(0,s.jsx)(tP,{icon:tb.A,label:"LLM Engagement",value:`${l.engagement_rate}%`,sub:n?`vs ${n.engagement_rate}% non-LLM`:void 0}),(0,s.jsx)(tP,{icon:tu.A,label:"LLM Conversions",value:l.conversions,sub:n?`vs ${n.conversions.toLocaleString()} non-LLM`:void 0})]})}function tM({view:e,snapshot:t,provider:a,llmPct:r,totalSessions:l}){let{overall_llm:n,non_llm:i,platform_breakdown:o}=t;return"llm"===e?(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsx)(tE,{platforms:o,providerPlatforms:a.platforms}),(0,s.jsx)(tD,{metrics:n})]}):"all"===e?(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsx)(tE,{platforms:o,providerPlatforms:a.platforms}),(0,s.jsx)(tL,{llm:n.sessions,nonLlm:i?.sessions||0})]}):"platforms"===e?(0,s.jsx)("div",{className:"grid grid-cols-1 gap-4",children:(0,s.jsx)(tE,{platforms:o,providerPlatforms:a.platforms,fullWidth:!0})}):(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsx)(tE,{platforms:o,providerPlatforms:a.platforms}),(0,s.jsx)(tL,{llm:n.sessions,nonLlm:i?.sessions||0})]})}function tE({platforms:e,providerPlatforms:t,fullWidth:a}){let l=(0,r.useMemo)(()=>[...e].sort((e,t)=>t.sessions-e.sessions),[e]),n=(0,r.useMemo)(()=>{let e={sessions:{label:"Sessions",color:tI[0]}};return l.forEach((a,s)=>{e[a.platform]={label:t?.[a.platform]?.label||a.platform,color:tI[s%tI.length]}}),e},[l,t]),i=(0,r.useMemo)(()=>l.map((e,a)=>({name:t?.[e.platform]?.label||e.platform,sessions:e.sessions,engagement:e.engaged_sessions>0&&e.sessions>0?`${(e.engaged_sessions/e.sessions*100).toFixed(1)}%`:"â",fill:tI[a%tI.length]})),[l,t]);return i.length?(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 bg-white p-3 space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-[11px] font-semibold text-gray-600",children:"Platform Sessions"}),(0,s.jsx)("span",{className:"text-[10px] text-gray-400",children:"Engagement"})]}),(0,s.jsx)(tA.at,{config:n,className:`aspect-auto w-full ${a?"h-[200px]":"h-[170px]"}`,children:(0,s.jsxs)(tf.E,{data:i,layout:"vertical",margin:{left:0,right:40,top:4,bottom:4},children:[(0,s.jsx)(ty.d,{horizontal:!1,strokeDasharray:"3 3",stroke:"#f0f0f0"}),(0,s.jsx)(tj.h,{dataKey:"name",type:"category",width:80,tick:{fontSize:11,fill:"#6b7280"},axisLine:!1,tickLine:!1}),(0,s.jsx)(tv.W,{type:"number",hide:!0}),(0,s.jsx)(tA.II,{content:(0,s.jsx)(tA.Nt,{indicator:"line"})}),(0,s.jsx)(tw.y,{dataKey:"sessions",radius:[0,4,4,0],barSize:18,children:i.map((e,t)=>(0,s.jsx)(tN.f,{fill:e.fill},t))})]})})]}):null}function tL({llm:e,nonLlm:t}){let a=e+t,l=a>0?(e/a*100).toFixed(1):"0",n=(0,r.useMemo)(()=>[{name:"LLM Traffic",value:e,fill:tI[0]},{name:"Other Traffic",value:t,fill:tI[3]}],[e,t]),i={llm:{label:"LLM Traffic",color:tI[0]},other:{label:"Other Traffic",color:tI[3]}};return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 bg-white p-3 space-y-2",children:[(0,s.jsx)("span",{className:"text-[11px] font-semibold text-gray-600",children:"LLM vs Other Traffic"}),(0,s.jsx)(tA.at,{config:i,className:"aspect-auto h-[170px] w-full",children:(0,s.jsxs)(tC.r,{children:[(0,s.jsx)(tA.II,{content:(0,s.jsx)(tA.Nt,{hideLabel:!0})}),(0,s.jsx)(tk.F,{data:n,dataKey:"value",nameKey:"name",innerRadius:50,outerRadius:70,strokeWidth:2,stroke:"#fff",children:n.map((e,t)=>(0,s.jsx)(tN.f,{fill:e.fill},t))}),(0,s.jsxs)("text",{x:"50%",y:"48%",textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-900 text-xl font-bold",children:[l,"%"]}),(0,s.jsx)("text",{x:"50%",y:"60%",textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-400 text-[10px]",children:"LLM share"})]})})]})}function tD({metrics:e}){let t=(0,r.useMemo)(()=>[{name:"Sessions",value:e.sessions,fill:tI[0]},{name:"Engaged",value:e.engaged_sessions,fill:tI[1]},{name:"Conversions",value:e.conversions,fill:tI[2]}],[e]),a={sessions:{label:"Sessions",color:tI[0]},engaged:{label:"Engaged",color:tI[1]},conversions:{label:"Conversions",color:tI[2]}};return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 bg-white p-3 space-y-2",children:[(0,s.jsx)("span",{className:"text-[11px] font-semibold text-gray-600",children:"LLM Metrics Breakdown"}),(0,s.jsx)(tA.at,{config:a,className:"aspect-auto h-[170px] w-full",children:(0,s.jsxs)(tf.E,{data:t,margin:{left:0,right:12,top:4,bottom:4},children:[(0,s.jsx)(ty.d,{vertical:!1,strokeDasharray:"3 3",stroke:"#f0f0f0"}),(0,s.jsx)(tv.W,{dataKey:"name",tick:{fontSize:11,fill:"#6b7280"}
1,axisLine:!1,tickLine:!1}),(0,s.jsx)(tj.h,{hide:!0}),(0,s.jsx)(tA.II,{content:(0,s.jsx)(tA.Nt,{})}),(0,s.jsx)(tw.y,{dataKey:"value",radius:[4,4,0,0],barSize:32,children:t.map((e,t)=>(0,s.jsx)(tN.f,{fill:e.fill},t))})]})})]})}var tF=a(11420),tO=a(20081);function tR({id:e,platforms:t}){let a=t?.[e];return a?(0,s.jsxs)("div",{className:"flex items-center px-3 py-2 rounded-[5px] border border-gray-200 bg-white",children:[(0,s.jsx)("img",{src:a.logo,alt:a.label,className:"w-4 h-4 object-contain flex-shrink-0 mr-2.5"}),(0,s.jsx)("span",{className:"text-xs font-semibold text-gray-900",children:a.label})]}):null}function tU({open:e,metadata:t,userId:a,provider:n,onSave:i,onClose:o}){let d=(0,r.useRef)(n.seedConfig(t)),x=(0,r.useRef)(null),[m,g]=(0,r.useState)(d.current),[h,p]=(0,r.useState)(!1),[b,y]=(0,r.useState)(!1),[j,v]=(0,r.useState)(null),[w,N]=(0,r.useState)(!1),[C,k]=(0,r.useState)(!1),[A,I]=(0,r.useState)([]),S=(0,r.useRef)(!1);r.useEffect(()=>{if(e){let e=n.seedConfig(t);d.current=e,g(e),x.current={...e},v(null),k(!1),I([]),S.current=!1}},[e,t,n]);let _=()=>{let e=x.current;return!!e&&n.configsDiffer(d.current,e)},P=(0,r.useCallback)(e=>{!e&&_()?y(!0):e||o()},[o]),T=(0,r.useCallback)(async()=>{if(!S.current&&!C&&a){S.current=!0,N(!0);try{let e=await fetch(n.propertiesApiPath(a)),t=await e.json();if(!e.ok||t.error){v(null),k(!0);return}v({id:t.connectionId,name:t.connectionName});let s=t.properties||t.adAccounts;I((Array.isArray(s)?s:[]).map(e=>({propertyId:e.propertyId??e.account_id??e.id,displayName:e.displayName??e.name,account:e.account??e.id}))),k(!0)}catch{}finally{N(!1),S.current=!1}}},[a,C,n]),$=(0,r.useCallback)(e=>{let t={...d.current,propertyId:e.propertyId,propertyName:e.displayName,connectionId:j?.id};d.current=t,g(t)},[j?.id]),M=(0,r.useCallback)((e,t)=>{d.current={...d.current,[e]:t},g(a=>({...a,[e]:t}))},[]),E=(0,r.useCallback)(async()=>{let e=d.current;e.propertyId&&"pending"!==e.propertyId&&(p(!0),i(e))},[i]),L=!!(m.propertyId&&"pending"!==m.propertyId),D=n.extraConfigFields;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Q.lG,{open:e,onOpenChange:P,children:(0,s.jsxs)(Q.Cf,{className:"sm:max-w-lg",onPointerDown:e=>e.stopPropagation(),onInteractOutside:e=>{_()&&(e.preventDefault(),y(!0))},onEscapeKeyDown:e=>{_()&&(e.preventDefault(),y(!0))},children:[(0,s.jsxs)(Q.c7,{children:[(0,s.jsx)(Q.L3,{children:"Configure Analytics Board"}),(0,s.jsx)(Q.rr,{children:n.modalDescription})]}),(0,s.jsxs)("div",{className:"py-2 max-h-[60vh] overflow-y-auto nodrag nowheel space-y-4",children:[(0,s.jsx)("div",{className:"flex items-center gap-2",children:L?(0,s.jsxs)(u.E,{variant:"outline",className:"text-xs border-green-300 bg-green-50 text-green-700",children:[(0,s.jsx)(tF.A,{className:"h-3 w-3 mr-1"}),"Property Selected"]}):(0,s.jsxs)(u.E,{variant:"outline",className:"text-xs border-yellow-300 bg-yellow-50 text-yellow-700",children:[(0,s.jsx)(tO.A,{className:"h-3 w-3 mr-1"}),"Select Property"]})}),L&&(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e4.default,{src:n.logo,alt:n.label,width:16,height:16,className:"rounded"}),(0,s.jsx)("span",{className:"text-sm font-semibold text-gray-900",children:m.propertyName||m.propertyId})]}),(0,s.jsx)("p",{className:"text-xs text-gray-500",children:m.propertyId})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(f.J,{className:"text-xs font-semibold text-gray-900",children:n.propertyLabel}),!C&&!w&&(0,s.jsxs)(c.$,{size:"sm",variant:"outline",className:"w-full justify-between text-xs h-9",onClick:T,children:[(0,s.jsx)("span",{children:L?n.changeText:n.selectText}),(0,s.jsx)(eT.A,{className:"h-3 w-3 ml-2"})]}),w&&(0,s.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border border-gray-200 rounded-[5px] bg-gray-50",children:[(0,s.jsx)(l.A,{className:"h-3 w-3 animate-spin text-gray-400"}),(0,s.jsx)("span",{className:"text-xs text-gray-500",children:n.loadingText})]}),C&&!j&&(0,s.jsxs)("p",{className:"text-xs text-gray-500",children:[n.noConnectionText," Connect via ",(0,s.jsx)("a",{href:n.integrationsUrl,className:"text-blue-600 hover:text-blue-800 underline",children:"Integrations"}),"."]}),A.length>0&&(0,s.jsx)("div",{className:"max-h-40 overflow-y-auto border border-gray-200 rounded-[5px] bg-white",children:A.map(e=>(0,s.jsxs)("button",{onClick:()=>$(e),className:"w-full text-left px-3 py-2 hover:bg-gray-50 text-xs border-b border-gray-100 last:border-0"+(m.propertyId===e.propertyId?" bg-blue-50 border-blue-200":""),children:[(0,s.jsx)("span",{className:"font-semibold text-gray-900 block",children:e.displayName}),(0,s.jsxs)("span",{className:"text-gray-400 text-[10px]",children:[e.account," \xb7 ",e.propertyId]})]},e.propertyId))})]}),D&&(0,s.jsx)(D,{...m,onChange:M,readOnly:!1}),n.platforms&&m.breakdownPlatforms&&(0,s.jsxs)("div",{className:"space-y-2 pt-3 border-t border-gray-100",children:[(0,s.jsx)(f.J,{className:"text-xs font-semibold text-gray-900",children:"Tracked Platforms"}),(0,s.jsx)("div",{className:"space-y-1.5",children:(m.breakdownPlatforms||n.defaultPlatforms||[]).map(e=>(0,s.jsx)(tR,{id:e,platforms:n.platforms},e))})]})]}),(0,s.jsxs)(Q.Es,{children:[(0,s.jsx)(c.$,{variant:"outline",onClick:()=>P(!1),children:"Cancel"}),(0,s.jsx)(c.$,{onClick:E,disabled:!L||h,children:h?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(l.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"}),"Saving..."]}):"Save Configuration"})]})]})}),(0,s.jsx)(eA.Lt,{open:b,onOpenChange:y,children:(0,s.jsxs)(eA.EO,{children:[(0,s.jsxs)(eA.wd,{children:[(0,s.jsx)(eA.r7,{children:"Discard unsaved changes?"}),(0,s.jsx)(eA.$v,{children:"You have unsaved configuration changes. Close without saving?"})]}),(0,s.jsxs)(eA.ck,{children:[(0,s.jsx)(eA.Zr,{children:"Keep Editing"}),(0,s.jsx)(eA.Rx,{onClick:()=>{y(!1),o()},children:"Discard Changes"})]})]})})]})}var tz=a(12419);let tB=["chatgpt","perplexity","gemini","claude","copilot"],tH={id:"google-analytics",label:"GA4",logo:"/GA4-logo.webp",origin:"google-analytics",integrationsUrl:"/integrations",propertyLabel:"GA4 Property",selectText:"Select a GA4 property",changeText:"Change GA4 property",loadingText:"Loading GA4 properties...",noConnectionText:"No active GA4 connection.",modalDescription:"Select a GA4 property and configure LLM traffic tracking.",emptyTitle:"No GA4 property configured",emptySubtitle:"Connect a Google Analytics property to view LLM traffic data.",seedConfig:e=>({propertyId:e.propertyId,connectionId:e.connectionId,propertyName:e.propertyName,dateRange:e.dateRange||"last_30d",compareNonLlm:!1!==e.compareNonLlm,breakdownPlatforms:e.breakdownPlatforms||[...tB]}),configsDiffer:(e,t)=>e.propertyId!==t.propertyId||e.connectionId!==t.connectionId||e.propertyName!==t.propertyName||e.dateRange!==t.dateRange||e.compareNonLlm!==t.compareNonLlm||JSON.stringify(e.breakdownPlatforms)!==JSON.stringify(t.breakdownPlatforms),propertiesApiPath:e=>`/api/providers/google-analytics/properties?userId=${encodeURIComponent(e)}`,fetchBaselineApiPath:"/api/analytics-board/fetch-baseline",extraConfigFields:tz.w,platforms:{chatgpt:{label:"ChatGPT",logo:"/openai-logo.svg"},perplexity:{label:"Perplexity",logo:"/perplexity-color.svg"},gemini:{label:"Gemini",logo:"/gemini.png"},claude:{label:"Claude",logo:"/claude-logo.svg"},copilot:{label:"Copilot",logo:"/copiklot.png"}},defaultPlatforms:tB},tW={id:"meta-ads",label:"Meta Ads",logo:"/2021_Facebook_icon.svg",origin:"meta-ads",integrationsUrl:"/integrations",propertyLabel:"Ad Account",selectText:"Select an ad account",changeText:"Change ad account",loadingText:"Loading ad accounts...",noConnectionText:"No active Meta Ads connection.",modalDescription:"Select an ad account and date range to fetch Meta Ads insights.",emptyTitle:"No ad account configured",emptySubtitle:"Connect Meta Ads in Integrations to view spend and performance.",seedConfig:e=>({propertyId:e.propertyId||e.accountId,connectionId:e.connectionId,propertyName:e.propertyName||e.accountName,dateRange:e.dateRange||"last_30d",origin:"meta-ads"}),configsDiffer:(e,t)=>e.propertyId!==t.propertyId||e.connectionId!==t.connectionId||e.propertyName!==t.propertyName||e.dateRange!==t.dateRange,propertiesApiPath:()=>"/api/providers/meta-ads/properties",fetchBaselineApiPath:"/api/analytics-board/fetch-baseline"},tX={"google-analytics":tH,"meta-ads":tW},tK=[tH,tW],tV=[{id:"mixpanel",label:"Mixpanel",logo:"/mixpanel-logo.svg"},{id:"plausible",label:"Plausible",logo:"/plausible-logo.svg"},{id:"adobe-analytics",label:"Adobe Analytics",logo:"/adobe-logo.svg"}];function tG({onSelect:e}
1){let[t,a]=(0,r.useState)(!1);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-[320px] gap-4 px-6 nodrag nowheel",onPointerDown:e=>e.stopPropagation(),children:[(0,s.jsx)("div",{className:"flex items-center justify-center w-8 h-8 rounded-[5px] border border-gray-200 bg-white",children:(0,s.jsx)(eu.A,{className:"h-4 w-4 text-gray-900"})}),(0,s.jsxs)("div",{className:"text-center space-y-1",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-gray-900",children:"Analytics Reporting"}),(0,s.jsx)("p",{className:"text-xs text-gray-400 max-w-[280px]",children:"Connect an analytics provider to track LLM traffic and engagement on this board."})]}),(0,s.jsxs)(c.$,{size:"sm",variant:"outline",className:"text-xs h-7 max-w-[225px] w-full gap-1.5",onClick:e=>{e.stopPropagation(),a(!0)},children:[(0,s.jsx)(eu.A,{className:"h-3 w-3"}),"Connect Analytics"]})]}),(0,s.jsx)(Q.lG,{open:t,onOpenChange:a,children:(0,s.jsxs)(Q.Cf,{className:"sm:max-w-md",onPointerDown:e=>e.stopPropagation(),children:[(0,s.jsxs)(Q.c7,{children:[(0,s.jsx)(Q.L3,{children:"Choose Analytics Provider"}),(0,s.jsx)(Q.rr,{children:"Select a data source for this board. More integrations coming soon."})]}),(0,s.jsxs)("div",{className:"py-3 space-y-3",children:[tK.map(t=>(0,s.jsxs)("button",{onClick:()=>{a(!1),e(t)},className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg border border-gray-200 bg-white hover:bg-gray-50 hover:border-gray-300 transition-all text-left",children:[(0,s.jsx)(e4.default,{src:t.logo,alt:t.label,width:24,height:24,className:"rounded flex-shrink-0"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-gray-900",children:t.label}),(0,s.jsx)("p",{className:"text-xs text-gray-400",children:t.modalDescription})]})]},t.id)),tV.map(e=>(0,s.jsxs)("div",{className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg border border-gray-100 bg-gray-50 opacity-50 cursor-not-allowed",children:[(0,s.jsx)("span",{className:"w-6 h-6 bg-gray-200 rounded flex items-center justify-center text-gray-500 text-[10px] font-bold flex-shrink-0",children:e.label.charAt(0)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-gray-500",children:e.label}),(0,s.jsx)("p",{className:"text-xs text-gray-300",children:"Coming soon"})]})]},e.id))]})]})})]})}function tY(e){return e.includes(",")||e.includes('"')?`"${e.replace(/"/g,'""')}"`:e}function tJ({id:e,data:t,onDelete:a}){let{updateBoard:l,userId:n}=(0,ep.y)(),i=t.board,o=i.metadata||{},d=o.propertyId,x=o.propertyName,m=!!(d&&"pending"!==d),g=(0,r.useMemo)(()=>o.origin?tX[o.origin||"google-analytics"]||tH:null,[o.origin]),h=(0,r.useRef)(g);h.current=g;let[u,p]=(0,r.useState)(!1),[b,f]=(0,r.useState)(!1),[y,j]=(0,r.useState)(!1),[v,w]=(0,r.useState)(null),N=(0,r.useRef)(!1),C=(0,r.useCallback)(async(e,t)=>{let a=e||h.current,s=t||d;if(a&&s&&"pending"!==s&&n){f(!0);try{let e=a.seedConfig({...o,propertyId:s}),t=await fetch(a.fetchBaselineApiPath,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=await t.json();r.success&&r.snapshot&&w(r.snapshot)}catch(e){console.error(`[AnalyticsBoard][${a.id}] Baseline fetch failed:`,e)}finally{f(!1)}}},[d,n,o]);(0,r.useEffect)(()=>{m&&!N.current&&!v&&g&&(N.current=!0,C())},[m,C,v,g]);let k=(0,r.useCallback)(t=>{h.current=t,l(e,{metadata:{...o,origin:t.origin}}),p(!0)},[e,o,l]),A=(0,r.useCallback)(async t=>{let a=h.current;if(a){j(!0),l(e,{metadata:{...o,...t,origin:a.origin}}),p(!1);try{let e=await fetch(a.fetchBaselineApiPath,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),s=await e.json();s.success&&s.snapshot&&w(s.snapshot)}catch(e){console.error(`[AnalyticsBoard][${a.id}] Baseline fetch failed:`,e)}j(!1)}},[e,o,l]),I=(0,r.useCallback)(()=>{C()},[C]),S=m&&g?(0,s.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-[5px] border border-gray-200 flex-shrink-0",children:(0,s.jsx)(e4.default,{src:g.logo,alt:g.label,width:16,height:16,className:"rounded-[3px]"})}):(0,s.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-[5px] border border-gray-200 flex-shrink-0",children:(0,s.jsx)(eu.A,{className:"h-3.5 w-3.5 text-gray-900"})});return(0,s.jsxs)("div",{className:"cursor-move",children:[(0,s.jsxs)("div",{className:"bg-white border border-gray-200 rounded w-[1100px] shadow-sm",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-gray-200",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[S,(0,s.jsx)("span",{className:"text-sm font-medium text-gray-900",children:i.title||"Analytics Reporting"}),m&&x&&(0,s.jsx)("span",{className:"text-xs text-gray-400 truncate max-w-[180px]",children:x})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 nodrag nowheel",onPointerDown:e=>e.stopPropagation(),children:[m&&v&&(0,s.jsx)(c.$,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 nodrag",onClick:e=>{e.stopPropagation(),function(e){let{overall_llm:t,non_llm:a,platform_breakdown:s,propertyName:r,dateRange:l,startDate:n,endDate:i,snapshot_timestamp:o}=e,d=t.sessions+(a?.sessions||0),c=[];for(let e of(c.push("Analytics Baseline Export"),c.push(`Property,${tY(r)}`),c.push(`Date Range,${tY(l)}`),c.push(`Period,${tY(n)} - ${tY(i)}`),c.push(`Snapshot,${tY(o)}`),c.push(""),c.push("Metric,LLM,Non-LLM,Total"),c.push(`Sessions,${t.sessions},${a?.sessions??"â"},${d}`),c.push(`Engaged Sessions,${t.engaged_sessions},${a?.engaged_sessions??"â"},${t.engaged_sessions+(a?.engaged_sessions||0)}`),c.push(`Engagement Rate,${t.engagement_rate}%,${a?`${a.engagement_rate}%`:"â"},`),c.push(`Conversions,${t.conversions},${a?.conversions??"â"},${t.conversions+(a?.conversions||0)}`),c.push(""),c.push("Platform,Sessions,Engaged Sessions,Conversions,Engagement Rate"),s)){let t=e.sessions>0?`${(e.engaged_sessions/e.sessions*100).toFixed(1)}%`:"â";c.push(`${tY(e.platform)},${e.sessions},${e.engaged_sessions},${e.conversions},${t}`)}let x=new Blob([c.join("\n")],{type:"text/csv;charset=utf-8;"}),m=URL.createObjectURL(x),g=document.createElement("a");g.href=m,g.download=`analytics-baseline-${r.replace(/\s+/g,"-").toLowerCase()}-${l}.csv`,document.body.appendChild(g),g.click(),document.body.removeChild(g),URL.revokeObjectURL(m)}(v)},title:"Download CSV",children:(0,s.jsx)(tx.A,{className:"h-3.5 w-3.5 text-gray-900"})}),m&&(0,s.jsx)(c.$,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 nodrag",onClick:e=>{e.stopPropagation(),I()},title:"Refresh data",children:(0,s.jsx)(tm.A,{className:"h-3.5 w-3.5 text-gray-900"})}),m&&g&&(0,s.jsx)(c.$,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 nodrag",onClick:e=>{e.stopPropagation(),p(!0)},title:"Configure",children:(0,s.jsx)(eK.A,{className:"h-3.5 w-3.5 text-gray-900"})}),a&&(0,s.jsx)(c.$,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-gray-900 hover:text-red-500 nodrag",onClick:e=>{e.stopPropagation(),a()},children:(0,s.jsx)(e1.A,{className:"h-3.5 w-3.5"})})]})]}),m?g?(0,s.jsx)(tT,{loading:b,saving:y,snapshot:v,propertyLabel:x||d||"",provider:g}):null:(0,s.jsx)(tG,{onSelect:k})]}),h.current&&(0,s.jsx)(tU,{open:u,metadata:o,userId:n,provider:h.current,onSave:A,onClose:()=>p(!1)})]})}var tq=a(52385),tZ=a(10509),tQ=a(57351),t0=a(51348),t1=a(84933),t2=a(80466),t5=a(17606),t3=a(70586),t4=a(69898),t6=a(1
15978),t9=a(83279),t8=a(12732),t7=a(95235);let ae=[{id:"white",bg:"#FFFFFF",border:"#E5E7EB"},{id:"gray",bg:"#F9FAFB",border:"#D1D5DB"},{id:"blue",bg:"#F0F9FF",border:"#93C5FD"},{id:"green",bg:"#F0FDF4",border:"#86EFAC"},{id:"amber",bg:"#FFFBEB",border:"#FCD34D"}];function at({id:e,artifact:t,selected:a,onUpdate:l,onDelete:n}){let i=t.metadata||{},[o,d]=r.useState(i.colorId||"white"),c=i.content??"",x=ae.find(e=>e.id===o)||ae[0],m=(0,r.useRef)(null),g=(0,r.useCallback)(e=>{m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{l({metadata:{...i,content:e,colorId:o}})},400)},[l,i,o]),h=(0,tq.hG)({extensions:[tZ.W.configure(),tQ.A.configure({placeholder:"Type a note..."}),t0.A],content:c?c?.trim()?/<[a-z][\s\S]*>/i.test(c)?c:`<p>${c.replace(/\n/g,"</p><p>")}</p>`:"":"",editorProps:{attributes:{class:"prose prose-sm max-w-none focus:outline-none min-h-[120px] py-1 px-2 [&_p]:leading-normal [&_p]:my-1 [&_strong]:font-bold [&_em]:italic [&_u]:underline"},handleDOMEvents:{mousedown:(e,t)=>t.stopPropagation?.()}},onUpdate:({editor:e})=>g(e.getHTML()),immediatelyRender:!1});(0,r.useEffect)(()=>()=>{m.current&&clearTimeout(m.current)},[]);let u=(e,t,a)=>(0,s.jsx)("button",{type:"button",onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),e()},className:"p-1 rounded hover:bg-black/10 transition-colors",title:a,children:(0,s.jsx)(t,{className:"w-3.5 h-3.5 text-gray-700"})});return(0,s.jsxs)("div",{className:"relative",children:[a&&h&&(0,s.jsxs)("div",{className:"absolute bottom-full left-0 mb-2 flex items-center gap-0.5 px-2 py-1 bg-white border border-gray-200 rounded-lg shadow-lg z-50",onMouseDownCapture:e=>e.preventDefault(),onMouseDown:e=>e.stopPropagation(),children:[ae.map(e=>(0,s.jsx)("button",{type:"button",onClick:()=>{var t;d(t=e.id),l({metadata:{...i,content:c,colorId:t}})},className:(0,eE.cn)("w-5 h-5 rounded-full border-2 transition-all",o===e.id?"border-gray-800 scale-110":"border-transparent hover:scale-110"),style:{backgroundColor:e.border}},e.id)),(0,s.jsx)("div",{className:"w-px h-5 bg-gray-200 mx-1"}),u(()=>h.chain().focus().toggleBold().run(),t1.A,"Bold"),u(()=>h.chain().focus().toggleItalic().run(),t2.A,"Italic"),u(()=>h.chain().focus().toggleUnderline().run(),t5.A,"Underline"),(0,s.jsx)("div",{className:"w-px h-5 bg-gray-200 mx-1"}),u(()=>h.chain().focus().toggleBulletList().run(),t3.A,"Bullet List"),u(()=>h.chain().focus().toggleOrderedList().run(),t4.A,"Ordered List"),(0,s.jsx)("div",{className:"w-px h-5 bg-gray-200 mx-1"}),u(()=>h.chain().focus().toggleHeading({level:1}).run(),t6.A,"Heading 1"),u(()=>h.chain().focus().toggleHeading({level:2}).run(),t9.A,"Heading 2"),u(()=>h.chain().focus().toggleHeading({level:3}).run(),t8.A,"Heading 3")]}),(0,s.jsxs)("div",{className:"rounded-lg overflow-hidden shadow-md transition-shadow hover:shadow-lg",style:{width:i.width||260,minHeight:i.height||180,backgroundColor:x.bg,border:`3px solid ${x.border}`},children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-2 pt-2 cursor-move","data-draghandle":!0,children:[(0,s.jsx)(t7.A,{className:"w-4 h-4 text-gray-400"}),(0,s.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),n()},className:"p-0.5 rounded hover:bg-black/10 transition-colors",children:(0,s.jsx)(z.A,{className:"w-3.5 h-3.5 text-gray-500"})})]}),(0,s.jsxs)("div",{className:"sticky-note-editor text-sm text-gray-800 cursor-text px-3 pb-3",onMouseDown:e=>e.stopPropagation(),"data-no-drag":!0,children:[(0,s.jsx)("style",{dangerouslySetInnerHTML:{__html:".sticky-note-editor strong{font-weight:700}.sticky-note-editor em{font-style:italic}.sticky-note-editor u{text-decoration:underline}"}}),h&&(0,s.jsx)(tq.$Z,{editor:h,className:"min-h-[120px]"})]})]})]})}var aa=a(25002),as=a(96117);let ar=e=>10*Math.round(e/10);function al({id:e,artifact:t,selected:a,onUpdate:l,onDelete:n,onMoveForward:o,onMoveBackward:d}){let c,x=t.metadata||{},m=x.fill||"#FFFFFF",g=x.stroke||"#E5E7EB",h=x.strokeWidth??1,u=x.opacity??100,p=x.cornerRadius??5,f=x.width||400,y=x.height||260,j=x.aspectRatioLocked??!1,{updateArtifact:v,updateNodePosition:w}=(0,ep.y)(),{getNode:N,flowToScreenPosition:C}=(0,i.VH)(),k=N(e),A=k?.position??{x:t.x??0,y:t.y??0},{getHandleProps:I}=function(e){let{nodeId:t,width:a,height:s,position:l,aspectRatioLocked:n=!1,onResize:o,onPositionChange:d}=e,{screenToFlowPosition:c}=(0,i.VH)(),x=(0,r.useRef)(null),m=(0,r.useCallback)(e=>{let t=x.current;if(!t)return;let a=c({x:e.clientX,y:e.clientY}),s=ar(a.x-t.startX),r=ar(a.y-t.startY),l=t.startW/Math.max(1,t.startH),n=t.startW,i=t.startH,m=t.startPosX,g=t.startPosY;if(t.aspectRatioLocked&&t.startH>0)switch(t.handle){case"e":i=Math.max(50,ar((n=Math.max(50,t.startW+s))/l));break;case"w":i=Math.max(50,ar((n=Math.max(50,t.startW-s))/l)),m=t.startPosX+(t.startW-n);break;case"s":n=Math.max(50,ar((i=Math.max(50,t.startH+r))*l));break;case"n":n=Math.max(50,ar((i=Math.max(50,t.startH-r))*l)),g=t.startPosY+(t.startH-i);break;case"se":{let e=t.startW+s,a=t.startH+r;e/a>=l?i=Math.max(50,ar((n=Math.max(50,e))/l)):n=Math.max(50,ar((i=Math.max(50,a))*l));break}case"sw":{let e=Math.max(50,t.startW-s);i=Math.max(50,ar(e/l)),n=e,m=t.startPosX+(t.startW-n);break}case"ne":{let e=Math.max(50,t.startH-r);n=Math.max(50,ar(e*l)),i=e,g=t.startPosY+(t.startH-i);break}case"nw":{let e=Math.max(50,t.startW-s),a=Math.max(50,t.startH-r);e/a>=l?i=Math.max(50,ar((n=e)/l)):n=Math.max(50,ar((i=a)*l)),m=t.startPosX+(t.startW-n),g=t.startPosY+(t.startH-i)}}else switch(t.handle){case"e":n=Math.max(50,t.startW+s);break;case"w":n=Math.max(50,t.startW-s),m=t.startPosX+(t.startW-n);break;case"s":i=Math.max(50,t.startH+r);break;case"n":i=Math.max(50,t.startH-r),g=t.startPosY+(t.startH-i);break;case"se":n=Math.max(50,t.startW+s),i=Math.max(50,t.startH+r);break;case"sw":n=Math.max(50,t.startW-s),i=Math.max(50,t.startH+r),m=t.startPosX+(t.startW-n);break;case"ne":n=Math.max(50,t.startW+s),i=Math.max(50,t.startH-r),g=t.startPosY+(t.startH-i);break;case"nw":n=Math.max(50,t.startW-s),i=Math.max(50,t.startH-r),m=t.startPosX+(t.startW-n),g=t.startPosY+(t.startH-i)}o({width:n,height:i}),(m!==t.startPosX||g!==t.startPosY)&&d(m,g)},[c,o,d]),g=(0,r.useCallback)(()=>{x.current=null,window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",g)},[m]);return{getHandleProps:(0,r.useCallback)(e=>({onMouseDown:t=>{t.preventDefault(),t.stopPropagation();let r=c({x:t.clientX,y:t.clientY});x.current={startX:r.x,startY:r.y,startW:a,startH:s,startPosX:l.x,startPosY:l.y,handle:e,aspectRatioLocked:n},window.addEventListener("mousemove",m),window.addEventListener("mouseup",g)}}),[a,s,l,n,c,m,g])}}({nodeId:e,width:f,height:y,position:A,aspectRatioLocked:j,onResize:e=>l({metadata:{...x,...e}}),onPositionChange:(t,a)=>w(e,{x:t,y:a})}),S=e=>{l({metadata:{...x,...e}})},_="nodrag absolute w-2.5 h-2.5 bg-white border border-gray-400 rounded-sm cursor-nwse-resize",P="nodrag absolute w-3 h-3 rounded-full bg-white border border-gray-400 cursor-ew-resize",T="nodrag absolute w-3 h-3 rounded-full bg-white border border-gray-400 cursor-ns-resize";return(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:(0,eE.cn)("transition-shadow",a&&"ring-2 ring-blue-400 ring-offset-1"),style:{width:f,height:y,backgroundColor:m,border:`${h}px solid ${g}`,borderRadius:p,opacity:u/100}}),a&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:(0,eE.cn)(_,"-top-1 -left-1 -translate-x-1/2 -translate-y-1/2 cursor-nwse-resize"),...I("nw")}),(0,s.jsx)("div",{className:(0,eE.cn)(_,"-top-1 -right-1 translate-x-1/2 -translate-y-1/2 cursor-nesw-resize"),...I("ne")}),(0,s.jsx)("div",{className:(0,eE.cn)(_,"-bottom-1 -left-1 -translate-x-1/2 translate-y-1/2 cursor-nesw-resize"),...I("sw")}),(0,s.jsx)("div",{className:(0,eE.cn)(_,"-bottom-1 -right-1 translate-x-1/2 translate-y-1/2 cursor-nwse-resize"),...I("se")}),(0,s.jsx)("div",{className:(0,eE.cn)(P,"top-1/2 -left-1.5 -translate-y-1/2 -translate-x-1/2"),...I("w")}),(0,s.jsx)("div",{className:(0,eE.cn)(P,"top-1/2 -right-1.5 -translate-y-1/2 translate-x-1/2"),...I("e")}),(0,s.jsx)("div",{className:(0,eE.cn)(T,"-top-1.5 left-1/2 -translate-x-1/2 -translate-y-1/2"),...I("n")}),(0,s.jsx)("div",{className:(0,eE.cn)(T,"-bottom-1.5 left-1/2 -translate-x-1/2 translate-y-1/2"),...I("s")})]}),a&&(0,s.jsxs)("div",{className:"nodrag absolute left-1/2 -translate-x-1/2 top-full mt-1 px-2 py-0.5 rounded bg-blue-500 text-white text-[10px] font-medium whitespace-nowrap",onMouseDown:e=>e.stopPropagation(),children:[Math.round(f)," \xd7 ",Math.round(y)]}),a&&"undefined"!=typeof document&&(0,aa.createPortal)((c=C({x:A.x+f,y:A.y}),(0,s.jsxs)("div",{className:"nodrag fixed w-56 bg-white border border-gray-200 rounded-lg shadow-xl text-xs overflow-hidden",style:{left:c.x+12,top:c.y,zIndex:9999},onMouseDown:e=>e.stopPropagation(),children:[(0,s.jsx)("div",{className:"px-3 py-2 bg-gray-50 border-b border-gray-200 font-bold text-gray-800 uppercase tracking-tight text-[11px]",children:"Rectangle"}),(0,s.jsxs)("div",{className:"px-3 py-2 border-b border-gray-100",children:[(0,s.jsx)("p",{className:"text-[10px] font-bold text-gray-500 uppercase mb-1.5",children:"Dimensions"}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("label",{className:"flex-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-gray-400",children:"W"}),(0,s.jsx)(b.p,{type:"number",defaultValue:f,onBlur:e=>S({width:Number(e.target.value)||100}),className:"h-7 text-xs mt-0.5"},`w-${f}`)]}),(0,s.jsxs)("label",{className:"flex-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-gray-400",children:"H"}),(0,s.jsx)(b.p,{type:"number",defaultValue:y,onBlur:e=>S({height:Number(e.target.value)||100}),className:"h-7 text-xs mt-0.5"},`h-${y}`)]})]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",title:"Lock aspect ratio",children:[(0,s.jsx)("input",{type:"checkbox",checked:j,onChange:e=>S({aspectRatioLocked:e.target.checked}),className:"rounded border-gray-300"}),(0,s.jsx)(as.A,{className:"w-3.5 h-3.5 text-gray-500"}),(0,s.jsx)("span",{className:"text-[10px] text-gray-600",children:"Lock aspect ratio"})]})]}),(0,s.jsxs)("div",{className:"px-3 py-2 border-b border-gray-100",children:[(0,s.jsx)("p",{className:"text-[10px] font-bold text-gray-500 uppercase mb-1.5",children:"Appearance"}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("label",{className:"flex-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-gray-400",children:"Opacity"}),(0,s.jsx)(b.p,{type:"number",min:0,max:100,value:u,onChange:e=>S({opacity:Math.min(100,Math.max(0,Number(e.target.value)))}),className:"h-7 text-xs mt-0.5"})]}),(0,s.jsxs)("label",{className:"flex-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-gray-400",children:"Radius"}),(0,s.jsx)(b.p,{type:"number",min:0,value:p,onChange:e=>S({cornerRadius:Number(e.target.value)||0}),className:"h-7 text-xs mt-0.5"})]})]})]}),(0,s.jsxs)("div",{className:"px-3 py-2 border-b border-gray-100",children:[(0,s.jsx)("p",{className:"text-[10px] font-bold text-gray-500 uppercase mb-1.5",children:"Fill"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("input",{type:"color",value:m,onChange:e=>S({fill:e.target.value}),className:"w-7 h-7 rounded border border-gray-200 cursor-pointer p-0"}),(0,s.jsx)(b.p,{value:m.replace("#","").toUpperCase(),onChange:e=>S({fill:`#${e.target.value.replace("#","")}`}),className:"h-7 text-xs flex-1 font-mono",maxLength:7})]})]}),(0,s.jsxs)("div",{className:"px-3 py-2 border-b border-gray-100",children:[(0,s.jsx)("p",{className:"text-[10px] font-bold text-gray-500 uppercase mb-1.5",children:"Stroke"}),(0,s.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,s.jsx)("input",{type:"color",value:g,onChange:e=>S({stroke:e.target.value}),className:"w-7 h-7 rounded border border-gray-200 cursor-pointer p-0"}),(0,s.jsx)(b.p,{type:"number",min:0,max:10,value:h,onChange:e=>S({strokeWidth:Number(e.target.value)||0}),className:"h-7 text-xs w-16",placeholder:"px"})]})]}),(0,s.jsxs)("div",{className:"px-3 py-2 flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex gap-1",children:[(0,s.jsx)("button",{onClick:o,className:"p-1 rounded hover:bg-gray-100",title:"Bring forward",children:(0,s.jsx)(eP.A,{className:"w-3.5 h-3.5 text-gray-600"})}),(0,s.jsx)("button",{onClick:d,className:"p-1 rounded hover:bg-gray-100",title:"Send backward",children:(0,s.jsx)(eT.A,{className:"w-3.5 h-3.5 text-gray-600"})})]}),(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),n()},className:"p-1 rounded hover:bg-red-50 text-red-500 hover:text-red-600",title:"Delete",children:(0,s.jsx)(e1.A,{className:"w-3.5 h-3.5"})})]})]})),document.body)]})}var an=a(12713);let ai={queued:"Queued",running:"Running",completed:"Completed",error:"Error"},ao={queued:"bg-gray-100 text-gray-700 border-gray-200",running:"bg-blue-50 text-blue-700 border-blue-200",completed:"bg-green-50 text-green-700 border-green-200",error:"bg-red-50 text-red-700 border-red-200"};function ad({shell:e,selected:t}){let a=e.metadata?.status||"queued";return(0,s.jsxs)("div",{className:(0,eE.cn)("relative w-[320px] rounded-lg",t&&"ring-2 ring-blue-400 ring-offset-2"),children:[(0,s.jsx)("div",{className:"absolute top-3 right-3 z-20",children:(0,s.jsx)(u.E,{variant:"outline",className:(0,eE.cn)("font-medium",ao[a]||ao.queued),children:ai[a]||ai.queued})}
1),(0,s.jsx)(an.AgentCard,{id:e.id,title:e.title,description:e.description,icons:e.icons,image:null,isPopular:!1,visual:e.visual||"generator",modelId:e.modelId})]})}let ac=(0,n.default)(()=>a.e(42774).then(a.bind(a,42774)).then(e=>e.CanvasMenuButton),{loadableGenerated:{webpack:()=>[42774]},ssr:!1});function ax({title:e,description:t,readOnly:a=!1,headerRight:n}){let{artifacts:o,nodes:d,edges:c,onNodesChange:x,onEdgesChange:g,boards:h,removeArtifact:u,removeBoard:p,addArtifact:b,addFreeformArtifact:f,updateArtifact:y,saveCanvas:j,saving:v,isLoading:w,userId:N,loadCanvas:C,setNodes:k,canvasId:A,canvasSlug:I}=(0,ep.y)(),{fitView:S}=(0,i.VH)(),[_,P]=(0,r.useState)(null),[T,M]=(0,r.useState)(!1),[E,L]=(0,r.useState)(!1),[D,F]=(0,r.useState)(null),[O,R]=(0,r.useState)(null),[z,B]=(0,r.useState)({open:!1,artifactId:null,initialData:null}),[H,W]=(0,r.useState)({open:!1,templateId:null}),[X,K]=(0,r.useState)({open:!1,boardId:null,boardTitle:"",artifactCount:0}),V=(0,r.useCallback)((e,t,a)=>{K({open:!0,boardId:a,boardTitle:e,artifactCount:t})},[]),G=(0,r.useCallback)(()=>{X.boardId&&p(X.boardId),K({open:!1,boardId:null,boardTitle:"",artifactCount:0})},[X.boardId,p]),Y=(0,r.useCallback)(e=>{if(O){let t=d.find(e=>e.id===O),a=h.find(e=>e.id===O),s=t?.data?.stage||"awareness",r=o.filter(e=>e.boardId===O),l=a?.positioningMode==="freeform",n=r.length%4,i=Math.floor(r.length/4);b({id:`artifact-${Date.now()}`,title:e.file_name||e.title||"Untitled",knowledgeItemId:e.id,storagePath:e.storage_path,sourceType:e.source_type,x:l?40+20*r.length:24+214*n,y:l?40+20*r.length:284*i,stage:s,boardId:O,metadata:e.metadata})}else{let t=o.filter(e=>!e.boardId).length;f({id:`artifact-${Date.now()}`,title:e.file_name||e.title||"Untitled",knowledgeItemId:e.id,storagePath:e.storage_path,sourceType:e.source_type,x:200+40*t,y:200+40*t,metadata:e.metadata})}},[o,O,b,f,d,h]),J=(0,r.useCallback)(e=>{let t={agentSlug:e.slug,description:e.description,modelId:e.content_metadata?.modelId,status:e.content_metadata?.status||"active",knowledgeCount:e.content_metadata?.linkedKnowledgeCount,toolCount:e.content_metadata?.linkedToolCount};if(O){let a=o.filter(e=>e.boardId===O);b({id:`agent-artifact-${Date.now()}`,title:e.title,knowledgeItemId:e.id,storagePath:void 0,sourceType:"agent_template",x:24+a.length%3*296,y:196*Math.floor(a.length/3),stage:"awareness",boardId:O,metadata:t})}else{let a=o.filter(e=>!e.boardId&&"agent_template"===e.sourceType).length;f({id:`agent-artifact-${Date.now()}`,title:e.title,knowledgeItemId:e.id,storagePath:void 0,sourceType:"agent_template",x:200+60*a,y:200+60*a,metadata:t})}},[o,O,b,f]),q=(0,r.useCallback)(()=>{let e=o.filter(e=>!e.boardId&&"sticky_note"===e.sourceType).length;f({id:`note-${Date.now()}`,title:"Sticky Note",sourceType:"sticky_note",x:300+30*e,y:300+30*e,metadata:{content:"",colorId:"white"}})},[o,f]),Z=(0,r.useCallback)(()=>{let e=o.filter(e=>!e.boardId&&"rectangle_shape"===e.sourceType).length;f({id:`rect-${Date.now()}`,title:"Rectangle",sourceType:"rectangle_shape",x:100+30*e,y:100+30*e,metadata:{fill:"#FFFFFF",stroke:"#E5E7EB",width:400,height:260,opacity:100,cornerRadius:5}})},[o,f]),Q=(0,r.useCallback)(e=>{k(t=>{let a=t.findIndex(t=>t.id===e);if(a<0||a===t.length-1)return t;let s=[...t];return[s[a],s[a+1]]=[s[a+1],s[a]],s})},[k]),ee=(0,r.useCallback)(e=>{k(t=>{let a=t.findIndex(t=>t.id===e);if(a<=0)return t;let s=[...t];return[s[a],s[a-1]]=[s[a-1],s[a]],s})},[k]),et=(0,r.useCallback)(e=>{k(t=>t.map(t=>t.id===e?{...t,hidden:!t.hidden}:t))},[k]),ea=d.find(e=>e.selected)?.id||null,es=(0,r.useMemo)(()=>({canvasArtifactCard:e=>(0,s.jsx)("div",{className:"canvas-card-drag cursor-move",children:(0,s.jsx)(eZ.b,{id:e.id,artifact:e.data.artifact,selected:e.selected,onUpdate:t=>y(e.data.artifact.id,t),onSettingsOpen:e=>B({open:!0,artifactId:e.knowledgeItemId,initialData:e}),onDelete:u,onMoveForward:()=>Q(e.id),onMoveBackward:()=>ee(e.id)})}),canvasAgentCard:e=>(0,s.jsx)("div",{className:"canvas-card-drag cursor-move",children:(0,s.jsx)(e5,{agent:{id:e.data.artifact.id,slug:e.data.artifact.metadata?.agentSlug||e.data.artifact.title,name:e.data.artifact.title,de
1scription:e.data.artifact.metadata?.description,modelId:e.data.artifact.metadata?.modelId,status:e.data.artifact.metadata?.status||"active",linkedKnowledgeCount:e.data.artifact.metadata?.knowledgeCount,linkedToolCount:e.data.artifact.metadata?.toolCount},onOpenModal:()=>W({open:!0,templateId:e.data.artifact.metadata?.agentSlug}),onOpenBuilder:()=>window.open(`/agent-builder/${e.data.artifact.metadata?.agentSlug}`,"_blank"),onRemove:()=>u(e.data.artifact.id)})}),workflowSubAgentShellCard:e=>(0,s.jsx)("div",{className:"canvas-card-drag cursor-move",children:(0,s.jsx)(ad,{shell:{id:e.data.artifact.id,title:e.data.artifact.title,description:e.data.artifact.metadata?.description||"",icons:Array.isArray(e.data.artifact.metadata?.icons)?e.data.artifact.metadata.icons:[],modelId:e.data.artifact.metadata?.modelId,visual:e.data.artifact.metadata?.visual||"generator",metadata:e.data.artifact.metadata},selected:e.selected})}),stickyNote:e=>(0,s.jsx)(at,{id:e.id,artifact:e.data.artifact,selected:e.selected,onUpdate:t=>y(e.data.artifact.id,t),onDelete:()=>u(e.data.artifact.id)}),rectangleShape:e=>(0,s.jsx)("div",{className:"canvas-card-drag cursor-move",children:(0,s.jsx)(al,{id:e.id,artifact:e.data.artifact,selected:e.selected,onUpdate:t=>y(e.data.artifact.id,t),onDelete:()=>u(e.data.artifact.id),onMoveForward:()=>Q(e.id),onMoveBackward:()=>ee(e.id)})}),stageBoard:e=>(0,s.jsx)(tt,{id:e.id,data:e.data,onAddArtifact:()=>{R(e.id),P("artifacts")},onDeleteBoard:(t,a)=>V(t,a,e.id),onSettingsOpen:e=>B({open:!0,artifactId:e.knowledgeItemId,initialData:e})}),agentKnowledgeTableBoard:e=>(0,s.jsx)(ta,{id:e.id,data:e.data,onAddAgent:()=>{R(e.id),P("agents")},onDeleteBoard:(t,a)=>V(t,a,e.id),onOpenAgentSettings:e=>W({open:!0,templateId:e})}),socialCalendarBoard:e=>(0,s.jsx)(tc,{id:e.id,data:{board:e.data.board,calendarId:e.data.board.metadata?.calendarId,calendarSlug:e.data.board.metadata?.calendarSlug,knowledgeTableId:e.data.board.metadata?.knowledgeTableId},onDelete:()=>V("Social Calendar",0,e.id),userId:N}),analyticsReportingBoard:e=>(0,s.jsx)(tJ,{id:e.id,data:{board:e.data.board},onDelete:()=>V("Analytics Reporting",0,e.id)})}),[u,y,V,Q,ee,N]);return(0,s.jsxs)("div",{className:"w-full h-screen bg-background flex flex-col",children:[(0,s.jsxs)("div",{className:"bg-white border-b border-gray-200 px-6 py-3 flex items-center justify-between flex-shrink-0 z-10",children:[(0,s.jsxs)("div",{className:"flex items-center gap-4",children:[(0,s.jsx)("h1",{className:"text-lg font-semibold text-gray-900 truncate max-w-[300px]",children:e}),t&&(0,s.jsx)("p",{className:"text-sm text-gray-600 hidden sm:inline truncate max-w-[400px]",children:t})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[n,!a&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(m,{onSave:j,disabled:v}),(0,s.jsx)(ac,{onExport:()=>L(!0),onShareOptions:()=>P("sharing")})]})]})]}),(0,s.jsxs)("div",{className:"flex-1 relative flex overflow-hidden bg-white",children:[w&&(0,s.jsxs)("div",{className:"absolute inset-0 z-[100] bg-white/80 backdrop-blur-sm flex flex-col items-center justify-center gap-3",children:[(0,s.jsx)(l.A,{className:"h-8 w-8 animate-spin text-blue-600"}),(0,s.jsx)("p",{className:"text-sm font-semibold text-gray-900 uppercase tracking-widest",children:"Restoring Canvas..."})]}),!a&&T&&(0,s.jsx)(eD,{nodes:d,onClose:()=>M(!1),onSelectNode:e=>k(t=>t.map(t=>({...t,selected:t.id===e}))),onMoveForward:Q,onMoveBackward:ee,onToggleVisibility:et,selectedNodeId:ea}),(0,s.jsxs)("div",{className:"flex-1 relative overflow-hidden",children:[!a&&(0,s.jsx)("div",{className:"absolute top-4 left-4 z-50",children:(0,s.jsx)(U,{isArtifactPaletteOpen:"artifacts"===_,onToggleArtifactPalette:()=>P(e=>"artifacts"===e?null:"artifacts"),isBoardPaletteOpen:"boards"===_,onToggleBoardPalette:()=>P(e=>"boards"===e?null:"boards"),isAgentPaletteOpen:"agents"===_,onToggleAgentPalette:()=>P(e=>"agents"===e?null:"agents"),isUtilityPaletteOpen:"utilities"===_,onToggleUtilityPalette:()=>P(e=>"utilities"===e?null:"utilities"),isLayersPanelOpen:T,onToggleLayersPanel:()=>M(e=>!e),onFitView:()=>S({padding:.3,duration:400})})}),(0,s.jsx)("div",{className:"w-full h-full relative",children:(0,s.jsx)(eq,{hoveredBoardId:D,children:(0,s.jsxs)(i.Gc,{nodes:d,edges:c,onNodesChange:a?void 0:x,onEdgesChange:a?void 0:g,onNodeMouseEnter:a?void 0:(e,t)=>F(t.id),onNodeMouseLeave:a?void 0:()=>F(null),nodeTypes:es,fitView:!0,fitViewOptions:{padding:.3,maxZoom:1}
1,minZoom:.5,maxZoom:1.5,elevateNodesOnSelect:!1,nodesDraggable:!a,nodesConnectable:!a,elementsSelectable:!a,proOptions:{hideAttribution:!0},className:"bg-white",children:[(0,s.jsx)(i.VS,{color:"#b1b1b1",gap:20,size:1,variant:i._5.Dots}),(0,s.jsx)(i.H2,{position:"bottom-right"})]})})})]}),!a&&"artifacts"===_&&(0,s.jsx)(en,{onSelect:Y,onClose:()=>P(null)}),!a&&"agents"===_&&(0,s.jsx)(ec,{onSelect:J,onClose:()=>P(null),userId:N}),!a&&"boards"===_&&(0,s.jsx)(eb,{onClose:()=>P(null)}),!a&&"utilities"===_&&(0,s.jsx)(ej,{onAddStickyNote:q,onAddRectangle:Z,onClose:()=>P(null)}),!a&&"sharing"===_&&(0,s.jsx)(e_,{canvasId:A,canvasSlug:I,onClose:()=>P(null)})]}),!a&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)($,{open:E,onOpenChange:L,canvasId:A,canvasSlug:I}),(0,s.jsx)(eH,{knowledgeItemId:z.artifactId,open:z.open,onOpenChange:e=>B(t=>({...t,open:e})),userId:N||void 0,onSave:()=>C(),initialData:z.initialData}),H.templateId&&(0,s.jsx)(eG,{templateId:H.templateId,userId:N,open:H.open,onOpenChange:e=>W(t=>({...t,open:e})),onSuccess:()=>C(),onError:e=>console.error("[AgentCanvasSettingsModal] Error:",e)}),(0,s.jsx)(eX,{open:X.open,onOpenChange:e=>{e||K(e=>({...e,open:!1}))},boardTitle:X.boardTitle,artifactCount:X.artifactCount,onConfirm:G})]})]})}function am(e){return(0,s.jsx)(ep.w,{initialCanvasId:e.canvasId,initialCanvasSlug:e.canvasSlug,agentTemplateId:e.agentTemplateId,initialArtifacts:e.artifacts??[],onArtifactRemoved:e.onArtifactRemoved,preserveArtifactPositions:e.preserveArtifactPositions??!0,children:(0,s.jsx)(i.Ln,{children:(0,s.jsx)(ax,{title:e.title,description:e.description,readOnly:e.readOnly,headerRight:e.headerRight})})})}},19915:(e,t,a)=>{a.d(t,{II:()=>g,Nt:()=>h,at:()=>x});var s=a(68987),r=a(2315),l=a(57060),n=a(59149),i=a(22671),o=a(93210);let d={light:"",dark:".dark"},c=r.createContext(null);function x({id:e,className:t,children:a,config:n,...i}){let d=r.useId(),x=`chart-${e||d.replace(/:/g,"")}`;return(0,s.jsx)(c.Provider,{value:{config:n},children:(0,s.jsxs)("div",{"data-slot":"chart","data-chart":x,className:(0,o.cn)("[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",t),...i,children:[(0,s.jsx)(m,{id:x,config:n}),(0,s.jsx)(l.u,{children:a})]})})}let m=({id:e,config:t})=>{let a=Object.entries(t).filter(([,e])=>e.theme||e.color);return a.length?(0,s.jsx)("style",{dangerouslySetInnerHTML:{__html:Object.entries(d).map(([t,s])=>` 2${s} [data-chart=${e}] { 3${a.map(([e,a])=>{let s=a.theme?.[t]||a.color;return s?` --color-${e}: ${s};`:null}).join("\n")} 4} 5`).join("\n")}}):null},g=n.m;function h({active:e,payload:t,className:a,indicator:l="dot",hideLabel:n=!1,hideIndicator:i=!1,label:d,labelFormatter:x,labelClassName:m,formatter:g,color:h,nameKey:p,labelKey:b}){let{config:f}=function(){let e=r.useContext(c);if(!e)throw Error("useChart must be used within a <ChartContainer />");return e}(),y=r.useMemo(()=>{if(n||!t?.length)return null;let[e]=t,a=`${b||e?.dataKey||e?.name||"value"}`,r=u(f,e,a),l=b||"string"!=typeof d?r?.label:f[d]?.label||d;return x?(0,s.jsx)("div",{className:(0,o.cn)("font-medium",m),children:x(l,t)}):l?(0,s.jsx)("div",{className:(0,o.cn)("font-medium",m),children:l}):null},[d,x,t,n,m,f,b]);if(!e||!t?.length)return null;let j=1===t.length&&"dot"!==l;return(0,s.jsxs)("div",{className:(0,o.cn)("border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",a),children:[j?null:y,(0,s.jsx)("div",{className:"grid gap-1.5",children:t.filter(e=>"none"!==e.type).map((e,t)=>{let a=`${p||e.name||e.dataKey||"value"}`,r=u(f,e,a),n=h||e.payload.fill||e.color;return(0,s.jsx)("div",{className:(0,o.cn)("[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5","dot"===l&&"items-center"),children:g&&e?.value!==void 0&&e.name?g(e.value,e.name,e,t,e.payload):(0,s.jsxs)(s.Fragment,{children:[r?.icon?(0,s.jsx)(r.icon,{}):!i&&(0,s.jsx)("div",{className:(0,o.cn)("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":"dot"===l,"w-1":"line"===l,"w-0 border-[1.5px] border-dashed bg-transparent":"dashed"===l,"my-0.5":j&&"dashed"===l}),style:{"--color-bg":n,"--color-border":n}}),(0,s.jsxs)("div",{className:(0,o.cn)("flex flex-1 justify-between leading-none",j?"items-end":"items-center"),children:[(0,s.jsxs)("div",{className:"grid gap-1.5",children:[j?y:null,(0,s.jsx)("span",{className:"text-muted-foreground",children:r?.label||e.name})]}),e.value&&(0,s.jsx)("span",{className:"text-foreground font-mono font-medium tabular-nums",children:e.value.toLocaleStr
5ing()})]})]})},e.dataKey)})})]})}function u(e,t,a){if("object"!=typeof t||null===t)return;let s="payload"in t&&"object"==typeof t.payload&&null!==t.payload?t.payload:void 0,r=a;return a in t&&"string"==typeof t[a]?r=t[a]:s&&a in s&&"string"==typeof s[a]&&(r=s[a]),r in e?e[r]:e[a]}i.s},24422:(e,t,a)=>{a.d(t,{A:()=>o,O:()=>i});var s=a(68987),r=a(72961),l=a(64094);let n=[{value:"TOF",label:"Top of Funnel",color:"bg-blue-100 text-blue-700 border-blue-200"},{value:"MOF",label:"Middle of Funnel",color:"bg-orange-100 text-orange-700 border-orange-200"},{value:"BOF",label:"Bottom of Funnel",color:"bg-red-100 text-red-700 border-red-200"}];function i({value:e,onChange:t,disabled:a=!1,showLabel:i=!0,compact:o=!1}){let d=e&&n.some(t=>t.value===e)?n.find(t=>t.value===e):null;return o?(0,s.jsxs)(r.l6,{value:e||"none",onValueChange:e=>{t("none"===e?null:e)},disabled:a,children:[(0,s.jsx)(r.bq,{className:"w-fit",children:(0,s.jsx)(r.yv,{placeholder:"Select stage..."})}),(0,s.jsxs)(r.gC,{children:[(0,s.jsx)(r.eb,{value:"none",children:"None"}),n.map(e=>(0,s.jsx)(r.eb,{value:e.value,children:e.label},e.value))]})]}):(0,s.jsxs)("div",{className:"space-y-2",children:[i&&(0,s.jsx)("label",{className:"text-xs text-gray-500 uppercase",children:"Stage of Funnel"}),(0,s.jsxs)(r.l6,{value:e||"none",onValueChange:e=>{t("none"===e?null:e)},disabled:a,children:[(0,s.jsx)(r.bq,{children:(0,s.jsx)(r.yv,{placeholder:"Select funnel stage..."})}),(0,s.jsxs)(r.gC,{children:[(0,s.jsx)(r.eb,{value:"none",children:"None (Optional)"}),n.map(e=>(0,s.jsx)(r.eb,{value:e.value,children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("div",{className:`w-2 h-2 rounded-full ${e.color.split(" ")[0]}`}),e.label]})},e.value))]})]}),d&&(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(l.E,{className:d.color,children:d.label}),(0,s.jsx)("span",{className:"text-xs text-gray-500",children:d.value})]})]})}function o({value:e}){if(!e)return(0,s.jsx)(l.E,{variant:"outline",className:"text-gray-500",children:"â"});let t=n.find(t=>t.value===e);return t?(0,s.jsx)(l.E,{variant:"outline",className:t.color,children:t.value}):(0,s.jsx)(l.E,{variant:"outline",children:"Unknown"})}},32821:(e,t,a)=>{a.d(t,{w:()=>m,y:()=>g});var s=a(68987),r=a(2315),l=a(32589),n=a(45664);let i=["awareness","interest","desire","action","loyalty"];var o=a(76348);let d={agent_template:"canvasAgentCard",workflow_sub_agent_shell:"workflowSubAgentShellCard",sticky_note:"stickyNote",rectangle_shape:"rectangleShape"},c={agent_knowledge_table:"agentKnowledgeTableBoard",social_calendar:"socialCalendarBoard",analytics_reporting:"analyticsReportingBoard"},x=(0,r.createContext)(null);function m({children:e,initialCanvasId:t,initialCanvasSlug:a,initialArtifacts:m=[],agentTemplateId:g,onArtifactRemoved:h,preserveArtifactPositions:u=!0}){let[p,b]=(0,r.useState)(m),[f,y]=(0,r.useState)([]),[j,v]=(0,r.useState)(null),[w,N]=(0,r.useState)([]),[C,k]=(0,r.useState)([]),[A,I]=(0,r.useState)(null),S=(0,r.useRef)(p),_=(0,r.useRef)(f),P=(0,r.useRef)(w),T=(0,r.useRef)(async()=>{}),$=(0,r.useRef)(0);S.current=p,_.current=f,P.current=w;let{loadCanvas:M,saveCanvas:E,saving:L,isLoading:D}=function(e){let[t,a]=(0,r.useState)(!1),[s,l]=(0,r.useState)(!!e.initialCanvasSlug);return{loadCanvas:(0,r.useCallback)(async()=>{if(!e.initialCanvasSlug)return void l(!1);l(!0);try{let t=await fetch(`/api/artifact-canvas?slug=${e.initialCanvasSlug}`);if(!t.ok)return;let a=await t.json(),s=function(e){let t=e.canvas_data;if(!t)return{artifacts:[],boards:[],layerOrder:null};let a=[],s=[],r=t.board_positions||{},l=t.board_configs||{},o=t.custom_board_artifacts||{};return(t.active_board_ids||[]).forEach(e=>{let a=l[e],o=r[e],d=o?.x??(o?.relX?o.relX*window.innerWidth:100),c=o?.y??(o?.relY?o.relY*window.innerHeight:100);if(a)s.push({id:e,type:a.type,title:a.title,stage:a.stage,x:d,y:c,positioningMode:a.positioningMode||"freeform",metadata:a.metadata});else{let a=e.startsWith("board-")?e.replace("board-",""):null,r=a&&i.includes(a),l=r?a:void 0;s.push({id:e,type:r?"stage":"freeform",title:r?n.L[l]?.label||a:t.board_titles?.[e]||"Freeform Board",stage:l,x:d,y:c,positioningMode:"freeform"})}}
5),t.stages&&i.forEach(e=>{(t.stages[e]||[]).forEach((t,s)=>{a.push({id:t.id,title:t.title,knowledgeItemId:t.metadata?.knowledgeItemId,storagePath:t.metadata?.storagePath,sourceType:t.metadata?.sourceType||t.category,thumbnailUrl:t.thumbnailUrl,x:t.metadata?.relativeX??220*s,y:t.metadata?.relativeY??0,stage:e,boardId:`board-${e}`,metadata:t.metadata})})}),Object.entries(o).forEach(([e,t])=>{Array.isArray(t)&&t.forEach((t,s)=>{a.push({id:t.id,title:t.title,knowledgeItemId:t.metadata?.knowledgeItemId,storagePath:t.metadata?.storagePath,sourceType:t.metadata?.sourceType||"agent_template",thumbnailUrl:t.thumbnailUrl,x:t.metadata?.relativeX??280*s,y:t.metadata?.relativeY??0,stage:"awareness",boardId:e,metadata:t.metadata})})}),(t.canvas_items||[]).forEach(e=>{let t=r[e.id];a.push({id:e.id,title:e.title,knowledgeItemId:e.metadata?.knowledgeItemId,storagePath:e.metadata?.storagePath,sourceType:e.metadata?.sourceType,thumbnailUrl:e.thumbnailUrl,x:t?.x??e.x??100,y:t?.y??e.y??100,stage:"awareness",boardId:void 0,metadata:e.metadata})}),{artifacts:a,boards:s,layerOrder:Array.isArray(t.layer_order)?t.layer_order:null}}(a);e.onLoaded(s.artifacts,s.boards,s.layerOrder)}catch(e){console.error("[useCanvasPersistence] Load error:",e)}finally{l(!1)}},[e.initialCanvasSlug,e.onLoaded]),saveCanvas:(0,r.useCallback)(async()=>{if(e.initialCanvasId){a(!0);try{var t,s,r,l,n;let a,o,d,c,x,m,g,h,u,p=(t=e.artifactsRef.current,s=e.boardsRef.current,r=e.nodesRef.current,l=e.initialCanvasId,n=e.agentTemplateId,a={awareness:[],interest:[],desire:[],action:[],loyalty:[]},o={},d=[],c=window.innerWidth,x=window.innerHeight,m={},r.forEach(e=>{e.position&&(m[e.id]={x:e.position.x,y:e.position.y,relX:e.position.x/c,relY:e.position.y/x})}),g={},s.forEach(e=>{g[e.id]={type:e.type,title:e.title,stage:e.stage,positioningMode:e.positioningMode||"freeform",metadata:e.metadata}}),t.forEach(e=>{let t=r.find(t=>t.id===e.id),l=t?.position||{x:e.x,y:e.y},n={id:e.id,title:e.title,thumbnailUrl:e.thumbnailUrl,metadata:{...e.metadata,knowledgeItemId:e.knowledgeItemId,storagePath:e.storagePath,sourceType:e.sourceType,relativeX:e.x,relativeY:e.y}};if(!e.boardId)return void d.push({...n,x:l.x,y:l.y,relX:l.x/c,relY:l.y/x});let m=s.find(t=>t.id===e.boardId);m?.type==="agent_knowledge_table"||"agent_template"===e.sourceType?(o[e.boardId]||(o[e.boardId]=[]),o[e.boardId].push(n)):i.includes(e.stage)&&a[e.stage].push(n)}),h={},s.forEach(e=>{h[e.id]=e.title}),u=r.map(e=>e.id),{id:l,agent_template_id:n,canvas_data:{stages:a,custom_board_artifacts:o,canvas_items:d,board_configs:g,board_positions:m,board_titles:h,active_board_ids:Object.keys(g),layer_order:u,updated_at:new Date().toISOString()}}),b=await fetch("/api/artifact-canvas",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)});if(!b.ok)throw Error(`Save failed: ${b.status}`)}catch(e){console.error("[useCanvasPersistence] Save error:",e)}finally{a(!1)}}},[e.initialCanvasId,e.agentTemplateId,e.artifactsRef,e.boardsRef,e.nodesRef]),saving:t,isLoading:s}}({initialCanvasSlug:a,initialCanvasId:t,agentTemplateId:g,artifactsRef:S,boardsRef:_,nodesRef:P,onLoaded:(0,r.useCallback)((e,t,a)=>{b(e),y(t),v(a)},[])});T.current=E;let{nodes:F,onNodesChange:O,onEdgesChange:R,updateNodePosition:U}=function(e){let{artifacts:t,boards:a,layerOrder:s,nodes:l,setNodes:n,setEdges:i,setArtifacts:x,setBoards:m,saveRef:g}=e,h=(0,r.useMemo)(()=>{let e=new Map;return t.forEach(t=>{let a=t.boardId||(t.stage?`board-${t.stage}`:"orphan");e.has(a)||e.set(a,[]),e.get(a).push(t)}),e},[t]),u=(0,r.useMemo)(()=>{let e=t.filter(e=>!e.boardId),r=new Set(a.map(e=>e.id)),n=new Set(e.map(e=>e.id)),i=new Map(e.map(e=>[e.id,e])),o=new Map(a.map(e=>[e.id,e])),x=e=>{let t=o.get(e);return{id:e,type:c[t.type]||"stageBoard",position:{x:t.x,y:t.y},data:{board:t,stage:t.stage,artifacts:h.get(e)||[]},dragHandle:".cursor-move"}},m=e=>{let t=i.get(e),a=d[t.sourceType||""]||"canvasArtifactCard";return{id:e,type:a,position:{x:t.x,y:t.y},data:{artifact:t},dragHandle:"stickyNote"===a?"[data-draghandle]":".canvas-card-drag"}},g=[],u=new Set,p=new Set;if(s?.length&&0===l.length){for(let e of s)if(r.has(e)&&o.has(e)){u.add(e);
5let t=o.get(e),a=l.find(t=>t.id===e);g.push(a?{...a,position:a.position??{x:t.x,y:t.y},data:{board:t,stage:t.stage,artifacts:h.get(e)||[]},dragHandle:".cursor-move"}:x(e))}else if(n.has(e)&&i.has(e)){p.add(e);let t=i.get(e),a=l.find(t=>t.id===e),s=d[t.sourceType||""]||"canvasArtifactCard";g.push(a?{...a,position:a.position??{x:t.x,y:t.y},data:{artifact:t},dragHandle:"stickyNote"===s?"[data-draghandle]":".canvas-card-drag"}:m(e))}}else if(l.length>0){for(let e of l)if(r.has(e.id)){let t=o.get(e.id);u.add(e.id),g.push({...e,position:e.position??{x:t.x,y:t.y},data:{board:t,stage:t.stage,artifacts:h.get(e.id)||[]},dragHandle:".cursor-move"})}else if(n.has(e.id)){let t=i.get(e.id);p.add(e.id);let a=d[t.sourceType||""]||"canvasArtifactCard";g.push({...e,position:e.position??{x:t.x,y:t.y},data:{artifact:t},dragHandle:"stickyNote"===a?"[data-draghandle]":".canvas-card-drag"})}}for(let e of a)u.has(e.id)||g.push(x(e.id));for(let t of e)p.has(t.id)||g.push(m(t.id));return g},[t,h,a,s,l]),p=(0,r.useCallback)((e,t=10)=>Math.round(e/t)*t,[]),b=(0,r.useCallback)(e=>{let t=e.filter(e=>"remove"===e.type);if(t.length>0){let e=t.map(e=>e.id);x(t=>t.filter(t=>!e.includes(t.id)&&(!t.boardId||!e.includes(t.boardId)))),m(t=>t.filter(t=>!e.includes(t.id))),setTimeout(()=>g.current?.(),100)}n(t=>{let a=(0,o._0)(e,t.length>0?t:u);return e.some(e=>"position"===e.type)?a.map(e=>e.position?{...e,position:{x:p(e.position.x),y:p(e.position.y)}}:e):a})},[p,n,x,m,g,u]),f=(0,r.useCallback)(e=>{i(t=>(0,o.zW)(e,t))},[i]),y=(0,r.useCallback)((e,t)=>{let a={x:p(t.x),y:p(t.y)};n(t=>(t.length>0?t:u).map(t=>t.id===e?{...t,position:a}:t)),x(t=>t.map(t=>t.id===e?{...t,x:a.x,y:a.y}:t))},[p,n,x,u]);return{nodes:u,onNodesChange:b,onEdgesChange:f,updateNodePosition:y}}({artifacts:p,boards:f,layerOrder:j,nodes:w,setNodes:N,setEdges:k,setArtifacts:b,setBoards:y,saveRef:T});(0,r.useEffect)(()=>{let e=!0;return(async()=>{let{data:{user:t}}=await l.supabase.auth.getUser();e&&t&&I(t.id),e&&a&&await M()})(),()=>{e=!1}},[a,M]),(0,r.useEffect)(()=>{a||t||b(e=>(function(e,t,a){if(0===t.length)return e;let s=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=s.get(e.id);return t?{...t,...e,x:a?t.x:e.x,y:a?t.y:e.y,metadata:{...t.metadata,...e.metadata}}:e})})(e,m,u))},[m,t,a,u]);let z=(0,r.useCallback)(e=>{b(t=>[...t,e]),setTimeout(()=>T.current(),100)},[]),B=(0,r.useCallback)(e=>{b(t=>{let a=t.find(t=>t.id===e);return h?.({artifactId:e,storagePath:a?.storagePath}),t.filter(t=>t.id!==e)}),setTimeout(()=>T.current(),100)},[h]),H=(0,r.useCallback)((e,t)=>{b(a=>a.map(a=>a.id===e?{...a,...t}:a))},[]),W=(0,r.useCallback)(e=>{b(t=>[...t,{...e,stage:e.stage||"awareness",boardId:void 0}]),setTimeout(()=>T.current(),100)},[]),X=(0,r.useCallback)((e,t,a)=>{let s=Date.now();if(s-$.current<100)return;$.current=s;let r=a?`board-${a}`:`board-${s}`,l="analytics_reporting"===e?{origin:"google-analytics"}:void 0;y(s=>s.some(e=>e.id===r)?s:[...s,{id:r,type:e,title:t,stage:a,x:100,y:100,positioningMode:"freeform",metadata:l}]),setTimeout(()=>T.current(),100)},[]),K=(0,r.useCallback)((e,t)=>{y(a=>a.map(a=>a.id===e?{...a,...t}:a)),setTimeout(()=>T.current(),120)},[]),V=(0,r.useCallback)(e=>{N(t=>t.filter(t=>t.id!==e)),y(t=>t.filter(t=>t.id!==e)),b(t=>t.filter(t=>t.boardId!==e)),setTimeout(()=>T.current(),100)},[]),G=(0,r.useMemo)(()=>({artifacts:p,boards:f,nodes:F,edges:C,saving:L,isLoading:D,userId:A,canvasId:t,canvasSlug:a,agentTemplateId:g,setArtifacts:b,setBoards:y,setNodes:N,onNodesChange:O,onEdgesChange:R,updateNodePosition:U,addArtifact:z,removeArtifact:B,updateArtifact:H,addBoard:X,updateBoard:K,removeBoard:V,addFreeformArtifact:W,saveCanvas:E,loadCanvas:M}),[p,f,F,C,L,D,A,t,a,g,O,R,U,z,B,H,X,K,V,W,E,M]);return(0,s.jsx)(x.Provider,{value:G,children:e})}function g(){let e=(0,r.useContext)(x);if(!e)throw Error("useCanvas must be used within CanvasProvider");return e}},45664:(e,t,a)=>{a.d(t,{L:()=>h});var s=a(70862),r=a(8549),l=a(20901),n=a(58407),i=a(1294),o=a(70099),d=a(98081),c=a(11891),x=a(21178),m=a(78324),g=a(89707);let h={awareness:{label:"Awareness",icon:s.A,description:"Top-of-funnel content for brand discovery"},interest:{label:"Interest",icon:r.A,description:"Educational content building curiosity"},desire:{label:"Desire",icon:l.A,description:"Compelling content creating want"},action:{label:"Action",icon:n.A,description:"Conversion-focused content"},loyalty:{label:"Loyalty",icon:i.A,description:"Retention and advocacy content"}};o.A,d.A,c.A,o.A,x.A,m.A,g.A}}]);
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.