import{i as e,n as t,t as n}from"./jsx-runtime-DG_AJzB_.js";import{t as r}from"./compiler-runtime-DCc3R3Xn.js";import{S as i,a,p as o,x as s,y as c}from"./createReactComponent-_L2mp4Ui.js";import{t as l}from"./utils-C8DGLIgm.js";import{Et as u}from"./getDisabledMountTransitionStyles-C-jmk481.js";var d=e(t()),f=d.createContext(void 0);function p(){let e=d.useContext(f);if(e===void 0)throw Error(c(13));return e}var m={imageLoadingStatus:()=>null},h=n(),g=d.forwardRef(function(e,t){let{className:n,render:r,...i}=e,[o,s]=d.useState(`idle`),c=d.useMemo(()=>({imageLoadingStatus:o}),[o]),l=d.useMemo(()=>({imageLoadingStatus:o,setImageLoadingStatus:s}),[o,s]),u=a(`span`,e,{state:c,ref:t,props:i,stateAttributesMapping:m});return(0,h.jsx)(f.Provider,{value:l,children:u})});function _(e,{referrerPolicy:t,crossOrigin:n}){let[r,i]=d.useState(`idle`);return s(()=>{if(!e)return i(`error`),o;let r=!0,a=new window.Image,s=e=>()=>{r&&i(e)};return i(`loading`),a.onload=s(`loaded`),a.onerror=s(`error`),t&&(a.referrerPolicy=t),a.crossOrigin=n??null,a.src=e,()=>{r=!1}},[e,n,t]),r}var v=d.forwardRef(function(e,t){let{className:n,render:r,onLoadingStatusChange:o,referrerPolicy:c,crossOrigin:l,...u}=e,f=p(),h=_(e.src,{referrerPolicy:c,crossOrigin:l}),g=i(e=>{o?.(e),f.setImageLoadingStatus(e)});return s(()=>{h!==`idle`&&g(h)},[h,g]),a(`img`,e,{state:d.useMemo(()=>({imageLoadingStatus:h}),[h]),ref:t,props:u,stateAttributesMapping:m,enabled:h===`loaded`})}),y=d.forwardRef(function(e,t){let{className:n,render:r,delay:i,...o}=e,{imageLoadingStatus:s}=p(),[c,l]=d.useState(i===void 0),f=u();return d.useEffect(()=>(i!==void 0&&f.start(i,()=>l(!0)),f.clear),[f,i]),a(`span`,e,{state:d.useMemo(()=>({imageLoadingStatus:s}),[s]),ref:t,props:o,stateAttributesMapping:m,enabled:s!==`loaded`&&c})}),b=r();function x(e){let t=(0,b.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,size:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`default`:i,o;t[4]===n?o=t[5]:(o=l(`size-8 rounded-full after:rounded-full data-[size=lg]:size-10 data-[size=sm]:size-6 after:border-border group/avatar relative flex shrink-0 select-none after:absolute after:inset-0 after:border after:mix-blend-darken dark:after:mix-blend-lighten`,n),t[4]=n,t[5]=o);let s;return t[6]!==r||t[7]!==a||t[8]!==o?(s=(0,h.jsx)(g,{"data-slot":`avatar`,"data-size":a,className:o,...r}),t[6]=r,t[7]=a,t[8]=o,t[9]=s):s=t[9],s}function S(e){let t=(0,b.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=l(`rounded-full aspect-square size-full object-cover`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,h.jsx)(v,{"data-slot":`avatar-image`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function C(e){let t=(0,b.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=l(`bg-muted text-muted-foreground rounded-full flex size-full items-center justify-center text-sm group-data-[size=sm]/avatar:text-xs`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,h.jsx)(y,{"data-slot":`avatar-fallback`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}export{C as n,S as r,x as t};