import{$ as e,A as t,I as n,J as r,N as i,P as a,Q as o,Y as s,a as c,g as l,gt as u,m as d,ut as f,x as p,xt as m,yt as h,z as g}from"./vue.runtime.esm-bundler-DS0mm12S.js";import{t as _}from"./utils-u71wZLxr.js";import{tt as v}from"./index-aDrlI3dP.js";import{O as y}from"./Teleport-CHY6zPT-.js";import{i as b}from"./button-DQxx5HZh.js";import{t as x}from"./useForwardExpose-DNY3s-e3.js";var[S,C]=y(`AvatarRoot`),w=p({__name:`AvatarRoot`,props:{asChild:{type:Boolean,required:!1},as:{type:null,required:!1,default:`span`}},setup(e){return x(),C({imageLoadingStatus:f(`idle`)}),(e,t)=>(n(),l(h(b),{"as-child":e.asChild,as:e.as},{default:o(()=>[g(e.$slots,`default`)]),_:3},8,[`as-child`,`as`]))}});function T(e,t){return e?t?(e.src!==t&&(e.src=t),e.complete&&e.naturalWidth>0?`loaded`:`loading`):`error`:`idle`}function E(e,{referrerPolicy:t,crossOrigin:n}={}){let r=f(!1),o=f(null),c=d(()=>r.value?(!o.value&&v&&(o.value=new window.Image),o.value):null),l=f(T(c.value,e.value)),u=e=>()=>{r.value&&(l.value=e)};return i(()=>{r.value=!0,s(r=>{let i=c.value;if(!i)return;l.value=T(i,e.value);let a=u(`loaded`),o=u(`error`);i.addEventListener(`load`,a),i.addEventListener(`error`,o),t?.value&&(i.referrerPolicy=t.value),typeof n?.value==`string`&&(i.crossOrigin=n.value),r(()=>{i.removeEventListener(`load`,a),i.removeEventListener(`error`,o)})})}),a(()=>{r.value=!1}),l}var D=p({__name:`AvatarImage`,props:{src:{type:String,required:!0},referrerPolicy:{type:null,required:!1},crossOrigin:{type:null,required:!1},asChild:{type:Boolean,required:!1},as:{type:null,required:!1,default:`img`}},emits:[`loadingStatusChange`],setup(t,{emit:i}){let a=t,s=i,{src:d,referrerPolicy:f,crossOrigin:p}=u(a);x();let m=S(),_=E(d,{referrerPolicy:f,crossOrigin:p});return r(_,e=>{s(`loadingStatusChange`,e),e!==`idle`&&(m.imageLoadingStatus.value=e)},{immediate:!0}),(t,r)=>e((n(),l(h(b),{role:`img`,"as-child":t.asChild,as:t.as,src:h(d),referrerpolicy:h(f),crossorigin:h(p)},{default:o(()=>[g(t.$slots,`default`)]),_:3},8,[`as-child`,`as`,`src`,`referrerpolicy`,`crossorigin`])),[[c,h(_)===`loaded`]])}}),O=p({__name:`Avatar`,props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e;return(e,r)=>(n(),l(h(w),{"data-slot":`avatar`,class:m(h(_)(`relative flex size-8 shrink-0 overflow-hidden rounded-full`,t.class))},{default:o(()=>[g(e.$slots,`default`)]),_:3},8,[`class`]))}}),k=p({__name:`AvatarImage`,props:{src:{},referrerPolicy:{},crossOrigin:{},asChild:{type:Boolean},as:{}},setup(e){let r=e;return(e,i)=>(n(),l(h(D),t({"data-slot":`avatar-image`},r,{class:`aspect-square size-full`}),{default:o(()=>[g(e.$slots,`default`)]),_:3},16))}});export{O as n,S as r,k as t};