1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EChartsBarChart-BM5RwBZm.js","assets/index-BBmhd2fr.js","assets/index-B7cYjGuw.css","assets/core-B_YBDarH.js","assets/echarts-zFUb0SoC.js","assets/chartTheme-DSkSEph5.js","assets/EChartsLineChart-D5FdcpAB.js","assets/EChartsAreaChart-B1-XJNOQ.js","assets/EChartsPieChart-DesdDOd6.js","assets/EChartsBubbleChart-0yKJ8_wS.js","assets/EChartsCustom-CuugBCzb.js"])))=>i.map(i=>d[i]); 2import{c as ce,o as Le,r as o,s as E,j as e,B as S,au as de,av as me,aw as ue,ax as O,g as W,ay as A,a2 as Fe,bu as Oe,bv as Te,bw as Re,aY as Ie,aZ as X,X as Me}from"./index-BBmhd2fr.js";import{A as pe,b as he,c as xe,d as fe,e as ge,f as je,g as be,h as ve}from"./alert-dialog-CJMv-S3Q.js";import{D as _e,b as we,c as Ce,d as ye,f as Ne,g as ze}from"./dialog-Cv-lzPma.js";import{I as ke}from"./input-DJvVat2j.js";import{L as Ue}from"./label-BW6NuIm7.js";import{L as Ve}from"./layers-Bk7ESuhy.js";import{P as Be}from"./plus-1Xviyy_4.js";import{E as Ae}from"./ellipsis-vertical-zuVSocR2.js";import{P as J}from"./pencil-wKHZc1OF.js";import{T as De}from"./trash-2-CXcMbGOS.js";import{F as qe,T as $e}from"./table-Bp8u0LMg.js";import{F as He}from"./folder-D4yu_fyM.js";import{b as q}from"./chartExport-ZbI8p08_.js";import{A as Ke,d as Pe,r as Ze}from"./AIChartFrame-CWNRw1iF.js";import{B as Q}from"./badge-BIx_PAw6.js";import{D as Ee}from"./download-RuZ6PuZu.js";import{F as Ge}from"./folder-input-C8MPUcpH.js";import{E as We}from"./external-link-CehcAQ4A.js";import{f as Xe}from"./format-DwiE_hab.js";import{S as ee,a as te,b as se,c as ae,f as F}from"./select-CEXh0zDM.js";import{P as re}from"./PaginationControls-CLJZ8TF2.js";import{S as ne}from"./search-rphmc9_k.js";import{L as Ye}from"./loader-circle-CtQ_lBrR.js";import{A as Je}from"./archive-CGxKfBFi.js";import"./index-DYm_9zBf.js";import"./marked.esm-Dvg92hr8.js";import"./purify.es-C5KSVp3G.js";import"./image-L9VFLUq1.js";import"./en-US-DVlPbiiU.js";import"./constructFrom-rJN6zrQ_.js";import"./index-BdQq_4o_.js";import"./index-B7nojceh.js";import"./chevron-up-rK4xo6gt.js";import"./chevrons-right-tgMoEmPf.js";import"./chevron-left-BZiYTarP.js";/** 3 * @license lucide-react v0.462.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const Qe=ce("Inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]]);/** 8 * @license lucide-react v0.462.0 - ISC 9 * 10 * This source code is licensed under the ISC license. 11 * See the LICENSE file in the root directory of this source tree. 12 */const Se=ce("Presentation",[["path",{d:"M2 3h20",key:"91anmk"}],["path",{d:"M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3",key:"2k9sn8"}],["path",{d:"m7 21 5-5 5 5",key:"bip4we"}]]);function et(t){return t.split(/[\s_-]+/).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join(" ")}function oe(t){if(t.name&&t.name.trim())return t.name.trim();if(t.db_name){const r=t.db_name.replace(/^altavia_data_/,"").replace(/^altavia_/,"");if(r)return et(r)}return null}function tt(){const{user:t}=Le(),[r,s]=o.useState([]),[i,p]=o.useState([]),[h,b]=o.useState(!0),j=o.useCallback(async()=>{var d,n,T;if(!t)return;b(!0);const[c,l,a]=await Promise.all([E.from("ai_artifact_folders").select("id, name, created_at").order("name",{ascending:!0}),E.from("ai_artifacts").select("id, kind, component, payload, folder_id, name, conversation_id, message_id, created_at, ai_conversations!inner(segment_id, data_sources(name, db_name))").order("created_at",{ascending:!1}),E.from("ai_exports").select("id, kind, status, file_size, slide_count, conversation_id, created_at, completed_at, ai_conversations!inner(title, segment_id, data_sources(name, db_name))").eq("status","ready").order("created_at",{ascending:!1})]);!c.error&&c.data&&s(c.data);const m=[];if(!l.error&&l.data)for(const u of l.data){const C=((d=u.ai_conversations)==null?void 0:d.data_sources)??null;m.push({id:u.id,kind:u.kind,component:u.component,payload:u.payload,folder_id:u.folder_id,name:u.name,conversation_id:u.conversation_id,message_id:u.message_id,created_at:u.created_at,
12segment_label:C?oe(C):null})}if(!a.error&&a.data)for(const u of a.data){const C=((n=u.ai_conversations)==null?void 0:n.data_sources)??null,k=((T=u.ai_conversations)==null?void 0:T.title)??null;m.push({id:u.id,kind:"pptx",component:"PowerPoint",payload:{title:k||"AVIALTA Insights"},folder_id:null,name:k||null,conversation_id:u.conversation_id,message_id:null,created_at:u.created_at,segment_label:C?oe(C):null,export_id:u.id,file_size:u.file_size??void 0,slide_count:u.slide_count??void 0})}m.sort((u,C)=>C.created_at.localeCompare(u.created_at)),p(m),b(!1)},[t]);return o.useEffect(()=>{j()},[j]),{folders:r,artifacts:i,loading:h,refresh:j,createFolder:async c=>{if(!t)return null;const{data:l,error:a}=await E.from("ai_artifact_folders").insert({name:c.trim(),user_id:t.id}).select("id, name, created_at").single();return a||!l?null:(s(m=>[...m,l].sort((d,n)=>d.name.localeCompare(n.name))),l)},renameFolder:async(c,l)=>{const{error:a}=await E.from("ai_artifact_folders").update({name:l.trim()}).eq("id",c);return a?!1:(s(m=>m.map(d=>d.id===c?{...d,name:l.trim()}:d).sort((d,n)=>d.name.localeCompare(n.name))),!0)},deleteFolder:async c=>{const{error:l}=await E.from("ai_artifact_folders").delete().eq("id",c);return l?!1:(s(a=>a.filter(m=>m.id!==c)),p(a=>a.map(m=>m.folder_id===c?{...m,folder_id:null}:m)),!0)},renameArtifact:async(c,l)=>{const a=i.find(d=>d.id===c);if((a==null?void 0:a.kind)==="pptx")return!1;const{error:m}=await E.from("ai_artifacts").update({name:l.trim()}).eq("id",c);return m?!1:(p(d=>d.map(n=>n.id===c?{...n,name:l.trim()}:n)),!0)},moveArtifact:async(c,l)=>{const a=i.find(d=>d.id===c);if((a==null?void 0:a.kind)==="pptx")return!1;const{error:m}=await E.from("ai_artifacts").update({folder_id:l}).eq("id",c);return m?!1:(p(d=>d.map(n=>n.id===c?{...n,folder_id:l}:n)),!0)},deleteArtifact:async c=>{const l=i.find(d=>d.id===c),a=(l==null?void 0:l.kind)==="pptx"?"ai_exports":"ai_artifacts",{error:m}=await E.from(a).delete().eq("id",c);return m?!1:(p(d=>d.filter(n=>n.id!==c)),!0)}}}function $({open:t,onOpenChange:r,title:s,label:i="Name",initialValue:p,confirmLabel:h="Save",onConfirm:b}){const[j,v]=o.useState(p),[x,w]=o.useState(!1);o.useEffect(()=>{t&&v(p)},[t,p]);const f=async()=>{if(j.trim()){w(!0);try{await b(j.trim()),r(!1)}finally{w(!1)}}};return e.jsx(_e,{open:t,onOpenChange:r,children:e.jsxs(we,{className:"sm:max-w-md",children:[e.jsx(Ce,{children:e.jsx(ye,{children:s})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"rename-input",children:i}),e.jsx(ke,{id:"rename-input",value:j,onChange:_=>v(_.target.value),onKeyDown:_=>{_.key==="Enter"&&f()},autoFocus:!0})]}),e.jsxs(Ne,{children:[e.jsx(S,{variant:"outline",onClick:()=>r(!1),disabled:x,children:"Cancel"}),e.jsx(S,{onClick:f,disabled:x||!j.trim(),children:h})]})]})})}function Y({label:t,count:r,icon:s,iconClassName:i,selected:p,onSelect:h,action:b}){return e.jsxs("div",{className:W("group relative grid grid-cols-[16px_1fr_auto] items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors",p?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[e.jsxs("button",{type:"button",onClick:h,className:"contents text-left",children:[e.jsx(s,{className:W("h-4 w-4 shrink-0",i)}),e.jsx("span",{className:"truncate",children:t}),e.jsx("span",{className:W("text-xs text-muted-foreground tabular-nums",b&&"group-hover:opacity-0"),children:r})]}),b&&e.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2",children:b})]})}function st({folders:t,artifacts:r,selected:s,onSelect:i,onCreateFolder:p,onRenameFolder:h,onDeleteFolder:b}){const[j,v]=o.useState(!1),[x,w]=o.useState(null),[f,_]=o.useState(null),D=r.length,c=r.filter(a=>!a.folder_id).length,l=t.reduce((a,m)=>(a[m.id]=r.filter(d=>d.folder_id===m.id).length,a),{});return e.jsxs("aside",{className:"w-44 shrink-0 border-r border-border bg-white dark:bg-background p-2 flex flex-col gap-0.5 overflow-y-auto",children:[e.jsx(Y,{id:"all",label:"All items",count:D,icon:Ve,iconClassName:"text-muted-foreground",selected:s==="all",onSelect:()=>i("all")}),e.jsxs("div",{className:"mt-4 mb-1 flex items-center gap-1 pl-3",children:[e.jsx("h2",{className:"text-xs uppercase tracking-wider text-muted-foreground font-semibold",children:"Folders"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>v(!0),"aria-label":"New folder",children:e.jsx(Be,{className:"h-3.5 w-3.5"})})]}),e.jsx(Y,{id:"unfiled",label:"Unfiled",count:c,icon:Qe,iconClassName:"text-muted-foreground",selected:s==="unfiled",onSelect:()=>i("unfiled")}),t.map(a=>{const m=s===a.id,d=m?qe:He;return e.jsx(Y,{id:a.id,label:a.name,count:l[a.id]??0,icon:d,iconClassName:"text-primary",selected:m,onSelect:()=>i(a.id),action:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100","aria-label":"Folder actions",children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})}),e.jsxs(ue,{align:"end",className:"bg-popover",children:[e.jsxs(O,{onClick:()=>w(a),children:[e.jsx(J,{className:"mr-2 h-4 w-4"})," Rename"]}),e.jsxs(O,{onClick:()=>_(a),className:"text-destructive focus:text-destructive",children:[e.jsx(De,{className:"mr-2 h-4 w-4"})," Delete"]})]})]})},a.id)}),e.jsx($,{open:j,onOpenChange:v,title:"New folder",label:"Folder name",initialValue:"",confirmLabel:"Create",onConfirm:async a=>{await p(a)}}),e.jsx($,{open:!!x,onOpenChange:a=>!a&&w(null),title:"Rename folder",label:"Folder name",initialValue:(x==null?void 0:x.name)??"",onConfirm:async a=>{x&&await h(x.id,a)}}),e.jsx(pe,{open:!!f,onOpenChange:a=>!a&&_(null),children:e.jsxs(he,{children:[e.jsxs(xe,{children:[e.jsx(fe,{children:"Delete folder?"}),e.jsxs(ge,{children:['"',f==null?void 0:f.name,'" will be deleted. The charts and tables inside it will move to Unfiled â they will not be deleted.']})]}),e.jsxs(je,{children:[e.jsx(be,{children:"Cancel"}),e.jsx(ve,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:async()=>{f&&(await b(f.id),s===f.id&&i("all"),_(null))},children:"Delete"})]})]})})]})}const le={EChartsBarChart:o.lazy(()=>A(()=>import("./EChartsBarChart-BM5RwBZm.js"),__vite__mapDeps([0,1,2,3,4,5]))),EChartsLineChart:o.lazy(()=>A(()=>import("./EChartsLineChart-D5FdcpAB.js"),__vite__mapDeps([6,1,2,3,4,5]))),EChartsAreaChart:o.lazy(()=>A(()=>import("./EChartsAreaChart-B1-XJNOQ.js"),__vite__mapDeps([7,1,2,3,4,5]))),EChartsPieChart:o.lazy(()=>A(()=>import("./EChartsPieChart-DesdDOd6.js"),__vite__mapDeps([8,1,2,3,4,5]))),EChartsBubbleChart:o.lazy(()=>A(()=>import("./EChartsBubbleChart-0yKJ8_wS.js"),__vite__mapDeps([9,1,2,3,4,5]))),EChartsCustom:o.lazy(()=>A(()=>import("./EChartsCustom-CuugBCzb.js"),__vite__mapDeps([10,1,2,3,4])))};function at(t){return Ze(t)}
12function rt({open:t,onOpenChange:r,artifact:s,name:i,onDownload:p}){var x,w,f;const h=s.kind==="chart"?le[s.component]??le.EChartsCustom:null,b=((x=s.payload)==null?void 0:x.props)??s.payload,j=(w=s.payload)==null?void 0:w.title,v=((f=s.payload)==null?void 0:f.markdown)??"";return e.jsx(_e,{open:t,onOpenChange:r,children:e.jsxs(we,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsx(Ce,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{variant:"secondary",className:"text-[10px] uppercase tracking-wide",children:s.kind}),e.jsx(ye,{className:"truncate",children:i})]})}),e.jsx("div",{className:"flex-1 overflow-auto -mx-2 px-2",children:s.kind==="chart"&&h?e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"h-96 animate-pulse bg-muted rounded"}),children:e.jsx(Ke,{title:j,children:e.jsx(h,{...b})})}):s.kind==="pptx"?e.jsxs("div",{className:"rounded border border-border bg-card p-8 flex flex-col items-center gap-4 text-center",children:[e.jsx("div",{className:"h-20 w-20 rounded-full bg-gradient-to-br from-[#CA379D] to-[#3170DD] flex items-center justify-center text-white",children:e.jsx(Se,{className:"h-10 w-10"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-lg font-semibold text-foreground",children:j||"PowerPoint deck"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Async-built presentation summarising the chat."})]}),e.jsxs("div",{className:"text-xs text-muted-foreground flex flex-wrap items-center justify-center gap-3",children:[typeof s.slide_count=="number"&&e.jsxs("span",{children:[s.slide_count," slide",s.slide_count===1?"":"s"]}),typeof s.file_size=="number"&&e.jsxs("span",{children:[(s.file_size/1024/1024).toFixed(s.file_size>1024*1024?1:2)," MB"]}),e.jsx("span",{children:new Date(s.created_at).toLocaleDateString()})]}),e.jsx("div",{className:"text-xs text-muted-foreground max-w-md",children:"Previewing a .pptx in the browser isn\\'t practical â click Download to open in PowerPoint, Keynote, or Google Slides. The deck will appear in the archive for 7 days after creation."})]}):e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none rounded border border-border bg-card p-4",dangerouslySetInnerHTML:{__html:at(Pe(v))}})}),e.jsxs(Ne,{className:"gap-2",children:[e.jsx(ze,{asChild:!0,children:e.jsx(S,{variant:"outline",children:"Close"})}),e.jsxs(S,{onClick:p,children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"})," Download"]})]})]})})}const ie={EChartsBarChart:o.lazy(()=>A(()=>import("./EChartsBarChart-BM5RwBZm.js"),__vite__mapDeps([0,1,2,3,4,5]))),EChartsLineChart:o.lazy(()=>A(()=>import("./EChartsLineChart-D5FdcpAB.js"),__vite__mapDeps([6,1,2,3,4,5]))),EChartsAreaChart:o.lazy(()=>A(()=>import("./EChartsAreaChart-B1-XJNOQ.js"),__vite__mapDeps([7,1,2,3,4,5]))),EChartsPieChart:o.lazy(()=>A(()=>import("./EChartsPieChart-DesdDOd6.js"),__vite__mapDeps([8,1,2,3,4,5]))),EChartsBubbleChart:o.lazy(()=>A(()=>import("./EChartsBubbleChart-0yKJ8_wS.js"),__vite__mapDeps([9,1,2,3,4,5]))),EChartsCustom:o.lazy(()=>A(()=>import("./EChartsCustom-CuugBCzb.js"),__vite__mapDeps([10,1,2,3,4])))};function nt(t){var s;if(t.name)return t.name;const r=(s=t.payload)==null?void 0:s.title;return typeof r=="string"&&r.trim()?r.trim():t.kind==="chart"?"Untitled chart":"Untitled table"}function ot({artifact:t}){var i;const r=ie[t.component]??ie.EChartsCustom,s=((i=t.payload)==null?void 0:i.props)??t.payload;return e.jsx("div",{className:"h-16 w-16 shrink-0 rounded border border-border bg-white overflow-hidden pointer-events-none",children:e.jsx("div",{style:{width:320,height:320,transform:"scale(0.2)",transformOrigin:"top left"},children:e.jsx(o.Suspense,{fallback:null,children:e.jsx(r,{...s})})})})}function lt(t,r,s){const i=new Blob([t],{type:s}),p=URL.createObjectURL(i),h=document.createElement("a");h.href=p,h.download=r,h.click(),URL.revokeObjectURL(p)}function it(t){const r=t.split(/\r?\n/).map(i=>i.trim()).filter(i=>i.length>0&&i.includes("|")),s=[];for(const i of r){const p=i.replace(/^\|/,"").replace(/\|$/,"").split("|").map(h=>h.trim());p.every(h=>/^:?-+:?$/.test(h))||s.push(p)}return s}function ct(t){return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function dt(t){return it(t).map(s=>s.map(ct).join(",")).join(` 13`)}function mt(t){var j;const[r,s]=t.split(",",2),i=((j=/data:([^;]+)/.exec(r))==null?void 0:j[1])??"application/octet-stream",p=atob(s),h=p.length,b=new Uint8Array(h);for(let v=0;v<h;
13v++)b[v]=p.charCodeAt(v);return new Blob([b],{type:i})}function ut({artifact:t,folders:r,onRename:s,onMove:i,onDelete:p,onCreateFolderAndMove:h}){const b=Fe(),[j,v]=o.useState(!1),[x,w]=o.useState(!1),[f,_]=o.useState(!1),[D,c]=o.useState(!1),l=nt(t),a=()=>{try{sessionStorage.setItem("ai_activeConvId",t.conversation_id)}catch{}b("/app/ai-insights")},m=async()=>{const n=l.replace(/[\\/:*?"<>|\x00-\x1F]+/g,"").trim().slice(0,80)||"artifact",T=t.payload??{};if(t.kind==="pptx"){const y=t.export_id??t.id;try{const{data:{session:N}}=await E.auth.getSession(),P=N==null?void 0:N.access_token;if(!P)return;const I=await fetch(`https://api.avialta.ai/api/export/powerpoint/${y}`,{headers:{Authorization:`Bearer ${P}`}});if(!I.ok)throw new Error(`HTTP ${I.status}`);const H=await I.blob(),K=I.headers.get("content-disposition")||"",M=/filename="?([^"]+)"?/.exec(K),Z=(M==null?void 0:M[1])||q(n,"pptx"),z=URL.createObjectURL(H),g=document.createElement("a");g.href=z,g.download=Z,g.click(),URL.revokeObjectURL(z)}catch(N){console.warn("[Archive] PPT download failed",N)}return}if(t.kind==="table"){const y=Pe(T.markdown??""),N=dt(y);lt(N,q(n,"csv"),"text/csv;charset=utf-8");return}const u=T.image;if(u!=null&&u.startsWith("data:image/")){const y=mt(u),N=URL.createObjectURL(y),P=document.createElement("a");P.href=N,P.download=q(n,"png"),P.click(),URL.revokeObjectURL(N);return}const C=document.querySelector(`[data-artifact-preview="${t.id}"]`),k=C==null?void 0:C.querySelector("canvas");if(k){const y=document.createElement("a");y.href=k.toDataURL("image/png"),y.download=q(n,"png"),y.click()}else v(!0)},d=n=>n.stopPropagation();return e.jsxs(e.Fragment,{children:[e.jsxs("li",{onClick:()=>v(!0),className:"flex items-center gap-3 px-3 py-2.5 hover:bg-muted/50 cursor-pointer transition-colors",children:[t.kind==="chart"?e.jsx(ot,{artifact:t}):t.kind==="pptx"?e.jsx("div",{className:"h-16 w-16 shrink-0 rounded border border-border bg-gradient-to-br from-[#CA379D] to-[#3170DD] flex items-center justify-center text-white",children:e.jsx(Se,{className:"h-7 w-7"})}):e.jsx("div",{className:"h-16 w-16 shrink-0 rounded border border-border bg-muted flex items-center justify-center",children:e.jsx($e,{className:"h-6 w-6 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium truncate",title:l,children:l}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx(Q,{variant:"secondary",className:"text-[10px] uppercase tracking-wide",children:t.kind}),t.segment_label&&e.jsx(Q,{variant:"outline",className:"text-[10px] font-normal",children:t.segment_label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Xe(new Date(t.created_at),"MMM d, yyyy")})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",onClick:d,children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":"Download",onClick:m,children:e.jsx(Ee,{className:"h-4 w-4"})}),e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":"Actions",children:e.jsx(Ae,{className:"h-4 w-4"})})}),e.jsxs(ue,{align:"end",className:"bg-popover w-52",children:[e.jsxs(O,{onClick:()=>w(!0),children:[e.jsx(J,{className:"mr-2 h-4 w-4"})," Rename"]}),e.jsxs(Oe,{children:[e.jsxs(Te,{children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"})," Move to folder"]}),e.jsxs(Re,{className:"bg-popover w-52 max-h-72 overflow-y-auto",children:[e.jsx(Ie,{className:"text-xs",children:"Folders"}),e.jsx(O,{onClick:()=>i(t.id,null),children:"Unfiled"}),r.length>0&&e.jsx(X,{}),r.map(n=>e.jsx(O,{onClick:()=>i(t.id,n.id),disabled:n.id===t.folder_id,children:n.name},n.id)),e.jsx(X,{}),e.jsxs(O,{onClick:()=>c(!0),children:[e.jsx(J,{className:"mr-2 h-4 w-4"})," New folderâ¦"]})]})]}),e.jsxs(O,{onClick:a,children:[e.jsx(We,{className:"mr-2 h-4 w-4"})," Open in chat"]}),e.jsx(X,{}),e.jsxs(O,{onClick:()=>_(!0),className:"text-destructive focus:text-destructive",children:[e.jsx(De,{className:"mr-2 h-4 w-4"})," Delete"]})]})]})]})]}),e.jsx("div",{"data-artifact-preview":t.id,children:e.jsx(rt,{open:j,onOpenChange:v,artifact:t,name:l,onDownload:m})}),e.jsx($,{open:x,onOpenChange:w,title:"Rename",label:"Name",initialValue:l,onConfirm:async n=>{await s(t.id,n)}}),e.jsx($,{open:D,onOpenChange:c,title:"New folder",label:"Folder name",initialValue:"",confirmLabel:"Create & move",onConfirm:async n=>{await h(n,t.id)}}),e.jsx(pe,{open:f,onOpenChange:_,children:e.jsxs(he,{children:[e.jsxs(xe,{children:[e.jsxs(fe,{children:["Delete this ",t.kind,"?"]}),e.jsxs(ge,{children:['This action cannot be undone. "',l,'" will be permanently removed from your archive.']})]}),e.jsxs(je,{children:[e.jsx(be,{children:"Cancel"}),e.jsx(ve,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:async()=>{await p(t.id),_(!1)},children:"Delete"})]})]})})]})}function U(t){var s;if(t.name)return t.name;const r=(s=t.payload)==null?void 0:s.title;return typeof r=="string"&&r.trim()?r.trim():t.kind==="chart"?"Untitled chart":t.kind==="table"?"Untitled table":"Untitled deck"}function Gt(){var z;const{folders:t,artifacts:r,loading:s,createFolder:i,renameFolder:p,deleteFolder:h,renameArtifact:b,moveArtifact:j,deleteArtifact:v}=tt(),[x,w]=o.useState("all"),[f,_]=o.useState(""),[D,c]=o.useState("all"),[l,a]=o.use
13State("newest"),[m,d]=o.useState(1),[n,T]=o.useState(20);o.useEffect(()=>{d(1)},[x,f,D,l,n]);const u=o.useMemo(()=>x==="all"?r:x==="unfiled"?r.filter(g=>!g.folder_id):r.filter(g=>g.folder_id===x),[r,x]),C=o.useMemo(()=>{const g=f.trim().toLowerCase();let R=u;return g&&(R=R.filter(L=>U(L).toLowerCase().includes(g))),D!=="all"&&(R=R.filter(L=>L.kind===D)),[...R].sort((L,B)=>{switch(l){case"oldest":return L.created_at.localeCompare(B.created_at);case"name_asc":return U(L).localeCompare(U(B));case"name_desc":return U(B).localeCompare(U(L));case"newest":default:return B.created_at.localeCompare(L.created_at)}})},[u,f,D,l]),k=C.length,y=Math.max(1,Math.ceil(k/n)),N=Math.min(m,y),P=(N-1)*n,V=P+n,I=C.slice(P,V),H=x==="all"?"All items":x==="unfiled"?"Unfiled":((z=t.find(g=>g.id===x))==null?void 0:z.name)??"Folder",K=async(g,R)=>{const G=await i(g);G&&await j(R,G.id)},M=f.trim()!==""||D!=="all",Z=()=>{_(""),c("all")};return e.jsxs("div",{className:"flex h-[calc(100vh-4rem)] bg-white dark:bg-background",children:[e.jsx(st,{folders:t,artifacts:r,selected:x,onSelect:w,onCreateFolder:i,onRenameFolder:p,onDeleteFolder:h}),e.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 pt-4 pb-2 text-xs text-muted-foreground",children:[H," · ",k," ",k===1?"item":"items"]}),e.jsxs("div",{className:"px-6 pb-3 flex flex-col sm:flex-row gap-2 sm:items-center",children:[e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(ne,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none"}),e.jsx(ke,{value:f,onChange:g=>_(g.target.value),placeholder:"Search by nameâ¦",className:"h-8 pl-8 pr-8 text-sm"}),f&&e.jsx("button",{type:"button",onClick:()=>_(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground","aria-label":"Clear search",children:e.jsx(Me,{className:"h-4 w-4"})})]}),e.jsxs(ee,{value:D,onValueChange:g=>c(g),children:[e.jsx(te,{className:"h-8 w-[140px] text-sm",children:e.jsx(se,{})}),e.jsxs(ae,{className:"bg-popover z-50",children:[e.jsx(F,{value:"all",children:"Type: All"}),e.jsx(F,{value:"chart",children:"Charts"}),e.jsx(F,{value:"table",children:"Tables"}),e.jsx(F,{value:"pptx",children:"PowerPoints"})]})]}),e.jsxs(ee,{value:l,onValueChange:g=>a(g),children:[e.jsx(te,{className:"h-8 w-[160px] text-sm",children:e.jsx(se,{})}),e.jsxs(ae,{className:"bg-popover z-50",children:[e.jsx(F,{value:"newest",children:"Sort: Newest"}),e.jsx(F,{value:"oldest",children:"Sort: Oldest"}),e.jsx(F,{value:"name_asc",children:"Name AâZ"}),e.jsx(F,{value:"name_desc",children:"Name ZâA"})]})]})]}),!s&&y>1&&e.jsx("div",{className:"px-6 pb-3 border-b border-border/50 mb-1",children:e.jsx(re,{currentPage:N,totalPages:y,totalItems:k,startIndex:P,endIndex:V,onPageChange:d,itemsPerPage:n,showItemsPerPage:!1,itemLabel:"items"})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 pb-6",children:s?e.jsxs("div",{className:"flex items-center justify-center py-20 text-muted-foreground",children:[e.jsx(Ye,{className:"h-5 w-5 animate-spin mr-2"})," Loading your archiveâ¦"]}):k===0?M?e.jsxs("div",{className:"text-center py-20 text-muted-foreground",children:[e.jsx(ne,{className:"h-10 w-10 mx-auto mb-3 opacity-40"}),e.jsx("p",{className:"text-sm mb-3",children:"No items match your search."}),e.jsx(S,{variant:"outline",size:"sm",onClick:Z,children:"Clear filters"})]}):e.jsxs("div",{className:"text-center py-20 text-muted-foreground",children:[e.jsx(Je,{className:"h-10 w-10 mx-auto mb-3 opacity-40"}),e.jsx("p",{className:"text-sm",children:r.length===0?"No saved charts, tables, or decks yet. Artifacts created in the AI chat are automatically archived here.":"Nothing in this folder yet."})]}):e.jsx("ul",{className:"divide-y divide-border border border-border rounded-md bg-white dark:bg-background overflow-hidden",children:I.map(g=>e.jsx(ut,{artifact:g,folders:t,onRename:b,onMove:j,onDelete:v,onCreateFolderAndMove:K},g.id))})}),!s&&k>0&&e.jsx("div",{className:"border-t border-border px-6 py-3 bg-white dark:bg-background",children:e.jsx(re,{currentPage:N,totalPages:y,totalItems:k,startIndex:P,endIndex:V,onPageChange:d,itemsPerPage:n,onItemsPerPageChange:T,pageSizeOptions:[10,20,50,100],showItemsPerPage:!0,itemLabel:"items"})})]})]})}export{Gt as default};
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.