import{o as e}from"./chunk-CMxvf4Kt.js";import{i as t,o as n}from"./bundle-mjs-NviOedTj.js";import{j as r}from"./auth-kryaWyOt.js";import{Bn as i,Gn as a,Kn as o,Wn as s,zn as c}from"./settings-DtMTlq96.js";import{et as l,n as u}from"./react-BDcLiltL.js";import{S as d,d as f,g as p}from"./rag-api-Bcs3XTYV.js";var m=e(n(),1),h=t();function g({projectId:e}){let t=(0,m.useRef)(null),n=(0,m.useCallback)(()=>p(e),[e]),{documents:g,loading:_,uploading:v,refresh:y,upload:b,remove:x}=c({type:`project`,projectId:e},n),S=(0,m.useCallback)(async t=>{t.length!==0&&(f(e),await b(t),f(e))},[e,b]),C=(0,m.useCallback)(async t=>{f(e),await x(t),f(e)},[e,x]),w=(0,m.useCallback)(()=>{f(e),y({quiet:!0})},[e,y]);(0,m.useEffect)(()=>d(e,()=>{y({quiet:!0})}),[e,y]);let T=g.length===0;return(0,h.jsxs)(`div`,{className:`mt-8`,onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),S(Array.from(e.dataTransfer.files??[]))},children:[(0,h.jsx)(`input`,{ref:t,type:`file`,multiple:!0,accept:a,className:`hidden`,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,S(t)}}),(0,h.jsx)(`div`,{className:`mb-4 rounded-[22px] bg-muted/30 px-5 py-4`,children:(0,h.jsx)(i,{scope:{type:`project`,id:e},compact:!0,onSourcesChanged:w})}),T?(0,h.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 rounded-[26px] bg-muted/30 px-6 py-16 text-center`,children:[(0,h.jsx)(`span`,{className:`flex size-12 items-center justify-center rounded-full bg-muted text-muted-foreground`,children:(0,h.jsx)(u,{icon:l,strokeWidth:1.75,className:`size-6`})}),(0,h.jsxs)(`div`,{className:`space-y-1`,children:[(0,h.jsx)(`p`,{className:`text-ui-15 font-semibold text-foreground`,children:`Give this project context`}),(0,h.jsx)(`p`,{className:`max-w-sm text-sm text-muted-foreground`,children:`Upload PDFs, docs, or text. Every chat in this project can use them.`})]}),(0,h.jsx)(r,{type:`button`,variant:`outline`,className:`mt-1 border-none bg-background text-foreground shadow-[0_2px_8px_-2px_rgba(0,0,0,0.16)] hover:bg-background/80 dark:bg-card dark:shadow-none dark:hover:bg-accent/50`,disabled:v||_,onClick:()=>t.current?.click(),children:`Add sources`}),(0,h.jsx)(`p`,{className:`text-ui-11 text-muted-foreground`,children:`Or drop files here`})]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-[26px] bg-muted/30 px-6 py-5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,h.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:g.length===1?`1 source`:`${g.length} sources`}),(0,h.jsx)(r,{type:`button`,size:`sm`,variant:`outline`,className:`border-none bg-background text-foreground shadow-[0_2px_8px_-2px_rgba(0,0,0,0.16)] hover:bg-background/80 dark:bg-card dark:shadow-none dark:hover:bg-accent/50`,disabled:v,onClick:()=>t.current?.click(),children:`Add sources`})]}),(0,h.jsx)(`div`,{className:`flex flex-row flex-wrap items-center gap-1.5`,children:g.map(e=>(0,h.jsx)(s,{filename:e.filename,status:e.status,progress:e.progress,error:e.error,onRemove:e.id.startsWith(`pending_`)||o(e)?void 0:()=>void C(e.id)},e.id))})]})]})}export{g as ProjectSourcesPanel};