import{r as h,u as x,j as l}from"./vendor-laZsiqLO.js";import{c as g}from"./utils-RgT4yCq8.js";let y=!1;function v({ad:e,className:m}){const u=h.useRef(null),{url:f}=x(),r=h.useMemo(()=>{if(!e?.dimensions||e.dimensions.toLowerCase()==="responsive")return{};const t=e.dimensions.match(/(\d+)\s*[xX*]\s*(\d+)/);if(t){const o=t[1],d=t[2];return{width:`${o}px`,height:`${d}px`,minWidth:`${o}px`,minHeight:`${d}px`,display:"block"}}return{}},[e?.dimensions]);return h.useEffect(()=>{if(!e||!e.is_active||e.type!=="code"||!u.current||!e.content)return;const t=u.current;t.innerHTML="",delete t.dataset.adPushed;const o=document.createElement("div");o.innerHTML=e.content;const d=()=>{const n=o.querySelector("ins.adsbygoogle");if(n){n.removeAttribute("data-adsbygoogle-status"),n.removeAttribute("data-ad-status"),r.width&&(n.style.display="inline-block",n.style.width=r.width,n.style.height=r.height),t.innerHTML="",t.appendChild(n.cloneNode(!0));const s=n.getAttribute("data-ad-client");if(s&&!y){const c=document.createElement("script");c.src=`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${s}`,c.async=!0,c.crossOrigin="anonymous",document.head.appendChild(c),y=!0}let i=0;const a=()=>{if(t.offsetWidth>0)try{(window.adsbygoogle=window.adsbygoogle||[]).push({})}catch(c){console.warn("AdSense push error on SPA navigate:",c)}else i<20&&(i++,setTimeout(a,100))};a();return}Array.from(o.childNodes).forEach(s=>{if(s.nodeType===Node.ELEMENT_NODE&&s.tagName==="SCRIPT"){const i=document.createElement("script");Array.from(s.attributes).forEach(a=>{i.setAttribute(a.name,a.value)}),i.textContent=s.textContent,t.appendChild(i)}else t.appendChild(s.cloneNode(!0))})},p=new IntersectionObserver(n=>{n.forEach(s=>{s.isIntersecting&&(d(),p.disconnect())})},{threshold:.1,rootMargin:"150px"});return p.observe(t),()=>{p.disconnect()}},[e,f,r]),!e||!e.is_active?null:e.type==="image"?l.jsx("div",{className:g("overflow-hidden rounded-md flex justify-center w-full mx-auto",m),style:r,children:l.jsxs("a",{href:e.target_url||"#",target:"_blank",rel:"noopener noreferrer",className:"block relative group w-full h-full",children:[l.jsx("img",{src:e.content,alt:e.name,className:"w-full h-full object-cover transition-opacity group-hover:opacity-90 mx-auto"}),l.jsx("span",{className:"absolute top-0 right-0 bg-black/40 text-[9px] uppercase tracking-widest text-white px-1.5 py-0.5 rounded-bl-md backdrop-blur-sm",children:"Ad"})]})}):e.type==="code"?l.jsx("div",{ref:u,style:r,className:g("overflow-hidden flex justify-center items-center w-full min-h-[50px] bg-transparent mx-auto",m)},`${f}-${e.id}`):null}export{v as A};
