import{j as u}from"./jsx-runtime-5BUNAZ9W.js";import{c as m}from"./cn-466VSCev.js";import{$,_ as b}from"./index-VfKohXEB.js";import{r as t}from"./index-4g5l5LRQ.js";import{$ as N}from"./index-tktZLsKA.js";import{$ as w}from"./index-TrPPXL0M.js";import{$ as _}from"./index-gxNcLOY3.js";const v="Avatar",[S,G]=N(v),[C,A]=S(v),I=t.forwardRef((e,r)=>{const{__scopeAvatar:a,...o}=e,[c,d]=t.useState("idle");return t.createElement(C,{scope:a,imageLoadingStatus:c,onImageLoadingStatusChange:d},t.createElement($.span,b({},o,{ref:r})))}),L="AvatarImage",E=t.forwardRef((e,r)=>{const{__scopeAvatar:a,src:o,onLoadingStatusChange:c=()=>{},...d}=e,n=A(L,a),s=M(o),l=w(g=>{c(g),n.onImageLoadingStatusChange(g)});return _(()=>{s!=="idle"&&l(s)},[s,l]),s==="loaded"?t.createElement($.img,b({},d,{ref:r,src:o})):null}),R="AvatarFallback",k=t.forwardRef((e,r)=>{const{__scopeAvatar:a,delayMs:o,...c}=e,d=A(R,a),[n,s]=t.useState(o===void 0);return t.useEffect(()=>{if(o!==void 0){const l=window.setTimeout(()=>s(!0),o);return()=>window.clearTimeout(l)}},[o]),n&&d.imageLoadingStatus!=="loaded"?t.createElement($.span,b({},c,{ref:r})):null});function M(e){const[r,a]=t.useState("idle");return _(()=>{if(!e){a("error");return}let o=!0;const c=new window.Image,d=n=>()=>{o&&a(n)};return a("loading"),c.onload=d("loaded"),c.onerror=d("error"),c.src=e,()=>{o=!1}},[e]),r}const y=I,x=E,h=k,i=t.forwardRef(({className:e,...r},a)=>u(y,{ref:a,className:m("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",e),...r}));i.displayName=y.displayName;const f=t.forwardRef(({className:e,...r},a)=>u(x,{ref:a,className:m("aspect-square h-full w-full",e),...r}));f.displayName=x.displayName;const p=t.forwardRef(({className:e,...r},a)=>u(h,{ref:a,className:m("flex h-full w-full items-center justify-center rounded-full bg-background-stronger",e),...r}));p.displayName=h.displayName;try{i.displayName="Avatar",i.__docgenInfo={description:"",displayName:"Avatar",props:{asChild:{defaultValue:null,description:"",name:"asChild",required:!1,type:{name:"boolean"}}}}}catch{}try{f.displayName="AvatarImage",f.__docgenInfo={description:"",displayName:"AvatarImage",props:{asChild:{defaultValue:null,description:"",name:"asChild",required:!1,type:{name:"boolean"}}}}}catch{}try{p.displayName="AvatarFallback",p.__docgenInfo={description:"",displayName:"AvatarFallback",props:{asChild:{defaultValue:null,description:"",name:"asChild",required:!1,type:{name:"boolean"}}}}}catch{}export{i as A,f as a,p as b};
