import{r as c,j as t}from"./query-Bw69rE6b.js";import{d as j,p as k,c as b,X as y}from"./index-CoUu6FiM.js";import{g as N}from"./usePages-D5h-FCve.js";import{U as D}from"./upload-DvIhupK8.js";/**
 * @license lucide-react v0.577.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const A=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]],E=j("file",A),S=[".xlsx",".eml",".md",".markdown",".txt",".pdf",".docx",".doc",".html",".htm",".csv",".tsv",".json",".yaml",".yml",".rst"];function T({pageId:u,sources:r,onChange:d}){const n=N(u),i=c.useRef(null),[p,l]=c.useState(!1),[m,x]=c.useState(null);async function f(e){x(null);const a=[...r];for(const o of Array.from(e))try{const s=await n.mutateAsync(o);a.push(s)}catch(s){x(s.message||`Upload failed for ${o.name}`);break}d(a)}function h(e){e.preventDefault(),l(!1),e.dataTransfer.files&&e.dataTransfer.files.length>0&&f(e.dataTransfer.files)}function g(e){e.target.files&&e.target.files.length>0&&f(e.target.files),e.target.value=""}function v(e){const a=r.filter((o,s)=>s!==e);d(a)}return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{onDragOver:e=>{e.preventDefault(),l(!0)},onDragLeave:()=>l(!1),onDrop:h,onClick:()=>i.current?.click(),role:"button",tabIndex:0,onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&i.current?.click()},className:b("flex h-24 cursor-pointer items-center justify-center gap-2 rounded-md border border-dashed px-3 text-center transition-colors",p?"border-accent bg-accent-soft/40":"border-border bg-surface hover:border-accent/40 hover:bg-surface-subtle"),children:[n.isPending?t.jsx(k,{size:14,className:"animate-spin text-ink-dim"}):t.jsx(D,{size:14,className:"text-ink-dim"}),t.jsxs("div",{className:"text-left",children:[t.jsx("div",{className:"text-xs font-medium text-ink",children:n.isPending?"Uploading...":"Drop files or click to browse"}),t.jsx("div",{className:"text-[10px] text-ink-dim",children:".xlsx · .pdf · .docx · .md · .csv · .json · .yaml · .html · .eml"})]})]}),t.jsx("input",{ref:i,type:"file",multiple:!0,accept:S.join(","),onChange:g,className:"hidden"}),m&&t.jsx("div",{className:"text-[11px] text-critical",children:m}),r.length===0?t.jsx("p",{className:"text-[11px] text-ink-dim",children:"No sources attached yet."}):t.jsx("ul",{className:"space-y-1",children:r.map((e,a)=>t.jsxs("li",{className:"flex items-center gap-2 rounded px-1 py-1 text-sm hover:bg-surface-subtle",children:[t.jsx(E,{size:13,className:"shrink-0 text-ink-dim"}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-ink",title:e.original_name,children:e.original_name}),t.jsx("button",{type:"button",onClick:()=>v(a),"aria-label":`Remove ${e.original_name}`,className:"shrink-0 rounded p-1 text-ink-dim hover:bg-surface hover:text-critical",children:t.jsx(y,{size:12})})]},`${e.path}-${a}`))})]})}export{T as S};
