import{r as d,j as e,B as x,w as c,t as D}from"./index-Cc987VYg.js";import{U as E}from"./upload-Bv3KwMlO.js";import{X as b}from"./separator-D14BnWPe.js";const P=d.forwardRef(({value:r,onChange:m,accept:i,maxSize:f=10,disabled:s=!1,error:a,variant:k="drag-drop",label:u="Upload file",description:h,className:g,id:j},F)=>{const n=d.useRef(null),[N,p]=d.useState(!1);d.useImperativeHandle(F,()=>n.current);const w=t=>{const o=t.target.files?.[0];o&&y(o)},y=t=>{if(t.size/1048576>f){D.error(`File size exceeds ${f}MB limit`);return}if(i){const R=i.split(",").map(l=>l.trim()),U=`.${t.name.split(".").pop()?.toLowerCase()}`;if(!R.some(l=>l===U||l.includes("*")&&t.type.startsWith(l.replace("/*","")))){D.error(`File type not accepted. Accepted types: ${i}`);return}}m?.(t)},B=t=>{t.preventDefault(),t.stopPropagation(),s||p(!0)},C=t=>{t.preventDefault(),t.stopPropagation(),p(!1)},z=t=>{if(t.preventDefault(),t.stopPropagation(),p(!1),s)return;const o=t.dataTransfer.files?.[0];o&&y(o)},v=()=>{m?.(null),n.current&&(n.current.value="")},A=()=>{n.current?.click()};return k==="drag-drop"?e.jsxs("div",{className:c("w-full",g),children:[e.jsxs("div",{onDragOver:B,onDragLeave:C,onDrop:z,className:c("relative flex flex-col items-center justify-center gap-2","rounded-md border border-dashed px-6 py-[30px]","transition-colors cursor-pointer",N&&"border-primary bg-primary/5",s&&"opacity-50 cursor-not-allowed",a&&"border-destructive",!N&&!a&&"border-[#6A7186] bg-[#EAF4F2]"),onClick:()=>!s&&n.current?.click(),style:{borderStyle:"dashed"},children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-full border-2 border-[#333333]",children:e.jsx(E,{className:"h-4 w-4 text-[#333333]"})}),e.jsxs("div",{className:"flex flex-col items-center gap-1 text-center",children:[e.jsx("p",{className:"font-['Quicksand'] text-lg font-semibold leading-[150%] text-[#000000]",children:u}),h&&e.jsx("p",{className:"text-sm text-muted-foreground",children:h}),!r&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Drag and drop or click to browse"})]}),e.jsx("input",{ref:n,id:j,type:"file",accept:i,onChange:w,disabled:s,className:"hidden"}),r&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-background px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium",children:r.name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",(r.size/1024).toFixed(2)," KB)"]}),e.jsx(x,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5",onClick:t=>{t.stopPropagation(),v()},children:e.jsx(b,{className:"h-3 w-3"})})]})]}),a&&e.jsx("p",{className:"mt-1 text-sm text-destructive",children:a})]}):e.jsxs("div",{className:c("w-full",g),children:[e.jsxs("div",{className:c("flex items-center gap-2.5 rounded-[44px] border border-[#DDDDDD]","py-1 pl-4 pr-1","transition-colors",s&&"opacity-50 cursor-not-allowed"),children:[e.jsx("div",{className:"flex-1 min-w-0",children:r?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:r.name}),e.jsxs("span",{className:"text-xs text-muted-foreground shrink-0",children:["(",(r.size/1024).toFixed(2)," KB)"]}),e.jsx(x,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0",onClick:v,disabled:s,children:e.jsx(b,{className:"h-3 w-3"})})]}):e.jsx("span",{className:"text-sm text-muted-foreground",children:u})}),e.jsx(x,{type:"button",onClick:A,disabled:s,className:c("h-11 rounded-[44px] !bg-[#000000] px-4 py-2.5","font-['Quicksand'] text-base font-bold leading-[150%] !text-white","shadow-[0px_1px_2px_0px_rgba(16,24,40,0.05)]","hover:!bg-[#000000]/90 hover:!text-white","dark:!bg-[#000000] dark:!text-white dark:hover:!bg-[#000000]/90"),children:"Browse"}),e.jsx("input",{ref:n,id:j,type:"file",accept:i,onChange:w,disabled:s,className:"hidden"})]}),a&&e.jsx("p",{className:"mt-1 text-sm text-destructive",children:a})]})});P.displayName="FileUpload";export{P as F};
