import{s as e}from"./rolldown-runtime-C5c2KzVm.js";import{$P as t,W_ as n,dl as r,qn as i,u as a}from"./lucide-C4oWPzu4.js";import{i as o,t as s}from"./utils-Bs-0X7qI.js";import{r as c}from"./bundle-mjs-C4g7ASB5.js";import{l}from"./shared-DtQmrU00.js";import{t as u}from"./dist-CImBN8k_.js";import{r as d,t as f}from"./button-B-NlEi4h.js";import{a as p}from"./upload-CYAEccK7.js";var m=e(t(),1),h=c(),g=u(`relative flex cursor-pointer items-center justify-center  border border-dashed transition-all aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 aria-invalid:ring-[3px]`,{variants:{variant:{default:`border-muted-foreground/25 bg-muted/50 hover:bg-muted`,outline:`border-border bg-background`},size:{sm:`size-16`,default:`size-20`,lg:`size-24`,xl:`size-32`},shape:{circle:`rounded-full`,rounded:`rounded-lg`}},defaultVariants:{variant:`default`,size:`default`,shape:`rounded`}});function _({className:e,variant:t,size:c,shape:u,value:_,defaultValue:v,disabled:y,accept:b=`image/*`,maxSize:x=5*1024*1024,placeholder:S,onChange:C,onUploadStart:w,onUploadError:T,forceMobile:E=!1}){let[D,O]=m.useState(v),[k,A]=m.useState(!1),[j,M]=m.useState(!1),N=m.useRef(null),P=o(e=>e.config.isInitialized),F=_??D,{isUploading:I,getRootProps:L,getInputProps:R}=p({multiple:!1,accept:b,maxSize:x,maxFiles:1,onUploadStart:()=>w?.(),onUploadSuccess:(e,t)=>{let n=t.url;O(n),C?.(n,t)},onUploadError:(e,t)=>{T?.(t)}}),z=m.useCallback(async e=>{if(x&&e.size>x){T?.(Error(`File size exceeds ${x} bytes`));return}try{M(!0),w?.();let t=await l(e);O(t.url),C?.(t.url,t)}catch(e){T?.(e instanceof Error?e:Error(`Upload failed`))}finally{M(!1)}},[x,C,w,T]),B=m.useCallback(e=>{let t=e.target.files?.[0];t&&z(t),e.target.value=``},[z]),V=P===!1?j:I,H=m.useMemo(()=>P===!1?{onClick:()=>N.current?.click()}:L(),[P,L]),U=e=>{e.stopPropagation(),O(void 0),C?.(void 0)},W=y||V,G=u??`rounded`;return(0,h.jsxs)(`div`,{"data-slot":`image-upload`,className:s(g({variant:t,size:c,shape:u}),F&&`border-solid border-transparent`,W&&`pointer-events-none opacity-50`,e),onMouseEnter:()=>A(!0),onMouseLeave:()=>A(!1),...W?{}:H,children:[P===!1?(0,h.jsx)(`input`,{ref:N,type:`file`,accept:b,style:{display:`none`},onChange:B,disabled:W}):(0,h.jsx)(`input`,{...R(),disabled:W}),F?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`img`,{src:F,alt:``,className:s(`size-full object-cover`,G===`circle`?`rounded-full`:`rounded-lg`)}),!V&&(0,h.jsx)(`button`,{type:`button`,className:s(`bg-destructive text-background absolute top-0.5 right-0.5 z-10 size-4 items-center justify-center rounded-full`,E?`flex`:`flex md:hidden`),onClick:U,"aria-label":`Remove image`,children:(0,h.jsx)(a,{className:`size-3 text-white`})}),k&&!V&&!E&&(0,h.jsxs)(`div`,{className:s(`absolute inset-0 hidden items-center justify-center gap-1 bg-black/50 md:flex`,G===`circle`?`rounded-full`:`rounded-lg`),onClick:e=>e.stopPropagation(),children:[(0,h.jsx)(f,{type:`button`,size:`icon-xs`,variant:`ghost`,className:`rounded-full p-1.5 text-white/80 transition-colors hover:bg-white/20! hover:text-white`,onClick:e=>{e.stopPropagation(),H.onClick()},"aria-label":`Replace image`,children:(0,h.jsx)(r,{className:`size-4`})}),(0,h.jsx)(f,{type:`button`,size:`icon-xs`,variant:`ghost`,className:`hover:text-destructive hover:bg-destructive/20! rounded-full p-1.5 text-white/80 transition-colors`,onClick:U,"aria-label":`Remove image`,children:(0,h.jsx)(i,{className:`size-4`})})]})]}):S??(0,h.jsx)(`div`,{className:`text-muted-foreground flex size-full flex-col items-center justify-center gap-1`,children:(0,h.jsx)(n,{className:`size-1/3 opacity-50`})}),V&&(0,h.jsx)(`div`,{className:s(`absolute inset-0 flex items-center justify-center bg-black/30`,G===`circle`?`rounded-full`:`rounded-lg`),children:(0,h.jsx)(d,{className:`text-white`})})]})}export{_ as t};