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