1import{ar as ie,ay as le,Z as oe,k as t,j as a,B as o,ac as I,az as de,aA as ce,w as V,a2 as Q,aB as ue,E as me,a1 as K,aC as pe,L as xe,a5 as he,aj as fe,a6 as be,r as ge,aD as X,i as ve,D as je}from"./index-t-vObaAn.js";import{T as ye}from"./tabs-B9OeMP14.js";import{u as we,s as Ce}from"./use-documents-Bth6oDoZ.js";import{U as Ne}from"./upload-status-BPEqsUrf.js";import{a as Ae}from"./document-detail-BG62Xp4s.js";import{selectDocuments as ke}from"./document-state-Bn5orut4.js";import{q as De}from"./home-chat-handoff-Dj31j5A7.js";import"./history-back-button-1JmUnwyS.js";function W(s){return s==="application/pdf"?"PDF":s.includes("wordprocessingml")?"DOCX":s==="text/plain"?"Text":s==="text/markdown"?"Markdown":s==="text/csv"?"CSV":s.split("/").pop()?.toUpperCase()??s}function Se({userId:s,tab:c="all",onTabChange:v,onAsk:w}){const n=ie(),u=le(),{upload:Y}=we(),Z=oe(),C=t.useRef(null),[N,G]=t.useState(""),[A,J]=t.useState(!1),[m,L]=t.useState(""),[p,z]=t.useState(""),[d,E]=t.useState(""),[j,ee]=t.useState("newest"),[R,U]=t.useState([]),[ae,k]=t.useState(!1),[F,P]=t.useState([]),[y,_]=t.useState(!1),[O,B]=t.useState(""),[M,te]=t.useState([]),i=n.data??[];t.useEffect(()=>{Ce(i)},[i]);const x=u.data?.enabled===!0,D=!n.isPending&&!n.isError&&i.length===0,H=[m,p,d].filter(Boolean).length,h=i.filter(e=>R.includes(e.id)),$=t.useMemo(()=>i.filter(e=>(c==="all"||(c==="mine"?e.ownerId===s:e.access==="workspace"))&&e.name.toLocaleLowerCase().includes(N.toLocaleLowerCase())&&(!m||e.mediaType===m)&&(!p||e.ownerId===p)&&(!d||(d==="off"?!e.availableToAi&&e.status==="ready":d==="ready"?e.status==="ready"&&e.availableToAi:e.status===d))).sort((e,r)=>j==="name"?e.name.localeCompare(r.name):j==="updated"?r.updatedAt.localeCompare(e.updatedAt):r.createdAt.localeCompare(e.createdAt)),[i,c,s,N,m,p,d,j]),q=e=>{u.data?.enabled&&Y(e,"hub",u.data)},se=e=>{w?.(e)},S=async(e,r=!1)=>{_(!0),B("");const T=r?M:h.filter(l=>l.canManage).map(l=>({id:l.id,availableToAi:e})),f=[];let b=0;const{appFetch:ne}=await fe(async()=>{const{appFetch:l}=await import("./index-t-vObaAn.js").then(g=>g.ee);return{appFetch:l}},[]);for(const l of T)try{await ne(`/api/documents/${encodeURIComponent(l.id)}`,{method:"PATCH",body:{availableToAi:l.availableToAi}});const g=i.find(re=>re.id===l.id);g&&f.push({id:g.id,availableToAi:g.availableToAi})}catch{b+=1}te(r?[]:f),B(b?`${b} documents could not be updated. Retry those documents.`:"AI availability updated."),await Z.invalidateQueries({queryKey:be.documents}),_(!1)};return a.jsxs("div",{className:"relative flex h-full min-h-0 flex-col bg-background",onDragOver:e=>{e.dataTransfer.types.includes("Files")&&(e.preventDefault(),x&&k(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||k(!1)},onDrop:e=>{e.preventDefault(),k(!1),q(Array.from(e.dataTransfer.files))},children:[a.jsxs("div",{className:V("shrink-0 space-y-4 border-b border-border py-4",Q),children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("h1",{"data-app-route-heading":!0,className:"text-xl font-semibold text-foreground",children:"Documents"}),a.jsx("p",{className:"mt-1 text-[13px] leading-5 text-muted-foreground",children:"Your documents, ready for your AI."})]}),D?null:a.jsxs(o,{size:"sm",disabled:!x,onClick:()=>C.current?.click(),children:[a.jsx(I,{icon:de,size:16}),"Upload files"]})]}),a.jsx("input",{ref:C,type:"file",multiple:!0,accept:u.data?.extensions.join(","),className:"hidden","aria-label":"Upload documents",onChange:e=>{q(Array.from(e.target.files??[])),e.target.value=""}}),D?null:a.jsxs(a.Fragment,{children:[a.jsx(ye,{tabs:[{id:"all",label:"All documents"},{id:"mine",label:"Mine"},{id:"shared",label:"Shared"}],activeTab:c,onChange:e=>v?.(e),ariaLabel:"Document views",idBase:"documents"}),a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsxs("div",{className:"flex h-8 min-w-0 flex-1 items-center gap-2 rounded-[10px] border border-border bg-card/40 px-2.5 focus-within:border-ring focus-within:ring-1 focus-within:ring-ring/40",children:[a.jsx(I,{icon:ce,size:16,className:"text-muted-foreground"}),a.jsx("input",{"aria-label":"Search documents",placeholder:"Search documentsâ¦",value:N,onChange:e=>
1G(e.target.value),className:"h-full min-w-0 w-full bg-transparent text-[13px] outline-none placeholder:text-muted-foreground"})]}),a.jsxs(o,{variant:"outline",size:"sm","aria-expanded":A,onClick:()=>J(!A),children:["Filters",H>0?a.jsx("span",{className:"ml-1 rounded bg-muted px-1.5 text-[11px]",children:H}):null]}),a.jsxs("select",{"aria-label":"Sort documents",value:j,onChange:e=>ee(e.target.value),className:"h-8 rounded-md border border-border bg-background px-2 text-xs",children:[a.jsx("option",{value:"newest",children:"Recently added"}),a.jsx("option",{value:"updated",children:"Recently updated"}),a.jsx("option",{value:"name",children:"Name"})]})]}),A?a.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.jsxs("select",{"aria-label":"File type",value:m,onChange:e=>L(e.target.value),className:"h-8 rounded-md border border-border bg-background px-2 text-xs",children:[a.jsx("option",{value:"",children:"All file types"}),[...new Set(i.map(e=>e.mediaType))].map(e=>a.jsx("option",{value:e,children:W(e)},e))]}),a.jsxs("select",{"aria-label":"Owner",value:p,onChange:e=>z(e.target.value),className:"h-8 rounded-md border border-border bg-background px-2 text-xs",children:[a.jsx("option",{value:"",children:"All owners"}),[...new Map(i.map(e=>[e.ownerId,e.ownerName])).entries()].map(([e,r])=>a.jsx("option",{value:e,children:r},e))]}),a.jsxs("select",{"aria-label":"AI availability",value:d,onChange:e=>E(e.target.value),className:"h-8 rounded-md border border-border bg-background px-2 text-xs",children:[a.jsx("option",{value:"",children:"All states"}),a.jsx("option",{value:"ready",children:"Available"}),a.jsx("option",{value:"off",children:"Off"}),a.jsx("option",{value:"processing",children:"Processing"}),a.jsx("option",{value:"failed",children:"Needs attention"})]}),a.jsx(o,{variant:"ghost",size:"sm",onClick:()=>{L(""),z(""),E("")},children:"Clear filters"})]}):null]}),O?a.jsxs("p",{className:"text-xs text-muted-foreground",role:"status",children:[O,M.length>0?a.jsx(o,{variant:"ghost",size:"xs",className:"ml-2",disabled:y,onClick:()=>{S(!1,!0)},children:"Undo"}):null]}):null,h.length>0?a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsxs("span",{className:"text-xs text-muted-foreground",children:[h.length," selected"]}),a.jsx(o,{size:"xs",variant:"outline",disabled:y,onClick:()=>se(h),children:"Ask AI"}),a.jsx(o,{size:"xs",variant:"outline",disabled:y,onClick:()=>{S(!0)},children:"Make available"}),a.jsx(o,{size:"xs",variant:"outline",disabled:y,onClick:()=>{S(!1)},children:"Turn off"}),a.jsx(o,{size:"xs",variant:"ghost",className:"text-destructive",onClick:()=>P(h),children:"Delete"})]}):null,a.jsx(Ne,{origin:"hub"})]}),a.jsxs("div",{"data-scroll-restoration-id":"dashboard-primary-scroll",className:V("min-h-0 flex-1 overflow-y-auto overscroll-contain py-4",Q),children:[ae?a.jsx("div",{className:"mb-4 rounded-xl border border-dashed border-ring bg-muted/20 px-4 py-6 text-center text-sm text-muted-foreground",children:"Drop files to upload"}):null,n.isPending?a.jsx(ue,{label:"Loading documents",rows:6}):n.isError?a.jsx(me,{title:"Documents could not load",onRetry:()=>{n.refetch()}}):D?a.jsx(K,{icon:a.jsx(I,{icon:pe,size:24,"aria-hidden":"true"}),title:x?"No documents yet":"Documents are not available yet",description:x?"Upload a PDF, DOCX, Markdown, text, or CSV file to get started.":"Document uploads are not available on this server yet.",action:x?a.jsx(o,{onClick:()=>C.current?.click(),children:"Upload files"}):void 0}):$.length===0?a.jsx(K,{title:"No matching documents",description:"Try a different search or clear filters."}):a.jsx("ul",{className:"divide-y divide-border/60 rounded-xl border border-border/60",children:$.map(e=>{const r=R.includes(e.id);return a.jsxs("li",{className:"flex items-center gap-3 px-3 py-3",children:[a.jsx("input",{type:"checkbox",checked:r,"aria-label":`Select ${e.name}`,onChange:T=>U(f=>T.target.checked?[...f,e.id]:f.filter(b=>b!==e.id))}),a.jsxs(xe,{to:"/app/documents/$documentId",params:{documentId:e.id},className:"min-w-0 flex-1 rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[a.jsx("p",{className:"truncate text-sm font-medium",children:e.name}),a.jsxs("p",{className:"truncate text-[11px] text-muted-foreground",children:[e.ownerName," · ",W(e.mediaType)," ·"," ",he(e)]})]})]},e.id)})})]}),F.length>0?a.jsx(Ae,{documents:F,onClose:()=>{P([]),U([])}}):null]})}function Pe(){const s=ge(X.useRouteContext()),{tab:c}=X.useSearch(),v=ve();function w(n){ke(n),De({kind:"message",payload:{message:`Use ${n.map(u=>u.name).join(", ")}
1 as sources and answer from them.`,webSearch:!1,attachments:[],pastedTexts:[]}}),v({to:"/app"})}return a.jsx(je,{title:"Documents",children:a.jsx(Se,{userId:s?.user?.id??"",tab:c??"all",onTabChange:n=>{v({to:"/app/documents",search:{tab:n==="all"?void 0:n},replace:!0})},onAsk:w})})}export{Pe as component};
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.