"use client"
import{a as w}from"./chunk-CB5EAH4A.mjs";import{a as N,m as t}from"./chunk-QXN35W2L.mjs";import{cva as V}from"class-variance-authority";import{UploadCloud as k}from"lucide-react";import{useState as x}from"react";import{toast as D}from"sonner";import{Fragment as I,jsx as r,jsxs as g}from"react/jsx-runtime";var u={any:{types:[]},images:{types:["image/png","image/jpeg"],errorMessage:"File type not supported (.png or .jpg only)"},csv:{types:["text/csv"],errorMessage:"File type not supported (.csv only)"}},H=V("group relative isolate flex aspect-[1200/630] w-full flex-col items-center justify-center overflow-hidden bg-white transition-all hover:bg-gray-50",{variants:{variant:{default:"rounded-md border border-gray-300 shadow-sm",plain:""}},defaultVariants:{variant:"default"}});function X({readFile:h,onChange:a,variant:P,className:R,iconClassName:U,previewClassName:j,accept:n="any",imageSrc:p,loading:z=!1,clickToUpload:c=!0,showHoverOverlay:A=!0,content:f,maxFileSizeMB:d=0,targetResolution:m,accessibilityLabel:E="File upload",disabled:o=!1}){let[y,i]=x(!1),[L,M]=x(null),v=async e=>{let s="dataTransfer"in e?e.dataTransfer.files&&e.dataTransfer.files[0]:e.target.files&&e.target.files[0];if(!s)return;if(M(s.name),d>0&&s.size/1024/1024>d){D.error(`File size too big (max ${d} MB)`);return}let F=u[n].types;if(F.length&&!F.includes(s.type)){D.error(u[n].errorMessage??"File type not supported");return}if(m){let l=await N(s,m);a==null||a({src:l,file:s});return}if(h){let l=new FileReader;l.onload=T=>{var b;return a==null?void 0:a({src:(b=T.target)==null?void 0:b.result,file:s})},l.readAsDataURL(s);return}a==null||a({file:s})};return g("label",{className:t(H({variant:P}),o?"cursor-not-allowed":t(c&&"cursor-pointer"),R),children:[z&&r("div",{className:"absolute inset-0 z-[5] flex items-center justify-center rounded-[inherit] bg-white",children:r(w,{})}),r("div",{className:"absolute inset-0 z-[5]",onDragOver:e=>{e.preventDefault(),e.stopPropagation(),i(!0)},onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),i(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),i(!1)},onDrop:async e=>{e.preventDefault(),e.stopPropagation(),v(e),i(!1)}}),g("div",{className:t("absolute inset-0 z-[3] flex flex-col items-center justify-center rounded-[inherit] bg-white transition-all",o&&"bg-gray-50",y&&!o&&"cursor-copy border-2 border-black bg-gray-50 opacity-100",p?t("opacity-0",A&&!o&&"group-hover:opacity-100"):t(!o&&"group-hover:bg-gray-50")),children:[r(k,{className:t("size-7 transition-all duration-75",o?"text-gray-400":t("text-gray-500 group-hover:scale-110 group-active:scale-95",y?"scale-110":"scale-100"),U)}),f!==null&&r("div",{className:t("mt-2 text-center text-sm text-gray-500",o&&"text-gray-400"),children:f??r(I,{children:g("p",{children:["Drag and drop ",c&&"or click"," to upload."]})})}),r("span",{className:"sr-only",children:E})]}),p&&r("img",{src:p,alt:"Preview",className:t("h-full w-full rounded-[inherit] object-cover",j)}),c&&r("div",{className:"sr-only mt-1 flex shadow-sm",children:r("input",{type:"file",accept:u[n].types.join(","),onChange:v,disabled:o},L)})]})}export{X as a};
