1import{bZ as D,bm as a,b8 as e}from"./index-D8Qj6vox.js";function v(n){return n<1024*1024?`${Math.round(n/1024)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function R({label:n,accept:b,maxBytes:d,onUpload:x,existingFileLabel:f}){const{t:r}=D(),g=a.useId(),c=a.useRef(null),[l,o]=a.useState({status:"idle"}),[w,m]=a.useState(!1),u=a.useCallback(s=>{if(s.type!=="application/pdf"){o({status:"error",message:r("fileUpload.onlyPdf")});return}if(s.size>d){o({status:"error",message:r("fileUpload.tooLarge",{size:v(d)})});return}o({status:"uploading",progress:0}),x(s,t=>{o({status:"uploading",progress:t})}).then(t=>{o({status:"success",textLength:t.text_length})}).catch(t=>{const p=t instanceof Error?t.message:r("fileUpload.uploadFailed");o({status:"error",message:p})})},[d,x,r]),j=a.useCallback(s=>{var p;const t=(p=s.target.files)==null?void 0:p[0];t&&u(t),s.target.value=""},[u]),y=a.useCallback(s=>{s.preventDefault(),m(!1);const t=s.dataTransfer.files[0];t&&u(t)},[u]),k=a.useCallback(s=>{s.preventDefault(),m(!0)},[]),N=a.useCallback(()=>{m(!1)},[]),C=a.useCallback(s=>{var t;(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),(t=c.current)==null||t.click())},[]),h=a.useCallback(()=>{o({status:"idle"}),setTimeout(()=>{var s;return(s=c.current)==null?void 0:s.click()},0)},[]),i=l.status==="uploading";return e.jsxs("div",{className:"w-full",children:[f&&l.status!=="success"&&e.jsxs("p",{className:"mb-3 text-body-sm text-emerald-400 flex items-center gap-1.5",children:[e.jsx("svg",{"aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4 shrink-0",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm3.857-9.809a.75.75 0 0 0-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 1 0-1.06 1.061l2.5 2.5a.75.75 0 0 0 1.137-.089l4-5.5Z",clipRule:"evenodd"})}),f]}),l.status==="success"&&e.jsxs("div",{className:"rounded-xl border border-emerald-500/30 bg-emerald-500/15 p-4 flex items-start gap-3",children:[e.jsx("svg",{"aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-5 w-5 text-emerald-400 shrink-0 mt-0.5",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm3.857-9.809a.75.75 0 0 0-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 1 0-1.06 1.061l2.5 2.5a.75.75 0 0 0 1.137-.089l4-5.5Z",clipRule:"evenodd"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-body-sm font-medium text-foreground",children:r("fileUpload.processed",{label:n,chars:l.textLength.toLocaleString()})}),e.jsx("button",{type:"button",onClick:h,className:"mt-1 text-caption text-emerald-400 underline underline-offset-2 hover:text-emerald-400 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded",children:r("fileUpload.uploadDifferent")})]})]}),l.status==="error"&&e.jsxs("div",{role:"alert",className:"rounded-xl border border-destructive/30 bg-destructive/10 p-4 flex items-start gap-3 mb-3",children:[e.jsx("svg",{"aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-5 w-5 text-destructive shrink-0 mt-0.5",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 1 1-16 0 8 8 0 0 1 16 0Zm-8-5a.75.75 0 0 1 .75.75v4.5a.75.75 0 0 1-1.5 0v-4.5A.75.75 0 0 1 10 5Zm0 10a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z",clipRule:"evenodd"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-body-sm text-destructive",children:l.message}),e.jsx("button",{type:"button",onClick:h,className:"mt-1 text-caption text-destructive underline underline-offset-2 hover:text-destructive/80 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded",children:r("fileUpload.tryAgain")})]})]}),l.status!=="success"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:c,id:g,type:"file",accept:b,"aria-label":n,className:"sr-only",onChange:j,disabled:i}),e.jsxs("div",{role:"button",tabIndex:i?-1:0,"aria-label":r("fileUpload.clickOrDrag",{label:n}),"aria-disabled":i,onDrop:y,onDragOver:k,onDragLeave:N,onKeyDown:C,onClick:()=>{var s;return!i&&((s=c.current)==null?void 0:s.click())},className:["group relative flex flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed bg-secondary px-6 py-10 text-center transition-colors cursor-pointer",w?"border-primary/40 bg-accent":"border-border hover:border-primary/40 hover:bg-accent",i?"cursor-not-allowed opacity-70":""].filter(
1Boolean).join(" "),children:[e.jsx("svg",{"aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,className:"h-10 w-10 text-primary transition-transform duration-300 group-hover:-translate-y-0.5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-body-sm font-medium text-foreground",children:r(i?"fileUpload.uploading":"fileUpload.dragDrop")}),e.jsx("p",{className:"mt-1 text-caption text-muted-foreground",children:r("fileUpload.pdfMax",{size:v(d)})})]}),i&&e.jsxs("div",{className:"w-full max-w-xs","aria-label":r("fileUpload.uploadProgress"),children:[e.jsx("div",{className:"h-2 w-full rounded-full bg-border overflow-hidden",children:e.jsx("div",{role:"progressbar","aria-valuenow":l.progress,"aria-valuemin":0,"aria-valuemax":100,className:"h-2 rounded-full bg-primary transition-all duration-200",style:{width:`${l.progress}%`}})}),e.jsxs("p",{className:"mt-1 text-caption text-primary text-center tabular-nums",children:[l.progress,"%"]})]})]}),e.jsx("label",{htmlFor:g,className:"sr-only",children:n})]})]})}export{R as F};
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.