const e=".advertory-right-column-track",t="--advertory-right-column-track-height",n=e=>e.getBoundingClientRect().top+window.scrollY,o=e=>{const{marginTop:t,marginBottom:n}=getComputedStyle(e);return e.getBoundingClientRect().height+parseFloat(t||"0")+parseFloat(n||"0")},r=(e,t)=>{const n=(o=t,`${Math.max(0,Math.round(o))}px`);var o;document.body.style.setProperty(e,n)},i=(e,t)=>`${e}-${t}`,a=(e,a,d)=>{var l;const c=Array.from(null!==(l=e.querySelectorAll(a))&&void 0!==l?l:[]),s=(e=>e.map(e=>{var t;return null===(t=document.querySelector(`[id^="${e}"]`))||void 0===t?void 0:t.parentElement}).map((e,t)=>({point:e,originalIndex:t})).filter(e=>Boolean(e.point)))(d);if(0===s.length)return;const u=n(e);(()=>{const e=document.querySelector("header");if(!e)return;const t=o(e);r("--advertory-newsroom-header-height",t)})(),s.forEach(({point:e,originalIndex:a})=>{((e,a,d)=>{const l=n(e),c=i(t,a),s=l-d,u=i("--advertory-right-column-split-point-height",a),h=o(e);r(c,s),r(u,h)})(e,a+1,u),(e=>{const t=null==e?void 0:e.id;if(!t)return;const n=i("--advertory-right-column-ad-height",t),a=o(e);r(n,a)})(c[a])});((e,o)=>{const i=n(e);r(t,i-o)})(s[Math.min(c.length,s.length-1)].point,u)};let d=!1;const l=t=>{if(!(null==t?void 0:t.enabled)||d)return;const{splitPointIDs:n,adSelector:o,trackSelector:r=e}=t,i=document.querySelector(r);if(!i)return;d=!0;const l=()=>{a(i,o,n)};l(),window.addEventListener("resize",l),window.addEventListener("orientationchange",l),window.addEventListener("load",l),window.addEventListener("advertory:adLoaded",()=>{requestAnimationFrame(l)});new ResizeObserver(l).observe(i)};export{l as initRightColumnSplit};
