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