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