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