"use client"
import{a as D}from"./chunk-2AVTXLJA.mjs";import{a as x}from"./chunk-LFIJPVK5.mjs";import{a as N,m as t}from"./chunk-NGCWPE34.mjs";import{cva as I}from"class-variance-authority";import{useState as P}from"react";import{toast as R}from"sonner";import{Fragment as G,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)"}},O=I("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:j,iconClassName:A,previewClassName:E,customPreview:T,accept:c="any",imageSrc:d,loading:L=!1,clickToUpload:g=!0,showHoverOverlay:M=!0,content:v,maxFileSizeMB:u=0,targetResolution:b,accessibilityLabel:V="File upload",disabled:s=!1}){let[F,l]=P(!1),[k,H]=P(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(H(a.name),u>0&&a.size/1024/1024>u){R.error(`File size too big (max ${u} MB)`);return}let w=m[c].types;if(w.length&&!w.includes(a.type)){R.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(O({variant:z}),s?"cursor-not-allowed":t(g&&"cursor-pointer"),j),children:[L&&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] border-2 border-transparent bg-white transition-all",s&&"bg-gray-50",F&&!s&&"cursor-copy border-black bg-gray-50 opacity-100",d?t("opacity-0",M&&!s&&"group-hover:opacity-100"):t(!s&&"group-hover:bg-gray-50")),children:[r(D,{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"),A)}),v!==null&&r("div",{className:t("mt-2 text-center text-sm text-gray-500",s&&"text-gray-400"),children:v??r(G,{children:y("p",{children:["Drag and drop ",g&&"or click"," to upload."]})})}),r("span",{className:"sr-only",children:V})]}),d&&(T??r("img",{src:d,alt:"Preview",className:t("h-full w-full rounded-[inherit] object-cover",E)})),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},k)})]})}export{X as a};
