import{r as a,j as n}from"./index-HQYpt33-.js";import{t as k,c as w}from"./runtime-omRR9KF1.js";const y=(e,r)=>{let s=0;const o=`${e}:${r}`;for(let t=0;t<o.length;t++)s=s*31+o.charCodeAt(t)&2147483647;return`x${s.toString(36)}`},x=({ad:e,eager:r,asText:s,linkClassName:o})=>{const t=a.useRef(null);return a.useEffect(()=>k(t.current,e.tok??""),[e.tok]),s||!e.img&&e.text?n.jsx("a",{ref:t,href:e.href,target:"_blank",rel:"noopener noreferrer",className:o??"hover:underline text-red-500 font-semibold",children:e.text}):e.img?n.jsx("a",{ref:t,href:e.href,target:"_blank",rel:"noopener noreferrer",children:n.jsx("img",{src:e.img,alt:e.text??"",width:e.w||void 0,height:e.h||void 0,loading:r?"eager":"lazy",decoding:"async",fetchPriority:r?"high":"low",style:{display:"block",width:"100%",height:"auto"}})}):null},$=({bundle:e,name:r,className:s,eager:o,text:t,fill:m})=>{const i=e?.slots?.[r],[j,v]=a.useState(null),l=i?.ads?.length?i:j,p=e?.ep;a.useEffect(()=>{p!==void 0&&w({endpoint:p,site:window.location.hostname})},[p]),a.useEffect(()=>{if(i?.ads?.length||!i?.tok)return;let f=!0;const d=e?.pp||"/api/panel";return fetch(`${d}/${i.tok}`).then(c=>c.ok?c.json():null).then(c=>{f&&c&&v(c)}).catch(()=>{}),()=>{f=!1}},[i?.tok,i?.ads?.length,e?.pp]);const h=l?.ads??[],u=[s,e?y(e.seed,r):null].filter(Boolean).join(" "),g=!m&&l?.w&&l?.h?{aspectRatio:`${l.w} / ${l.h}`,width:"100%",maxWidth:l.w}:{};return h.length===0?n.jsx("div",{className:u,style:g}):h.length===1?n.jsx("div",{className:u,style:g,children:n.jsx(x,{ad:h[0],eager:o,asText:t,linkClassName:t?s:void 0})}):n.jsx("div",{className:u,style:{display:"contents"},children:h.map((f,d)=>n.jsx(x,{ad:f,eager:o&&d===0,asText:t,linkClassName:t?s:void 0},`${r}-${d}`))})},A=({bundle:e,name:r,className:s,eager:o})=>n.jsx($,{bundle:e,name:r,className:s,eager:o});export{A,$ as S};
