import{r as a,j as s}from"./vendor-BXQAQzXu.js";function D({src:i,alt:g,className:o="",loading:y="lazy",priority:t=!1,sizes:u,width:n,height:c,onLoad:m,onError:f,onClick:l,placeholder:j,assetUrl:b=""}){const[$,h]=a.useState(!1),[N,p]=a.useState(!1),[x,R]=a.useState(0),[d,L]=a.useState(!1),S=a.useRef(null),T=2,r=i.startsWith("http")?i:`${b}${i.startsWith("/")?"":"/"}${i}`,W=e=>"",v=()=>{h(!0),m==null||m()},E=()=>{x{R(e=>e+1),p(!1),h(!1)},1e3):(p(!0),f==null||f())};if(a.useEffect(()=>{const e=setTimeout(()=>{L(!0)},t?100:500);return()=>clearTimeout(e)},[t]),a.useEffect(()=>{if(t&&typeof window<"u"&&d){const e=document.createElement("link");return e.rel="preload",e.as="image",e.href=r,u&&e.setAttribute("imagesizes",u),document.head.appendChild(e),()=>{try{document.head.removeChild(e)}catch{}}}},[t,r,u]),!d)return s.jsx("div",{className:`${o} bg-gray-100 animate-pulse flex items-center justify-center`,style:{width:n,height:c},children:s.jsx("div",{className:"text-gray-400 text-sm",children:"Loading..."})});if(!$&&j)return s.jsxs("div",{className:`bg-gray-200 animate-pulse flex items-center justify-center ${l?"cursor-pointer":""} ${o}`,style:{width:n,height:c},onClick:l,children:[s.jsx("img",{ref:S,src:r,alt:g,className:"sr-only",loading:t?"eager":y,onLoad:v,onError:E,width:n,height:c}),s.jsx("div",{className:"text-gray-400 text-sm",children:j})]});if(N)return s.jsx("div",{className:`${o} bg-gray-100 flex items-center justify-center`,style:{width:n,height:c},children:s.jsx("div",{className:"text-gray-500 text-sm",children:"Failed to load image"})});const C=W(),I=x>0?`${r}${r.includes("?")?"&":"?"}t=${Date.now()}`:r,O={ref:S,src:d?I:"",srcSet:d&&C||void 0,sizes:u,alt:g,className:`${o} ${$?"opacity-100":"opacity-0"} transition-opacity duration-300 ${l?"cursor-pointer":""}`,loading:t?"eager":y,onLoad:v,onError:E,onClick:l,width:n,height:c,decoding:t?"sync":"async",...t&&{fetchpriority:"high"}};return s.jsx("img",{...O},x)}export{D as O};