import{r as t,j as c,a as S}from"./index-ii2kaLch.js";const y=(i={})=>{const{threshold:f=0,root:r=null,rootMargin:a="50px",freezeOnceVisible:l=!1,initialIsIntersecting:n=!1}=i,m=t.useRef(null),[d,e]=t.useState(n);return t.useEffect(()=>{const s=m.current;if(!s||l&&d)return;if(!("IntersectionObserver"in window)){e(!0);return}const o=new IntersectionObserver(([g])=>{const u=g.isIntersecting;e(u),u&&l&&o.unobserve(s)},{threshold:f,root:r,rootMargin:a});return o.observe(s),()=>{o.disconnect()}},[m,f,r,a,l,d]),[m,d]},L=({src:i,alt:f,width:r,height:a,className:l,objectFit:n="contain",loading:m="lazy",sizes:d="100vw",priority:e=!1})=>{const s=i.includes(",")?i.split(",")[0].trim():i,[o,g]=t.useState(!1),[u,v]=t.useState(!1),[p,I]=t.useState(e?s:null),[E,b]=y({threshold:0,rootMargin:"100px",freezeOnceVisible:!0,initialIsIntersecting:e}),h="/placeholder.svg",j=s.startsWith("http")||s.startsWith("//");t.useEffect(()=>{(e||b)&&I(s)},[b,e,s]);const w=()=>{v(!0)},z=()=>{g(!0),v(!0),I(h)},x=o?h:p,O=!u&&!e;return c.jsxs("div",{ref:E,className:S("relative overflow-hidden bg-muted",l),style:{aspectRatio:r&&a?`${r}/${a}`:void 0},children:[O&&c.jsx("div",{className:"absolute inset-0 animate-pulse",style:{background:"linear-gradient(110deg, hsl(var(--muted)) 8%, hsl(var(--muted) / 0.6) 18%, hsl(var(--muted)) 33%)",backgroundSize:"200% 100%",animation:"shimmer 1.5s linear infinite"},"aria-hidden":"true"}),x&&c.jsxs("picture",{children:[!o&&j&&c.jsx(c.Fragment,{}),c.jsx("img",{src:x,alt:f,width:r,height:a,loading:e?"eager":"lazy",decoding:e?"sync":"async",sizes:d,onLoad:w,onError:z,className:S("w-full h-full transition-opacity duration-500",u?"opacity-100":"opacity-0",n==="contain"&&"object-contain",n==="cover"&&"object-cover",n==="fill"&&"object-fill",n==="none"&&"object-none",n==="scale-down"&&"object-scale-down"),style:{contentVisibility:e?"visible":"auto"},draggable:!1})]})]})};export{L as O};