(function(){"use strict";try{if(typeof document<"u"){var t=document.createElement("style");t.id="inside-ad",t.appendChild(document.createTextNode("#streann-node{position:fixed;right:0;bottom:0;width:auto;max-width:100vw}#streann-node:has(#page-content){height:auto!important}@media (max-width: 425px){#streann-node:has(#page-content){width:75vw!important}}#page-content{position:relative;width:426px;max-width:100%}#page-content-split-ad{position:relative!important;width:100vh!important}#video-container{position:relative;padding-bottom:56.25%}#video-element{position:absolute;top:0;left:0;width:100%;height:100%}#streann-adhesion{position:fixed;width:100%;left:0;top:0;background:#0006;height:100px;z-index:10000;padding-top:15px;padding-bottom:15px}.adhesion-container{width:100%;margin:0 auto;text-align:center;opacity:1!important;z-index:11111}#adhesion{margin:0 auto;text-align:center}.close-btn-container{position:fixed;right:10px;opacity:1!important;top:10px;height:30px;width:30px;border-radius:100%;background-color:#fff;display:flex;justify-content:center}.closeButton{position:absolute;background-color:#00000080;padding:5px 13px;top:0;right:0;z-index:1;cursor:pointer;border-radius:4px;display:none}#cornerCloseButton{top:6px;right:6px;padding:4px;line-height:0;color:#fff;background-color:#0009;border-radius:4px;box-sizing:content-box}#cornerCloseButton svg{display:block;width:18px;height:18px}#cornerCloseButton:hover{background-color:#000c}#streann-logo{position:absolute;top:0;left:0;z-index:1;cursor:pointer}.logo{width:30px;height:30px}#un-mute,#mute{position:absolute;bottom:0;left:0;padding:5px 13px;z-index:1;cursor:pointer}.split-ad-close-btn{position:absolute;right:1px;top:90%;transform:translateY(-50%);background-color:transparent;color:#fff;padding:10px 20px;border:2px solid white;cursor:pointer;border-radius:5px;font-size:16px}.split-ad-unmute-btn{display:block;position:absolute;top:10px;right:10px;background-color:transparent;border:none;border-radius:50%;width:40px;height:40px;cursor:pointer;padding:8px;z-index:1000}#video-container-split-ad{position:relative!important;padding-bottom:56.25%}.multiview-ad{position:absolute;top:0;left:0;width:100%;height:100%;background:#000;display:flex;justify-content:center;align-items:center;z-index:9999}.multiview-ad-fullscreen{position:fixed}.multiview-right-bar-ad{position:relative;width:100%;height:auto;aspect-ratio:16 / 9}.multiview-ad-content{position:relative;width:100%;height:100%;display:flex;justify-content:center;align-items:center}.multiview-ad-player{width:100%;height:100%;object-fit:contain}.streann-ima-multiview-content,.streann-ima-multiview-video-container{position:relative;width:100%;height:100%}.streann-ima-multiview-content .streann-ima-video{position:absolute;top:0;left:0;width:100%;height:100%}.multiview-ad-close-btn{position:absolute;right:10px;bottom:10px;background-color:transparent;color:#fff;padding:10px 20px;border:2px solid white;cursor:pointer;border-radius:5px;font-size:16px;z-index:10000}.multiview-ad-unmute-btn{display:block;position:absolute;top:10px;right:10px;background-color:transparent;border:none;border-radius:50%;width:40px;height:40px;cursor:pointer;padding:8px;z-index:10000}")),document.head.appendChild(t)}}catch(i){console.error("vite-plugin-css-injected-by-js",i)}})();
var Ye = Object.defineProperty;
var qe = (i, e, t) => e in i ? Ye(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
var d = (i, e, t) => (qe(i, typeof e != "symbol" ? e + "" : e, t), t);
var L = /* @__PURE__ */ ((i) => (i.CORNER = "CORNER", i.EMBED = "EMBED", i.ADHESION = "ADHESION", i.EMBED_FLOAT = "EMBED_FLOAT", i.SPLIT_AD = "SPLIT_AD", i.MULTIVIEW_CANVAS = "MULTIVIEW_CANVAS", i.MULTIVIEW_RIGHT_BAR = "MULTIVIEW_RIGHT_BAR", i))(L || {}), E = /* @__PURE__ */ ((i) => (i.VAST = "VAST", i.BANNER = "BANNER", i.LOCAL_VIDEO = "LOCAL_VIDEO", i.LOCAL_IMAGE = "LOCAL_IMAGE", i))(E || {}), De = /* @__PURE__ */ ((i) => (i[i.SUNDAY = 0] = "SUNDAY", i[i.MONDAY = 1] = "MONDAY", i[i.TUESDAY = 2] = "TUESDAY", i[i.WEDNESDAY = 3] = "WEDNESDAY", i[i.THURSDAY = 4] = "THURSDAY", i[i.FRIDAY = 5] = "FRIDAY", i[i.SATURDAY = 6] = "SATURDAY", i))(De || {});
const g = {
  apiKey: "",
  apiToken: "",
  baseUrl: "",
  isAlreadyInit: !1,
  multiviewHostOnly: !1
};
let k = null, P = null;
function ke() {
  return k ? Promise.resolve(k) : (P || (P = je().finally(() => {
    P = null;
  })), P);
}
async function je() {
  try {
    const t = await (await fetch("https://geoip.streann.tech/")).json();
    return k = {
      country: t.countryCode || t.country || "",
      city: t.city || "",
      state: t.region || t.state || "",
      zip: t.zip || t.PostalCode || ""
    }, k;
  } catch {
    return {
      country: "",
      city: "",
      state: "",
      zip: ""
    };
  }
}
function Ge() {
  return k;
}
const Ke = "cornerAd", M = "background: orange; color: black; display: block;border-radius: 2px; padding: 2px;", _ = "background: white; color: black;", G = "streannAdsDebug";
function V() {
  var i;
  return typeof window > "u" || ((i = window.insideAd) == null ? void 0 : i.debug) !== !1;
}
function Xe() {
  try {
    const i = new URLSearchParams(window.location.search).get("debug");
    return i === "true" || i === "1" ? (sessionStorage.setItem(G, "1"), !0) : i === "false" || i === "0" ? (sessionStorage.removeItem(G), !1) : sessionStorage.getItem(G) === "1";
  } catch {
    return !1;
  }
}
const Qe = Xe();
class ue {
  constructor(e = Ke) {
    d(this, "scopeName");
    this.scopeName = e;
  }
  /** Whether `debug()` lines are printed (?debug=true). */
  get debugEnabled() {
    return Qe && V();
  }
  /**
   * A logger that tags its lines with `scope` instead of the default. Cheap to
   * call, so it can be created inline or held as a field.
   */
  scope(e) {
    return new ue(e);
  }
  get badge() {
    return `%c streann.com(${this.scopeName}) %c`;
  }
  info(...e) {
    V() && console.info(this.badge, M, _, ...e);
  }
  warn(...e) {
    V() && console.warn(this.badge, M, _, ...e);
  }
  error(...e) {
    V() && console.error(this.badge, M, _, ...e);
  }
  // Only printed with ?debug=true (see above)
  debug(...e) {
    if (!this.debugEnabled)
      return;
    const t = (performance.now() / 1e3).toFixed(1) + "s";
    console.info(this.badge, M, _, `[${t}]`, ...e);
  }
}
const l = new ue();
let U = null;
function Je() {
  return U ? l.debug("getCampaigns(): using cached campaigns") : U = Ze().catch((i) => (l.debug("getCampaigns(): request FAILED, will retry on next refresh", (i == null ? void 0 : i.message) || i), U = null, [])), U;
}
async function Ze() {
  const { country: i } = await ke();
  if (!i)
    throw new Error("Could not resolve country");
  localStorage.setItem("streannCountryId", i), l.debug("getCampaigns(): fetching campaigns", { country: i });
  const e = await fetch(
    `${g.baseUrl}v1/r/${g.apiKey}/campaigns/WEB?country=${i}`,
    {
      method: "GET",
      headers: new Headers({
        Authorization: `ApiToken ${g.apiToken}`
      })
    }
  );
  if (e.status != 200)
    throw new Error(`Something went wrong fetching campaigns: ${e.status}`);
  return e.json();
}
function et() {
  return Object.values(De)[(/* @__PURE__ */ new Date()).getDay()];
}
function ge(i) {
  let e = i.reduce((o, r) => o + r.weight, 0), t = Math.floor(Math.random() * e) + 1, n = 0, s = null;
  for (let o of i)
    if (n += o.weight, t <= n) {
      s = o;
      break;
    }
  return s || i[0];
}
function Pe(i) {
  return new Promise((e, t) => {
    const n = document.createElement("script");
    n.async = !0, n.src = i, n.onload = e, n.onerror = t, document.body.appendChild(n);
  });
}
function tt(i) {
  return document.evaluate(
    i,
    document,
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null
  ).singleNodeValue;
}
function ye(i) {
  var o;
  const e = (o = i.properties) == null ? void 0 : o.webSettings;
  if (!e)
    return null;
  const { elemId: t, parentXpath: n, advancedScript: s } = e;
  if (t)
    return document.getElementById(t);
  if (n)
    return tt(n);
  if (s)
    try {
      const r = new Function(s)();
      return r ? document.getElementById(r) : null;
    } catch {
      return null;
    }
  return null;
}
function Ae(i) {
  const e = Date.now(), t = new Date(i.startDate), n = new Date(i.endDate);
  return t.getTime() <= e && n.getTime() >= e;
}
function ve(i) {
  if (!i.timePeriods)
    return !0;
  const e = et(), t = /* @__PURE__ */ new Date();
  return i.timePeriods.every((s) => {
    const [o, r, a] = s.startTime.split(":").map(Number), c = /* @__PURE__ */ new Date();
    c.setHours(o), c.setMinutes(r), c.setSeconds(a);
    const [u, f, h] = s.endTime.split(":").map(Number), p = /* @__PURE__ */ new Date();
    return p.setHours(u), p.setMinutes(f), p.setSeconds(h), s.daysOfWeek.includes(e) && c <= t && p >= t;
  });
}
function Ee(i) {
  return i.replace(/^https?:\/\//, "").replace(/^www\./, "").split("/")[0].split(":")[0].toLowerCase();
}
function nt(i) {
  const e = Ee(location.host), t = Ee(String(i));
  return t ? e === t || e.endsWith(`.${t}`) : !1;
}
function it(i) {
  return i.absolutePath && i.absolutePath.length > 0 ? i.absolutePath.some((e) => e === location.pathname) : i.tags && i.tags.length ? i.tags.some((e) => location.pathname.includes(e)) : !0;
}
function ee(i) {
  return i.domain && !(i.domain.includes(location.host) || nt(i.domain)) ? !1 : it(i);
}
function st(i) {
  const e = i.placements.filter(ee).filter(te);
  return !(!e || e.length == 0);
}
function te(i) {
  var s, o;
  const e = (o = (s = i.properties) == null ? void 0 : s.webSettings) == null ? void 0 : o.screens;
  let t = "";
  const n = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  return n <= 425 ? t = "MOBILE" : n <= 768 ? t = "TABLET" : t = "DESKTOP", e ? e.includes(t) : !0;
}
function ot(i) {
  const e = i.filter(Ae).filter(ve);
  l.debugEnabled && i.forEach((o) => {
    l.debug(`filter campaign "${o.name}"`, {
      dateOk: Ae(o),
      timePeriodOk: ve(o),
      startDate: o.startDate,
      endDate: o.endDate,
      timePeriods: o.timePeriods,
      browserTime: (/* @__PURE__ */ new Date()).toString()
    });
  });
  let t;
  if (e.length > 1 ? t = ge(e.filter(st)) : t = e[0], !t || !t.placements)
    return { campaign: void 0, filteredPlacements: [] };
  const n = t.placements.filter(ee).filter(te);
  if (l.debugEnabled) {
    const o = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth, r = o <= 425 ? "MOBILE" : o <= 768 ? "TABLET" : "DESKTOP";
    t.placements.forEach((a) => {
      var c, u;
      l.debug(`filter placement "${a.name}" [${a.viewType}]`, {
        tagOk: ee(a),
        screenOk: te(a),
        currentScreen: `${r} (width ${o})`,
        screens: (u = (c = a.properties) == null ? void 0 : c.webSettings) == null ? void 0 : u.screens,
        domain: a.domain,
        host: location.host,
        tags: a.tags,
        absolutePath: a.absolutePath,
        path: location.pathname
      });
    });
  }
  n.length == 0;
  const s = n.map(
    (o) => o.ads.length > 1 ? { ...o, ad: ge(o.ads) } : { ...o, ad: o.ads[0] }
  );
  return { campaign: t, filteredPlacements: s };
}
const rt = {
  "559ff7ade4b0d0aff40888dd": "waOD17zDaPce11Z0puO7SnklPkRA9OFA",
  "611fd870e4b03ec37aae6e5e": "7cYD4eXXRSfU3Fm1cRUfbzLjGl5TCa0H",
  //Bethelmedia
  "63588500e4b0a3efdffcd7ae": "2JW19nsrunPbTCvLlDpujMeEqy7B5BKw",
  //Emmanueltv
  "6849d5ca8f0828869550a9d4": "VVClTfMzzYh9tp8xzWiXgtZiXLSOAKTC",
  //Fearpix
  "61290efae4b0304f3eb75567": "SfZ3PMQtGdOvQLpddJcqRXQM9byJT2oR",
  //FlexFlix
  "67ae4dca8f0849e7e4f7bacd": "AGOodqAzgaWFLGl4dnABChTF7fOr4N6B",
  //GameStreamMedia
  "665489308f0895bfb0a92709": "8n31clcNq8cBbtgFzfJlCDmhFFLqkOVt",
  //Gols
  "68d6ef1f8f0806541640a2bf": "aVgVElbEaVAlkTGtiEACO2OcLSutKY4V",
  //ImpactProfessionals
  "67ffb7cd8f088acea336789e": "AChsRySIuKQeAB2JTjaXKEQLaG9zr8qk",
  //Okgol
  "5fc01321e4b0612f786b31c1": "LnfN4l7AeFfI3ygS5ChjTFwfO9KpiKjd",
  //Panamsport,
  "61316705e4b0295f87dae396": "YTAtmWLysGqH38Hl8pH3GNWxKjuJwW1T",
  //Tdmax
  "67afc6258f0849e7e502973e": "bo2q97sTBTo35YQaMo14uiusWqosZr3p",
  //Televicentro
  "686c6dac8f0802f464222b69": "8oGsm3BJC5qq4mrDY2b3oDkcImVJ2Nb5",
  //Tvin
  "613fa9a7e4b0ee1171b95105": "aCQPR3Q6FuA0HmDPRYdKONpC7ULP6dCj",
  //Wipr
  "56bb41cce4b01db401d1b040": "XKHTYLWGqZszh7ZSIUl91CDeQZ23Cg0m"
  //Actualidad
};
function at(i) {
  return rt[i];
}
const dt = "3.6.7";
class lt {
  constructor() {
    d(this, "initialized", !1);
    d(this, "writeKey");
    d(this, "resellerId");
  }
  initialize(e) {
    this.initialized || (this.resellerId = e, this.writeKey = at(e), this.writeKey && (this.loadSegmentSnippet(this.writeKey), this.initialized = !0));
  }
  getCommonProperties() {
    const e = Ge();
    return {
      resellerId: this.resellerId || "",
      country: (e == null ? void 0 : e.country) || "",
      city: (e == null ? void 0 : e.city) || "",
      state: (e == null ? void 0 : e.state) || "",
      zip: (e == null ? void 0 : e.zip) || "",
      platform: "Web",
      deviceType: "Web",
      appVersion: dt
    };
  }
  loadSegmentSnippet(e) {
    const t = window.analytics = window.analytics || [];
    if (!t.initialize) {
      if (t.invoked)
        return;
      t.invoked = !0, t.methods = [
        "trackSubmit",
        "trackClick",
        "trackLink",
        "trackForm",
        "pageview",
        "identify",
        "reset",
        "group",
        "track",
        "ready",
        "alias",
        "debug",
        "page",
        "once",
        "off",
        "on",
        "addSourceMiddleware",
        "addIntegrationMiddleware",
        "setAnonymousId",
        "addDestinationMiddleware"
      ], t.factory = function(n) {
        return function(...s) {
          return s.unshift(n), t.push(s), t;
        };
      };
      for (const n of t.methods)
        t[n] = t.factory(n);
      t.load = function(n, s) {
        var a;
        const o = document.createElement("script");
        o.type = "text/javascript", o.async = !0, o.src = `https://cdn.segment.com/analytics.js/v1/${n}/analytics.min.js`;
        const r = document.getElementsByTagName("script")[0];
        (a = r == null ? void 0 : r.parentNode) == null || a.insertBefore(o, r), t._loadOptions = s;
      }, t._writeKey = e, t.SNIPPET_VERSION = "4.15.3", t.load(e), t.page();
    }
  }
  track(e, t) {
    if (this.initialized)
      try {
        const n = window.analytics;
        if (n && n.track) {
          const s = {
            ...this.getCommonProperties(),
            ...t
          };
          n.track(e, s);
        }
      } catch {
      }
  }
  trackAdRequested(e) {
    this.track("Ad Requested", {
      screen: e
    });
  }
  trackAdDisplayed(e, t, n) {
    this.track("Ad Displayed", {
      adName: e,
      adType: t,
      screen: n
    });
  }
  trackAdFailed(e, t) {
    this.track("Ad Failed", {
      screen: e,
      error: t
    });
  }
}
const $ = new lt(), N = l.scope("schedule"), K = l.scope("ad-error");
function ct(i) {
  var e;
  K.error(i.message, i), $.trackAdFailed(
    i.screen || window.location.pathname,
    i.code !== void 0 ? `${i.code}: ${i.message}` : i.message
  );
  try {
    (e = g.onAdError) == null || e.call(g, i);
  } catch (t) {
    K.warn("the host page's onAdError handler threw", t);
  }
  try {
    window.dispatchEvent(new CustomEvent("insideAdError", { detail: i }));
  } catch (t) {
    K.warn("failed dispatching the insideAdError event", t);
  }
}
class ut {
  constructor(e, t) {
    d(this, "campaing");
    d(this, "refresh");
    d(this, "refreshTimeout");
    d(this, "onVisible");
    d(this, "disposed", !1);
    this.campaing = e, this.refresh = t;
  }
  insideAdReceived(e) {
    l.debug("insideAdReceived", e);
  }
  insideAdLoaded() {
    l.debug("insideAdLoaded");
  }
  insideAdPlay() {
    l.debug("insideAdPlay");
  }
  insideAdStop() {
    this.scheduleNextAd();
  }
  insideAdSkipped() {
    l.debug("insideAdSkipped"), this.scheduleNextAd();
  }
  insideAdClicked() {
    l.debug("insideAdClicked");
  }
  insideAdError(e) {
    l.debug("insideAdError", e), ct(e), this.scheduleNextAd();
  }
  insideAdVolumeChanged(e) {
    l.debug("insideAdVolumeChanged", e);
  }
  /**
   * Arms the refresh that plays the next ad, the web counterpart of
   * startTimerForNextAd() in the native SDKs. Every terminal ad state routes
   * here, and re-arming cancels the previous timer, so overlapping terminal
   * events (destoryIma calling both onAdFinish and insideAdStop, say) still
   * schedule exactly one refresh.
   */
  scheduleNextAd() {
    var n, s;
    if (this.disposed) {
      N.info("terminal ad state on a retired cycle - not re-arming the refresh");
      return;
    }
    const e = ((s = (n = this.campaing) == null ? void 0 : n.properties) == null ? void 0 : s.intervalInMinutes) ?? 1;
    if (!e || e <= 0) {
      N.info("intervalInMinutes disabled - ads will not repeat");
      return;
    }
    const t = this.refreshTimeout !== void 0;
    this.clearRefreshTimeout(), N.info(
      `next ad refresh in ${e} min${t ? " (replacing the pending one)" : ""}`
    ), this.refreshTimeout = setTimeout(() => {
      this.refreshTimeout = void 0, this.refreshWhenVisible();
    }, e * 6e4);
  }
  /**
   * Radio listeners keep the tab in the background for hours. Ads requested
   * there are never seen, so Google barely fills them and every one of them
   * drags the fill rate down - hold the next ad until the page is visible.
   */
  refreshWhenVisible() {
    if (!document.hidden) {
      this.refresh();
      return;
    }
    N.info("tab hidden - the next ad waits until the page is visible again");
    const e = () => {
      document.hidden || (this.clearRefreshTimeout(), N.info("tab visible again - refreshing ads"), this.refresh());
    };
    this.onVisible = e, document.addEventListener("visibilitychange", e);
  }
  clearRefreshTimeout() {
    clearTimeout(this.refreshTimeout), this.refreshTimeout = void 0, this.onVisible && (document.removeEventListener("visibilitychange", this.onVisible), this.onVisible = void 0);
  }
  /**
   * Retires this cycle's callback: cancels its pending refresh and stops it
   * arming another. Called when the next refresh cycle takes over.
   */
  dispose() {
    this.disposed = !0, N.info("refresh cycle retired"), this.clearRefreshTimeout();
  }
}
const ht = "https://imasdk.googleapis.com/js/sdkloader/ima3.js";
let O = null;
const be = () => {
  O = null;
}, pt = () => {
  const i = window;
  return i.google && i.google.ima ? Promise.resolve(i.google.ima) : O || (O = Pe(ht).then(() => i.google.ima), O.then(be).catch(be), O);
}, mt = "https://securepubads.g.doubleclick.net/tag/js/gpt.js", ft = () => {
  const i = window;
  return i.googletag && i.googletag.apiReady ? Promise.resolve(i.googletag) : Pe(mt).then(() => i.googletag);
};
var ne = function(i, e) {
  return ne = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, n) {
    t.__proto__ = n;
  } || function(t, n) {
    for (var s in n)
      Object.prototype.hasOwnProperty.call(n, s) && (t[s] = n[s]);
  }, ne(i, e);
};
function Y(i, e) {
  if (typeof e != "function" && e !== null)
    throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
  ne(i, e);
  function t() {
    this.constructor = i;
  }
  i.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
}
function ie(i) {
  var e = typeof Symbol == "function" && Symbol.iterator, t = e && i[e], n = 0;
  if (t)
    return t.call(i);
  if (i && typeof i.length == "number")
    return {
      next: function() {
        return i && n >= i.length && (i = void 0), { value: i && i[n++], done: !i };
      }
    };
  throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function z(i, e) {
  var t = typeof Symbol == "function" && i[Symbol.iterator];
  if (!t)
    return i;
  var n = t.call(i), s, o = [], r;
  try {
    for (; (e === void 0 || e-- > 0) && !(s = n.next()).done; )
      o.push(s.value);
  } catch (a) {
    r = { error: a };
  } finally {
    try {
      s && !s.done && (t = n.return) && t.call(n);
    } finally {
      if (r)
        throw r.error;
    }
  }
  return o;
}
function W(i, e, t) {
  if (t || arguments.length === 2)
    for (var n = 0, s = e.length, o; n < s; n++)
      (o || !(n in e)) && (o || (o = Array.prototype.slice.call(e, 0, n)), o[n] = e[n]);
  return i.concat(o || Array.prototype.slice.call(e));
}
function b(i) {
  return typeof i == "function";
}
function Me(i) {
  var e = function(n) {
    Error.call(n), n.stack = new Error().stack;
  }, t = i(e);
  return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
}
var X = Me(function(i) {
  return function(t) {
    i(this), this.message = t ? t.length + ` errors occurred during unsubscription:
` + t.map(function(n, s) {
      return s + 1 + ") " + n.toString();
    }).join(`
  `) : "", this.name = "UnsubscriptionError", this.errors = t;
  };
});
function se(i, e) {
  if (i) {
    var t = i.indexOf(e);
    0 <= t && i.splice(t, 1);
  }
}
var q = function() {
  function i(e) {
    this.initialTeardown = e, this.closed = !1, this._parentage = null, this._finalizers = null;
  }
  return i.prototype.unsubscribe = function() {
    var e, t, n, s, o;
    if (!this.closed) {
      this.closed = !0;
      var r = this._parentage;
      if (r)
        if (this._parentage = null, Array.isArray(r))
          try {
            for (var a = ie(r), c = a.next(); !c.done; c = a.next()) {
              var u = c.value;
              u.remove(this);
            }
          } catch (m) {
            e = { error: m };
          } finally {
            try {
              c && !c.done && (t = a.return) && t.call(a);
            } finally {
              if (e)
                throw e.error;
            }
          }
        else
          r.remove(this);
      var f = this.initialTeardown;
      if (b(f))
        try {
          f();
        } catch (m) {
          o = m instanceof X ? m.errors : [m];
        }
      var h = this._finalizers;
      if (h) {
        this._finalizers = null;
        try {
          for (var p = ie(h), y = p.next(); !y.done; y = p.next()) {
            var B = y.value;
            try {
              Se(B);
            } catch (m) {
              o = o ?? [], m instanceof X ? o = W(W([], z(o)), z(m.errors)) : o.push(m);
            }
          }
        } catch (m) {
          n = { error: m };
        } finally {
          try {
            y && !y.done && (s = p.return) && s.call(p);
          } finally {
            if (n)
              throw n.error;
          }
        }
      }
      if (o)
        throw new X(o);
    }
  }, i.prototype.add = function(e) {
    var t;
    if (e && e !== this)
      if (this.closed)
        Se(e);
      else {
        if (e instanceof i) {
          if (e.closed || e._hasParent(this))
            return;
          e._addParent(this);
        }
        (this._finalizers = (t = this._finalizers) !== null && t !== void 0 ? t : []).push(e);
      }
  }, i.prototype._hasParent = function(e) {
    var t = this._parentage;
    return t === e || Array.isArray(t) && t.includes(e);
  }, i.prototype._addParent = function(e) {
    var t = this._parentage;
    this._parentage = Array.isArray(t) ? (t.push(e), t) : t ? [t, e] : e;
  }, i.prototype._removeParent = function(e) {
    var t = this._parentage;
    t === e ? this._parentage = null : Array.isArray(t) && se(t, e);
  }, i.prototype.remove = function(e) {
    var t = this._finalizers;
    t && se(t, e), e instanceof i && e._removeParent(this);
  }, i.EMPTY = function() {
    var e = new i();
    return e.closed = !0, e;
  }(), i;
}(), _e = q.EMPTY;
function Ve(i) {
  return i instanceof q || i && "closed" in i && b(i.remove) && b(i.add) && b(i.unsubscribe);
}
function Se(i) {
  b(i) ? i() : i.unsubscribe();
}
var Ue = {
  onUnhandledError: null,
  onStoppedNotification: null,
  Promise: void 0,
  useDeprecatedSynchronousErrorHandling: !1,
  useDeprecatedNextContext: !1
}, oe = {
  setTimeout: function(i, e) {
    for (var t = [], n = 2; n < arguments.length; n++)
      t[n - 2] = arguments[n];
    var s = oe.delegate;
    return s != null && s.setTimeout ? s.setTimeout.apply(s, W([i, e], z(t))) : setTimeout.apply(void 0, W([i, e], z(t)));
  },
  clearTimeout: function(i) {
    var e = oe.delegate;
    return ((e == null ? void 0 : e.clearTimeout) || clearTimeout)(i);
  },
  delegate: void 0
};
function gt(i) {
  oe.setTimeout(function() {
    throw i;
  });
}
function Te() {
}
function F(i) {
  i();
}
var He = function(i) {
  Y(e, i);
  function e(t) {
    var n = i.call(this) || this;
    return n.isStopped = !1, t ? (n.destination = t, Ve(t) && t.add(n)) : n.destination = Et, n;
  }
  return e.create = function(t, n, s) {
    return new re(t, n, s);
  }, e.prototype.next = function(t) {
    this.isStopped || this._next(t);
  }, e.prototype.error = function(t) {
    this.isStopped || (this.isStopped = !0, this._error(t));
  }, e.prototype.complete = function() {
    this.isStopped || (this.isStopped = !0, this._complete());
  }, e.prototype.unsubscribe = function() {
    this.closed || (this.isStopped = !0, i.prototype.unsubscribe.call(this), this.destination = null);
  }, e.prototype._next = function(t) {
    this.destination.next(t);
  }, e.prototype._error = function(t) {
    try {
      this.destination.error(t);
    } finally {
      this.unsubscribe();
    }
  }, e.prototype._complete = function() {
    try {
      this.destination.complete();
    } finally {
      this.unsubscribe();
    }
  }, e;
}(q), yt = Function.prototype.bind;
function Q(i, e) {
  return yt.call(i, e);
}
var At = function() {
  function i(e) {
    this.partialObserver = e;
  }
  return i.prototype.next = function(e) {
    var t = this.partialObserver;
    if (t.next)
      try {
        t.next(e);
      } catch (n) {
        H(n);
      }
  }, i.prototype.error = function(e) {
    var t = this.partialObserver;
    if (t.error)
      try {
        t.error(e);
      } catch (n) {
        H(n);
      }
    else
      H(e);
  }, i.prototype.complete = function() {
    var e = this.partialObserver;
    if (e.complete)
      try {
        e.complete();
      } catch (t) {
        H(t);
      }
  }, i;
}(), re = function(i) {
  Y(e, i);
  function e(t, n, s) {
    var o = i.call(this) || this, r;
    if (b(t) || !t)
      r = {
        next: t ?? void 0,
        error: n ?? void 0,
        complete: s ?? void 0
      };
    else {
      var a;
      o && Ue.useDeprecatedNextContext ? (a = Object.create(t), a.unsubscribe = function() {
        return o.unsubscribe();
      }, r = {
        next: t.next && Q(t.next, a),
        error: t.error && Q(t.error, a),
        complete: t.complete && Q(t.complete, a)
      }) : r = t;
    }
    return o.destination = new At(r), o;
  }
  return e;
}(He);
function H(i) {
  gt(i);
}
function vt(i) {
  throw i;
}
var Et = {
  closed: !0,
  next: Te,
  error: vt,
  complete: Te
}, bt = function() {
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
}();
function St(i) {
  return i;
}
function Tt(i) {
  return i.length === 0 ? St : i.length === 1 ? i[0] : function(t) {
    return i.reduce(function(n, s) {
      return s(n);
    }, t);
  };
}
var we = function() {
  function i(e) {
    e && (this._subscribe = e);
  }
  return i.prototype.lift = function(e) {
    var t = new i();
    return t.source = this, t.operator = e, t;
  }, i.prototype.subscribe = function(e, t, n) {
    var s = this, o = It(e) ? e : new re(e, t, n);
    return F(function() {
      var r = s, a = r.operator, c = r.source;
      o.add(a ? a.call(o, c) : c ? s._subscribe(o) : s._trySubscribe(o));
    }), o;
  }, i.prototype._trySubscribe = function(e) {
    try {
      return this._subscribe(e);
    } catch (t) {
      e.error(t);
    }
  }, i.prototype.forEach = function(e, t) {
    var n = this;
    return t = Ie(t), new t(function(s, o) {
      var r = new re({
        next: function(a) {
          try {
            e(a);
          } catch (c) {
            o(c), r.unsubscribe();
          }
        },
        error: o,
        complete: s
      });
      n.subscribe(r);
    });
  }, i.prototype._subscribe = function(e) {
    var t;
    return (t = this.source) === null || t === void 0 ? void 0 : t.subscribe(e);
  }, i.prototype[bt] = function() {
    return this;
  }, i.prototype.pipe = function() {
    for (var e = [], t = 0; t < arguments.length; t++)
      e[t] = arguments[t];
    return Tt(e)(this);
  }, i.prototype.toPromise = function(e) {
    var t = this;
    return e = Ie(e), new e(function(n, s) {
      var o;
      t.subscribe(function(r) {
        return o = r;
      }, function(r) {
        return s(r);
      }, function() {
        return n(o);
      });
    });
  }, i.create = function(e) {
    return new i(e);
  }, i;
}();
function Ie(i) {
  var e;
  return (e = i ?? Ue.Promise) !== null && e !== void 0 ? e : Promise;
}
function wt(i) {
  return i && b(i.next) && b(i.error) && b(i.complete);
}
function It(i) {
  return i && i instanceof He || wt(i) && Ve(i);
}
var Ct = Me(function(i) {
  return function() {
    i(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
  };
}), Fe = function(i) {
  Y(e, i);
  function e() {
    var t = i.call(this) || this;
    return t.closed = !1, t.currentObservers = null, t.observers = [], t.isStopped = !1, t.hasError = !1, t.thrownError = null, t;
  }
  return e.prototype.lift = function(t) {
    var n = new Ce(this, this);
    return n.operator = t, n;
  }, e.prototype._throwIfClosed = function() {
    if (this.closed)
      throw new Ct();
  }, e.prototype.next = function(t) {
    var n = this;
    F(function() {
      var s, o;
      if (n._throwIfClosed(), !n.isStopped) {
        n.currentObservers || (n.currentObservers = Array.from(n.observers));
        try {
          for (var r = ie(n.currentObservers), a = r.next(); !a.done; a = r.next()) {
            var c = a.value;
            c.next(t);
          }
        } catch (u) {
          s = { error: u };
        } finally {
          try {
            a && !a.done && (o = r.return) && o.call(r);
          } finally {
            if (s)
              throw s.error;
          }
        }
      }
    });
  }, e.prototype.error = function(t) {
    var n = this;
    F(function() {
      if (n._throwIfClosed(), !n.isStopped) {
        n.hasError = n.isStopped = !0, n.thrownError = t;
        for (var s = n.observers; s.length; )
          s.shift().error(t);
      }
    });
  }, e.prototype.complete = function() {
    var t = this;
    F(function() {
      if (t._throwIfClosed(), !t.isStopped) {
        t.isStopped = !0;
        for (var n = t.observers; n.length; )
          n.shift().complete();
      }
    });
  }, e.prototype.unsubscribe = function() {
    this.isStopped = this.closed = !0, this.observers = this.currentObservers = null;
  }, Object.defineProperty(e.prototype, "observed", {
    get: function() {
      var t;
      return ((t = this.observers) === null || t === void 0 ? void 0 : t.length) > 0;
    },
    enumerable: !1,
    configurable: !0
  }), e.prototype._trySubscribe = function(t) {
    return this._throwIfClosed(), i.prototype._trySubscribe.call(this, t);
  }, e.prototype._subscribe = function(t) {
    return this._throwIfClosed(), this._checkFinalizedStatuses(t), this._innerSubscribe(t);
  }, e.prototype._innerSubscribe = function(t) {
    var n = this, s = this, o = s.hasError, r = s.isStopped, a = s.observers;
    return o || r ? _e : (this.currentObservers = null, a.push(t), new q(function() {
      n.currentObservers = null, se(a, t);
    }));
  }, e.prototype._checkFinalizedStatuses = function(t) {
    var n = this, s = n.hasError, o = n.thrownError, r = n.isStopped;
    s ? t.error(o) : r && t.complete();
  }, e.prototype.asObservable = function() {
    var t = new we();
    return t.source = this, t;
  }, e.create = function(t, n) {
    return new Ce(t, n);
  }, e;
}(we), Ce = function(i) {
  Y(e, i);
  function e(t, n) {
    var s = i.call(this) || this;
    return s.destination = t, s.source = n, s;
  }
  return e.prototype.next = function(t) {
    var n, s;
    (s = (n = this.destination) === null || n === void 0 ? void 0 : n.next) === null || s === void 0 || s.call(n, t);
  }, e.prototype.error = function(t) {
    var n, s;
    (s = (n = this.destination) === null || n === void 0 ? void 0 : n.error) === null || s === void 0 || s.call(n, t);
  }, e.prototype.complete = function() {
    var t, n;
    (n = (t = this.destination) === null || t === void 0 ? void 0 : t.complete) === null || n === void 0 || n.call(t);
  }, e.prototype._subscribe = function(t) {
    var n, s;
    return (s = (n = this.source) === null || n === void 0 ? void 0 : n.subscribe(t)) !== null && s !== void 0 ? s : _e;
  }, e;
}(Fe);
const xe = new Fe();
function x(i) {
  xe.next(i);
}
function Bt() {
  return xe.asObservable();
}
class Lt {
  constructor() {
    d(this, "googletag");
    d(this, "timeOutCornerBanner");
    d(this, "timeOutAdhesion");
    d(this, "insideAdCallback");
    d(this, "onCornerBannerFinish");
    d(this, "onCornerBannerLoaded");
    d(this, "mapBanners", /* @__PURE__ */ new Map());
    d(this, "onSlotRender", (e) => {
      const t = e.slot, n = t.getSlotElementId(), s = this.mapBanners.get(n);
      s && (e.isEmpty ? (l.debug("Banner slot rendered EMPTY", {
        slotId: n,
        bannerUrl: s.url,
        bannerType: s.type,
        adUnitPath: t.getAdUnitPath(),
        size: e.size,
        creativeId: e.creativeId,
        lineItemId: e.lineItemId
      }), s.type === "CORNER" && (this.releaseCornerSlot(), this.onCornerBannerFinish(!0)), s.type === "ADHESION" && x("ERROR")) : (l.debug("Banner slot rendered SUCCESSFULLY", {
        slotId: n,
        bannerUrl: s.url,
        size: e.size,
        creativeId: e.creativeId,
        lineItemId: e.lineItemId,
        advertiserId: e.advertiserId
      }), s.type === "CORNER" && this.onCornerBannerLoaded && this.onCornerBannerLoaded(e.size), s.type === "ADHESION" && x("STARTED")));
    });
    d(this, "onViewableListener", (e) => {
      const t = e.slot, n = this.mapBanners.get(t.getSlotElementId());
      n && (n.type === "CORNER" ? this.timeOutCornerBanner = setTimeout(() => {
        if (!this.checkIfBannerExist(t.getSlotElementId())) {
          l.debug("Banner not found refreshing false");
          return;
        }
        this.destroyCornerAdBanner();
      }, n.duration * 1e3) : n.type === "ADHESION" ? this.timeOutAdhesion = setTimeout(() => {
        if (!this.checkIfBannerExist(t.getSlotElementId())) {
          l.debug("Banner not found refreshing false");
          return;
        }
        this.removeBanner(n.id);
      }, n.duration * 1e3) : setTimeout(() => {
        if (!this.checkIfBannerExist(t.getSlotElementId())) {
          l.debug("Banner not found refreshing false");
          return;
        }
        l.debug("Refreshing banner", n == null ? void 0 : n.id), this.googletag.pubads().refresh([t]);
      }, n.duration * 1e3));
    });
    ft().then((e) => {
      this.googletag = e, l.debug("googletag loaded"), this.init();
    });
  }
  init() {
    this.googletag.cmd.push(() => {
      this.googletag.pubads().addEventListener("impressionViewable", this.onViewableListener), this.googletag.pubads().addEventListener("slotRenderEnded", this.onSlotRender), this.googletag.pubads().addEventListener("slotRequested", (e) => {
        const t = e.slot;
        this.mapBanners.get(t.getSlotElementId()) && l.debug("Banner ad REQUEST sent to Google", {
          slotId: t.getSlotElementId(),
          adUnitPath: t.getAdUnitPath()
        });
      }), this.googletag.pubads().addEventListener("slotResponseReceived", (e) => {
        const t = e.slot;
        this.mapBanners.get(t.getSlotElementId()) && l.debug("Banner ad RESPONSE received from Google", {
          slotId: t.getSlotElementId(),
          adUnitPath: t.getAdUnitPath()
        });
      }), this.googletag.setConfig({ centering: !0 }), this.googletag.enableServices();
    });
  }
  checkIfBannerExist(e) {
    return this.mapBanners.has(e);
  }
  mapToBannerSizes(e) {
    const t = [];
    return e.forEach(({ width: n, height: s }) => {
      t.push([n, s]);
    }), t;
  }
  addBanners(e) {
    this.googletag.cmd.push(() => {
      e.forEach((t) => {
        if (t.type == "CORNER") {
          const o = document.querySelector("#streann-node");
          if (!o) {
            l.debug("streann-node not found - cannot insert corner banner"), setTimeout(() => this.addBanners([t]), 500);
            return;
          }
          const r = o.querySelector("#page-content");
          r && r.remove(), document.getElementById(t.id) || o.insertAdjacentHTML("beforeend", `<div id="${t.id}"></div>`);
          const a = this.mapBanners.get(t.id);
          if (a) {
            l.debug("Destroying existing corner banner before creating new one");
            try {
              this.googletag.destroySlots([a.slot]), this.mapBanners.delete(t.id), l.debug("Destroyed existing banner slot", t.id);
            } catch (c) {
              l.debug("Error destroying existing slot:", c), this.mapBanners.delete(t.id);
            }
          }
        }
        const n = this.mapToBannerSizes(t.sizes);
        l.debug("Attempting to define banner slot", {
          adUnitPath: t.url,
          sizes: n,
          elementId: t.id,
          bannerType: t.type
        });
        const s = this.googletag.defineSlot(
          t.url,
          n,
          t.id
        );
        if (!s) {
          l.debug("Banner cannot be defined", t), t.type === "CORNER" && this.onCornerBannerFinish && this.onCornerBannerFinish(!0);
          return;
        }
        l.debug("Banner defined successfully", {
          adUnitPath: s.getAdUnitPath(),
          slotElementId: s.getSlotElementId()
        }), s.addService(this.googletag.pubads()), this.mapBanners.set(t.id, { ...t, slot: s }), l.debug("Calling googletag.display() for banner", t.id), this.googletag.display(t.id);
      });
    });
  }
  removeBanner(e) {
    const t = this.mapBanners.get(e);
    if (t) {
      if (t.type === "ADHESION") {
        x("FINISHED"), clearTimeout(this.timeOutAdhesion), this.clearSlot(t.slot), this.mapBanners.delete(e);
        return;
      }
      this.clearSlot(t.slot);
    }
  }
  addCallback(e, t, n) {
    this.insideAdCallback = e, this.onCornerBannerFinish = t, this.onCornerBannerLoaded = n;
  }
  destroyCornerAdBanner() {
    const e = this.mapBanners.get("corner-banner");
    e && (clearTimeout(this.timeOutCornerBanner), this.mapBanners.delete("corner-banner"), this.googletag.cmd.push(() => {
      try {
        this.googletag.destroySlots([e.slot]), l.debug("Destroyed corner banner slot");
      } catch (t) {
        l.debug("Error destroying corner banner slot:", t);
      }
    }), this.onCornerBannerFinish(!1), this.insideAdCallback && this.insideAdCallback.insideAdStop());
  }
  /**
   * Destroys the corner banner slot without finishing the ad. Called whenever
   * the corner box goes away, so GPT never keeps a slot whose div is gone
   * ("defineSlot was called without a corresponding DIV") and the next
   * defineSlot on "corner-banner" is not refused as a duplicate.
   */
  releaseCornerSlot() {
    const e = this.mapBanners.get("corner-banner");
    e && (clearTimeout(this.timeOutCornerBanner), this.mapBanners.delete("corner-banner"), this.googletag.cmd.push(() => {
      try {
        this.googletag.destroySlots([e.slot]), l.debug("Released corner banner slot");
      } catch (t) {
        l.debug("Error releasing corner banner slot:", t);
      }
    }));
  }
  clearSlot(e) {
    this.googletag.cmd.push(() => {
      this.googletag.pubads().clear([e]), l.debug("clearing slot", e);
      try {
        const t = e.getSlotElementId();
        this.mapBanners.has(t) && (this.mapBanners.delete(t), l.debug("deleted banner mapping for", t));
      } catch (t) {
        l.debug("Could not delete banner map entry:", t);
      }
    });
  }
  clearAllSlots() {
    l.debug("clearing All slots");
    const e = [...this.mapBanners.values()].map((t) => t.slot);
    clearTimeout(this.timeOutCornerBanner), clearTimeout(this.timeOutAdhesion), this.mapBanners.clear(), !(!this.googletag || !e.length) && this.googletag.cmd.push(() => {
      this.googletag.destroySlots(e);
    });
  }
}
const C = new Lt(), J = 3e4, Rt = 15e3, Nt = 12e4, $e = `
<div id="page-content">
    <div id="video-container">
      <video id="video-element" src="" playsinline webkit-playsinline>
      </video>
      <div id="ad-container"></div>
    </div>
</div>
`, Ot = `
<div id="page-content-split-ad">
 <div id="video-container-split-ad">
      <video id="video-element" src="">
      </video>
      <div id="ad-container"></div>
    </div>
</div>
`, Dt = `
<div class="streann-ima-multiview-content">
 <div class="streann-ima-multiview-video-container">
      <!-- playsinline + muted must be ATTRIBUTES, not just properties: iOS Safari
           refuses inline playback without playsinline (it wants fullscreen) and
           refuses unmuted autoplay, so IMA's ad element fails with adPlayError
           400 the moment it calls play(). Same rule the host app follows for its
           own players. -->
      <video class="streann-ima-video" src="" playsinline webkit-playsinline muted></video>
      <div class="streann-ima-ad-container"></div>
    </div>
</div>
`;
let S, T;
function kt(i) {
  return i instanceof Error ? i.message : String(i);
}
const I = /* @__PURE__ */ new Map();
let Pt = 0;
class he {
  constructor(e) {
    d(this, "id", ++Pt);
    d(this, "slot");
    d(this, "placement");
    d(this, "containerId");
    d(this, "url");
    d(this, "insideAdCallback");
    d(this, "onAdFinish");
    d(this, "onAdLoaded");
    d(this, "onAdStart");
    d(this, "adData");
    d(this, "log");
    d(this, "ima");
    d(this, "vastUrl", "");
    d(this, "videoContent", null);
    d(this, "adContainer", null);
    d(this, "playButton", null);
    d(this, "adDisplayContainer");
    d(this, "adsLoader");
    d(this, "adsManager");
    d(this, "autoplayAllowed", !1);
    d(this, "autoplayRequiresMuted", !1);
    d(this, "adErrorHandled", !1);
    d(this, "ended", !1);
    d(this, "watchdog");
    this.slot = e.slot, this.placement = e.placement, this.containerId = e.containerId, this.url = e.url, this.insideAdCallback = e.insideAdCallback, this.onAdFinish = e.onAdFinish, this.onAdLoaded = e.onAdLoaded, this.onAdStart = e.onAdStart, this.adData = e.ad && e.screen ? { adName: e.ad.name, adType: e.ad.adType, screen: e.screen } : null, this.log = l.scope(`ima:${this.placement}#${this.id}`);
  }
  /** True while this session still owns its slot. */
  isLive() {
    return !this.ended && I.get(this.slot) === this;
  }
  /** Sets the volume of the running ad. 0 is muted, 1 is full volume. */
  setVolume(e) {
    if (!(!this.adsManager || this.ended))
      try {
        this.adsManager.setVolume(e), this.log.info("ad volume set", e);
      } catch (t) {
        this.log.warn("error setting ad volume", t);
      }
  }
  start() {
    const e = I.get(this.slot);
    e && (this.log.warn("taking over a VAST slot that is still claimed", {
      previousSessionId: e.id,
      previousPlacement: e.placement
    }), e.supersede()), I.set(this.slot, this), this.armWatchdog(J, "waiting for the ad to load"), this.log.info("VAST session claimed", { containerId: this.containerId }), pt().then((t) => {
      if (this.ended) {
        this.log.warn("session ended while the IMA script loaded - ad request cancelled");
        return;
      }
      this.ima = t, this.vastUrl = xt(this.url), console.log("[inside-ad] VAST URL before macros:", this.url), console.log("[inside-ad] VAST URL after macros:", this.vastUrl), this.mount() && (this.setUpAdsLoader(), this.checkMutedAutoplaySupport());
    }).catch((t) => {
      this.ended || this.fail(`failed loading the IMA SDK: ${kt(t)}`);
    });
  }
  /**
   * Ends the ad and cleans up after it: the placement is told the ad is over,
   * IMA is torn down and the host container removed. Does nothing once ended.
   */
  destroy() {
    if (this.ended)
      return;
    this.log.info("destroying IMA", { containerId: this.containerId }), this.end(), this.onAdFinish(), this.placement === "CORNER" && Z(!1), this.disposeIma();
    const e = document.getElementById(this.containerId);
    e && (e.remove(), this.restoreMainPlayer()), this.insideAdCallback.insideAdStop();
  }
  // ---------------------------------------------------------------- lifecycle
  /** Leave the slot and stop the watchdog. Every way out of a session runs this. */
  end() {
    this.ended = !0, clearTimeout(this.watchdog), this.watchdog = void 0, I.get(this.slot) === this && I.delete(this.slot);
  }
  /**
   * Another placement took the slot (corner vs split). Stop this ad's IMA
   * objects quietly - the newcomer owns the page now - and let a split ad take
   * its own view down, as it always has when it lost the session.
   */
  supersede() {
    this.end(), this.disposeIma(), this.placement === "SPLIT_AD" && this.onAdFinish();
  }
  /** A failure before IMA could report anything itself. */
  fail(e) {
    this.log.error(`${e} - cancelling`), this.end(), this.insideAdCallback.insideAdError(this.buildAdError(e)), this.onAdFinish(this.placement === "CORNER" ? !0 : void 0);
  }
  disposeIma() {
    if (this.adsManager)
      try {
        this.adsManager.destroy();
      } catch (e) {
        this.log.warn("error destroying adsManager", e);
      }
    if (this.adsLoader)
      try {
        this.adsLoader.contentComplete();
      } catch (e) {
        this.log.warn("error calling adsLoader.contentComplete", e);
      }
    this.videoContent && (this.videoContent.onended = null, this.videoContent.pause());
  }
  restoreMainPlayer() {
    if (this.placement !== "SPLIT_AD")
      return;
    const e = document.getElementById("vjsplayer");
    e && (e.style.width = "100%", e.style.float = "none");
  }
  /**
   * Put a deadline on the session.
   *
   * Every path that ends a VAST ad - destroy, onAdError - ends the session, so a
   * path that ends without either firing would hold the slot for the life of
   * the page. IMA leaves plenty of those open: autoplay refused so
   * adsManager.init is never reached, a VAST response that yields neither
   * ADS_MANAGER_LOADED nor AD_ERROR, COMPLETE without ALL_ADS_COMPLETED, an
   * init/start that throws.
   *
   * So the session carries a deadline that every sign of life pushes out. If it
   * ever expires the session really is stuck, and it is torn down like any
   * other finished ad, so its placement's waterfall or refresh still runs.
   */
  armWatchdog(e, t) {
    clearTimeout(this.watchdog), this.watchdog = setTimeout(() => {
      this.watchdog = void 0, !this.ended && (this.log.error(`VAST session stalled while ${t} - tearing it down`, {
        waitedMs: e
      }), this.destroy());
    }, e);
  }
  /** A sign of life from the running ad: push the deadline out. */
  touch(e, t) {
    this.ended || this.armWatchdog(e, t);
  }
  buildAdError(e, t) {
    var n, s, o;
    return {
      message: e,
      code: t,
      placement: this.placement,
      adType: (n = this.adData) == null ? void 0 : n.adType,
      adName: (s = this.adData) == null ? void 0 : s.adName,
      screen: (o = this.adData) == null ? void 0 : o.screen
    };
  }
  // -------------------------------------------------------------------- setup
  /** Inserts this ad's markup and finds its elements. False when it cannot. */
  mount() {
    const e = this.placement === "CORNER", t = e ? document.querySelector("#streann-node") : document.getElementById(this.containerId);
    if (!t)
      return this.fail(e ? "#streann-node is gone" : `container #${this.containerId} not found`), !1;
    const n = e ? $e : this.placement === "SPLIT_AD" ? Ot : Dt;
    t.insertAdjacentHTML("beforeend", n);
    const s = t.lastElementChild;
    return this.videoContent = s.querySelector("video"), this.adContainer = s.querySelector("#ad-container, .streann-ima-ad-container"), this.playButton = e ? document.getElementById("playButton") : t.querySelector("#playButton"), !this.videoContent || !this.adContainer ? (this.fail(`no ad container inside #${e ? "streann-node" : this.containerId}`), !1) : (e ? ["un-mute", "mute", "cornerCloseButton", "streann-logo"].forEach((o) => {
      const r = document.getElementById(o);
      r && (r.style.display = "none");
    }) : this.adContainer.style.display = "none", this.log.info("IMA mounted", {
      containerId: this.containerId,
      slot: `${this.videoContent.clientWidth}x${this.videoContent.clientHeight}`
    }), !0);
  }
  setUpAdsLoader() {
    const e = this.ima;
    this.adDisplayContainer = new e.AdDisplayContainer(this.adContainer, this.videoContent), this.adsLoader = new e.AdsLoader(this.adDisplayContainer), this.adsLoader.getSettings().setDisableCustomPlaybackForIOS10Plus(!0), this.adsLoader.addEventListener(
      e.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
      (t) => this.onAdsManagerLoaded(t),
      !1
    ), this.adErrorHandled = !1, this.adsLoader.addEventListener(
      e.AdErrorEvent.Type.AD_ERROR,
      (t) => this.onAdError(t),
      !1
    ), this.videoContent.onended = () => this.contentEnded();
  }
  /** Checks whether video can autoplay while muted, then requests the ad. */
  checkMutedAutoplaySupport() {
    const e = this.videoContent;
    e.volume = 0, e.muted = !0;
    const t = (s, o) => {
      this.ended || (e.pause(), s ? this.log.info("muted autoplay is supported") : (l.debug("Autoplay check: muted autoplay FAILED (continuing as muted anyway)", (o == null ? void 0 : o.message) || o), this.log.warn("muted autoplay was refused - requesting the ad anyway")), this.autoplayAllowed = !0, this.autoplayRequiresMuted = !0, this.requestAds());
    }, n = e.play();
    n !== void 0 && n.then(() => t(!0)).catch((s) => t(!1, s));
  }
  requestAds() {
    const e = this.videoContent, t = new this.ima.AdsRequest();
    t.adTagUrl = this.vastUrl, t.linearAdSlotWidth = e.clientWidth, t.linearAdSlotHeight = e.clientHeight, t.nonLinearAdSlotWidth = e.clientWidth, t.nonLinearAdSlotHeight = e.clientHeight / 3, t.vastLoadTimeout = 1e4, t.setAdWillAutoPlay(this.autoplayAllowed), t.setAdWillPlayMuted(this.autoplayRequiresMuted), this.log.info("requesting ads", {
      slot: `${t.linearAdSlotWidth}x${t.linearAdSlotHeight}`,
      autoplayAllowed: this.autoplayAllowed,
      autoplayRequiresMuted: this.autoplayRequiresMuted,
      tag: this.vastUrl
    }), this.adsLoader.requestAds(t), this.adData && $.trackAdRequested(this.adData.screen);
  }
  playAds() {
    const e = this.videoContent;
    try {
      this.adDisplayContainer.initialize(), this.adsManager.init(e.clientWidth, e.clientHeight, this.ima.ViewMode.NORMAL), this.adsManager.start();
    } catch (t) {
      this.log.error("adsManager.init/start threw - falling back to content", t), e.play();
    }
  }
  // ------------------------------------------------------------------- events
  onAdsManagerLoaded(e) {
    if (this.ended)
      return;
    l.debug("IMA AdsManager loaded (VAST response has an ad)");
    const t = this.ima, n = new t.AdsRenderingSettings();
    n.restoreCustomPlaybackStateOnAdBreakComplete = !0, n.loadVideoTimeout = 15e3;
    const s = e.getAdsManager(this.videoContent, n);
    this.adsManager = s, s.setVolume(0), this.adErrorHandled = !1;
    const o = (r) => this.onAdEvent(r);
    s.addEventListener(t.AdErrorEvent.Type.AD_ERROR, (r) => this.onAdError(r)), s.addEventListener(t.AdEvent.Type.CONTENT_PAUSE_REQUESTED, () => this.onContentPauseRequested()), s.addEventListener(t.AdEvent.Type.CONTENT_RESUME_REQUESTED, () => this.onContentResumeRequested()), s.addEventListener(t.AdEvent.Type.ALL_ADS_COMPLETED, o), s.addEventListener(t.AdEvent.Type.LOADED, o), s.addEventListener(t.AdEvent.Type.STARTED, o), s.addEventListener(t.AdEvent.Type.IMPRESSION, o), s.addEventListener(t.AdEvent.Type.COMPLETE, o), this.autoplayAllowed ? (this.log.info("ads manager loaded - starting playback"), this.playAds()) : this.playButton ? (this.log.info("ads manager loaded - waiting for a click to play"), this.playButton.style.display = "block") : (this.log.warn("ads manager loaded but no autoplay and no play button - tearing down"), this.destroy());
  }
  onAdEvent(e) {
    var s, o, r, a, c, u, f, h, p, y, B, m, D;
    if (this.ended)
      return;
    const t = this.ima, n = e.getAd();
    switch (this.log.info(`ad event: ${e.type}`, n ? {
      adId: (s = n.getAdId) == null ? void 0 : s.call(n),
      title: (o = n.getTitle) == null ? void 0 : o.call(n),
      duration: (r = n.getDuration) == null ? void 0 : r.call(n),
      linear: (a = n.isLinear) == null ? void 0 : a.call(n)
    } : void 0), e.type) {
      case t.AdEvent.Type.LOADED:
        this.touch(J, "the ad media loads"), this.insideAdCallback.insideAdLoaded(), n.isLinear() || (c = this.videoContent) == null || c.play();
        break;
      case t.AdEvent.Type.STARTED: {
        this.insideAdCallback.insideAdPlay(), this.adData && $.trackAdDisplayed(
          this.adData.adName,
          this.adData.adType,
          this.adData.screen
        ), this.log.info("ad STARTED", {
          adId: (u = n == null ? void 0 : n.getAdId) == null ? void 0 : u.call(n),
          duration: (f = n == null ? void 0 : n.getDuration) == null ? void 0 : f.call(n),
          size: n ? `${(h = n.getWidth) == null ? void 0 : h.call(n)}x${(p = n.getHeight) == null ? void 0 : p.call(n)}` : void 0,
          linear: (y = n == null ? void 0 : n.isLinear) == null ? void 0 : y.call(n)
        });
        const fe = Number((B = n == null ? void 0 : n.getDuration) == null ? void 0 : B.call(n)) * 1e3;
        if (this.touch(
          fe > 0 ? fe + Rt : Nt,
          "the ad plays"
        ), (m = this.onAdStart) == null || m.call(this), this.adContainer && (this.adContainer.style.display = "block"), this.placement === "SPLIT_AD") {
          const j = document.getElementById("vjsplayer");
          j && (j.style.width = "50%", j.style.float = "right");
        }
        break;
      }
      case t.AdEvent.Type.IMPRESSION:
        this.placement === "CORNER" && (Z(!0), (D = this.onAdLoaded) == null || D.call(this));
        break;
      case t.AdEvent.Type.CLICK:
        this.insideAdCallback.insideAdClicked();
        break;
      case t.AdEvent.Type.SKIPPED:
        this.destroy(), this.insideAdCallback.insideAdSkipped();
        break;
      case t.AdEvent.Type.ALL_ADS_COMPLETED:
        this.destroy();
        break;
      case t.AdEvent.Type.COMPLETE:
        this.touch(
          J,
          "waiting for the next ad in the pod or ALL_ADS_COMPLETED"
        );
        break;
    }
  }
  onAdError(e) {
    var n;
    const t = e.getError();
    if (this.ended || this.adErrorHandled) {
      this.log.warn("VAST error ignored - the session already ended", {
        errorCode: t.getErrorCode(),
        errorMessage: t.getMessage()
      });
      return;
    }
    this.adErrorHandled = !0, this.log.error("VAST ad error - tearing down and triggering the fallback", {
      errorCode: t.getErrorCode(),
      errorMessage: t.getMessage(),
      errorType: t.getType(),
      containerId: this.containerId
    }), this.end(), (n = document.getElementById(this.containerId)) == null || n.remove(), this.restoreMainPlayer(), this.disposeIma(), this.placement === "CORNER" && Z(!1), this.insideAdCallback.insideAdError(
      this.buildAdError(t.getMessage(), t.getErrorCode())
    ), l.debug("VAST error cleanup complete - calling onAdFinish(true) to trigger waterfall"), this.onAdFinish(!0);
  }
  contentEnded() {
    var e;
    this.videoContent && (this.videoContent.onended = null), (e = this.adsLoader) == null || e.contentComplete();
  }
  onContentPauseRequested() {
    this.ended || !this.videoContent || (this.videoContent.pause(), this.videoContent.onended = null);
  }
  onContentResumeRequested() {
    this.ended || !this.videoContent || (this.videoContent.onended = () => this.contentEnded());
  }
}
function Mt(i, e, t, n, s, o) {
  l.debug("initImaSdk called - starting VAST ad request", {
    vastUrl: e,
    timestamp: (/* @__PURE__ */ new Date()).toISOString()
  }), new he({
    slot: "CORNER_SPLIT",
    placement: "CORNER",
    // The corner hosts IMA in #page-content (inside #streann-node).
    containerId: "page-content",
    url: e,
    insideAdCallback: i,
    onAdFinish: t,
    onAdLoaded: n,
    ad: s,
    screen: o
  }).start();
}
function _t(i, e, t, n, s, o) {
  new he({
    slot: "CORNER_SPLIT",
    placement: "SPLIT_AD",
    containerId: n,
    url: e,
    insideAdCallback: i,
    onAdFinish: t,
    ad: s,
    screen: o
  }).start();
}
function Vt(i) {
  return !I.has(i);
}
function Ut(i, e, t, n, s, o, r) {
  const a = n.includes("right-bar") ? "MULTIVIEW_RIGHT_BAR" : "MULTIVIEW_CANVAS", c = I.get(a);
  if (c)
    return l.scope("ima").warn("VAST ad already running in this slot - refusing multiview request", {
      slot: a,
      containerId: n,
      owningSessionId: c.id
    }), null;
  const u = new he({
    slot: a,
    placement: a,
    containerId: n,
    url: e,
    insideAdCallback: i,
    onAdFinish: t,
    onAdStart: r,
    ad: s,
    screen: o
  });
  return u.start(), u;
}
function Ht() {
  var i;
  (i = I.get("CORNER_SPLIT")) == null || i.destroy();
}
const Ft = {
  "[STREANN-PLAYER-HEIGHT]": () => window.innerHeight.toString(),
  "[STREANN-PLAYER-WIDTH]": () => window.innerWidth.toString(),
  "[STREANN-APP-BUNDLE-ID]": () => "",
  "[STREANN-APP-NAME]": () => "",
  "[STREANN-APP-VERSION]": () => "",
  "[STREANN-APP-DOMAIN]": () => "",
  "[STREANN-APP-STORE-URL]": () => "",
  "[STREANN-SITE-URL]": () => `${window.location.origin}${window.location.pathname}`,
  "[STREANN-CONTENT-ID]": () => localStorage.getItem("streannContentId") || "",
  "[STREANN-CONTENT-TITLE]": () => localStorage.getItem("streannContentTitle") || "",
  "[STREANN-CONTENT-LENGTH]": () => "",
  "[STREANN-CONTENT-URL]": () => window.location.href,
  "[STREANN-CONTENT-ENCODED-URL]": () => "",
  "[STREANN-DESCRIPTION-URL]": () => "",
  "[STREANN-DEVICE-ID]": () => "",
  "[STREANN-NETWORK]": () => "",
  "[STREANN-CARRIER]": () => "",
  "[STREANN-DEVICE-MANUFACTURER]": () => "",
  "[STREANN-DEVICE-MODEL]": () => "",
  "[STREANN-DEVICE-OS]": () => "",
  "[STREANN-DEVICE-OS-VERSION]": () => "",
  "[STREANN-DEVICE-TYPE]": () => "web",
  "[STREANN-IP]": () => "https://geoip.streann.com/",
  "[STREANN-UA]": () => navigator.userAgent,
  "[STREANN-IFA-TYPE]": () => "",
  "[STREANN-ADVERTISING-ID]": () => "",
  "[STREANN-ADVERTISING-ID-HEX]": () => "",
  "[STREANN-ADVERTISING-ID-MD5]": () => "",
  "[STREANN-IDFA]": () => "",
  "[STREANN-IDFA-MD5]": () => "",
  "[STREANN-IDFA-HEX]": () => "",
  "[STREANN-LOCATION-LAT]": () => "",
  "[STREANN-LOCATION-LONG]": () => "",
  "[STREANN-COUNTRY-ID]": () => localStorage.getItem("streannCountryId") || "",
  "[STREANN-DO-NOT-TRACK]": () => "",
  "[STREANN-GDPR]": () => "",
  "[STREANN-GDPR-CONSENT]": () => "",
  "[STREANN-USER-BIRTHYEAR]": () => "",
  "[STREANN-USER-GENDER]": () => "",
  // Numeric only: timestamp + random digits
  "[STREANN-CACHEBUSTER]": () => `${Date.now()}${Math.floor(Math.random() * 1e6).toString().padStart(6, "0")}`,
  "[STREANN-US-PRIVACY]": () => ""
};
function xt(i) {
  return Object.entries(Ft).reduce(
    (e, [t, n]) => e.includes(t) ? e.split(t).join(n()) : e,
    i
  );
}
let ae;
function $t(i, e, t) {
  var r, a;
  ae = t, (r = document.querySelector("#streann-node")) == null || r.insertAdjacentHTML("beforeend", $e);
  const n = document.getElementById("video-element");
  S = document.getElementById("mute"), T = document.getElementById("un-mute");
  const s = document.getElementById("cornerCloseButton"), o = document.getElementById("streann-logo");
  (a = document.getElementById("video-container")) == null || a.append(T, S), s && (s.style.display = "none"), o && (o.style.display = "none"), T.style.display = "none", S.style.display = "none", n.muted = !0, n.defaultMuted = !0, n.setAttribute("muted", ""), n.setAttribute("playsinline", ""), n.src = i.url, n.load(), l.debug("Local video ad: loading", { url: i.url, name: i.name }), n.addEventListener("error", () => {
    var c, u;
    l.debug("Local video ad: video ERROR", { code: (c = n.error) == null ? void 0 : c.code, message: (u = n.error) == null ? void 0 : u.message }), pe(!0);
  }, { once: !0 }), n.addEventListener("playing", () => {
    l.debug("Local video ad: playing", { duration: n.duration }), o && (o.style.display = "block"), n.muted ? (T.style.display = "block", S.style.display = "none") : (T.style.display = "none", S.style.display = "block"), e && e();
  }, { once: !0 }), n.play().catch(function(c) {
    l.debug("Local video ad: autoplay FAILED", c == null ? void 0 : c.name, c == null ? void 0 : c.message);
  }), n.addEventListener("click", function() {
    i.properties.clickThroughUrl && window.open(i.properties.clickThroughUrl, "_blank");
  }), n.addEventListener("ended", ze), S.addEventListener("click", () => {
    n.muted = !0, S.style.display = "none", T.style.display = "block";
  }), T.addEventListener("click", () => {
    n.muted = !1, T.style.display = "none", S.style.display = "block";
  });
}
function ze() {
  l.debug("Local video ad: ended"), pe();
}
function pe(i = !1) {
  const e = document.getElementById("video-element");
  e && (e.pause(), e.removeEventListener("ended", ze), e.style.display = "none");
  const t = document.getElementById("page-content");
  if (t) {
    const s = document.getElementById("streann-node"), o = [document.getElementById("un-mute"), document.getElementById("mute")].filter((r) => !!r);
    o.forEach((r) => r.style.display = "none"), s == null || s.append(...o), t.remove();
  }
  const n = ae;
  ae = void 0, n && n(i);
}
function Z(i) {
  const e = document.getElementById("streann-logo");
  i ? e && (e.style.display = "block") : e && (e.style.display = "none");
}
const R = class R {
  constructor(e, t, n) {
    d(this, "placement");
    // private ad : any;
    d(this, "counterFailedCornerAd", 0);
    d(this, "insideAdCallback");
    d(this, "currentAd");
    d(this, "closeButtonTimer");
    d(this, "adInProgress", !1);
    d(this, "lastAttemptTime", 0);
    d(this, "currentAttemptCount", 0);
    d(this, "finishing", !1);
    var o, r, a, c;
    this.placement = e, this.insideAdCallback = n;
    const s = 1;
    l.debug(`Corner placement "${e.name}": ad "${t == null ? void 0 : t.name}" (${t == null ? void 0 : t.adType}) starts in ${s}s`, {
      adminStartAfterSeconds: (o = e.properties) == null ? void 0 : o.startAfterSeconds,
      showCloseButtonAfterSeconds: (r = e.properties) == null ? void 0 : r.showCloseButtonAfterSeconds,
      styles: (c = (a = e.properties) == null ? void 0 : a.webSettings) == null ? void 0 : c.styles,
      fallback: t != null && t.fallback ? `${t.fallback.adType} "${t.fallback.name}"` : null
    }), this.counterFailedCornerAd = 0, setTimeout(() => {
      this.startAd(t);
    }, Number(s) * 1e3);
  }
  cornerElem(e) {
    return `
  <div id="streann-node" style="${e}">
    <div id="cornerCloseButton" class="closeButton" role="button" aria-label="Close ad">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" aria-hidden="true">
        <path d="M6 6l12 12M18 6L6 18"/>
      </svg>
    </div>
    <div id="streann-logo" class="streann-logo" style="display: none;">
      <a href="https://streann.com/" target="_blank">
        <img src="https://img.streann.com/streann-img/559ff7ade4b0d0aff40888dd/uploads/images/754c4884-ab89-4331-9134-bbe6f89bde28/NEW_Streann-Logo-Icon-Inside-Corner.png" class="logo" alt="streann-logo">    
      </a>
    </div>
    <div id="un-mute" class="un-mute" style="display: none;">
      <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-volume-mute-fill" viewBox="0 0 16 16">
        <path d="M6.717 3.55A.5.5 0 0 1 7 4v8a.5.5 0 0 1-.812.39L3.825 10.5H1.5A.5.5 0 0 1 1 10V6a.5.5 0 0 1 .5-.5h2.325l2.363-1.89a.5.5 0 0 1 .529-.06m7.137 2.096a.5.5 0 0 1 0 .708L12.207 8l1.647 1.646a.5.5 0 0 1-.708.708L11.5 8.707l-1.646 1.647a.5.5 0 0 1-.708-.708L10.793 8 9.146 6.354a.5.5 0 1 1 .708-.708L11.5 7.293l1.646-1.647a.5.5 0 0 1 .708 0"/>
      </svg>
    </div>
    <div class="mute" id="mute" style="display: none;">
      <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-volume-up-fill" viewBox="0 0 16 16">
        <path d="M11.536 14.01A8.47 8.47 0 0 0 14.026 8a8.47 8.47 0 0 0-2.49-6.01l-.708.707A7.48 7.48 0 0 1 13.025 8c0 2.071-.84 3.946-2.197 5.303z"/>
        <path d="M10.121 12.596A6.48 6.48 0 0 0 12.025 8a6.48 6.48 0 0 0-1.904-4.596l-.707.707A5.48 5.48 0 0 1 11.025 8a5.48 5.48 0 0 1-1.61 3.89z"/>
        <path d="M8.707 11.182A4.5 4.5 0 0 0 10.025 8a4.5 4.5 0 0 0-1.318-3.182L8 5.525A3.5 3.5 0 0 1 9.025 8 3.5 3.5 0 0 1 8 10.475zM6.717 3.55A.5.5 0 0 1 7 4v8a.5.5 0 0 1-.812.39L3.825 10.5H1.5A.5.5 0 0 1 1 10V6a.5.5 0 0 1 .5-.5h2.325l2.363-1.89a.5.5 0 0 1 .529-.06"/>
      </svg>
    </div>
  </div>
`;
  }
  // Delay before trying next ad in waterfall
  startAd(e) {
    var s, o, r, a;
    if (this.adInProgress) {
      l.debug("BLOCKED: Ad already in progress, skipping startAd", {
        blockedAdType: e.adType,
        blockedAdName: e.name,
        currentAdInProgress: (s = this.currentAd) == null ? void 0 : s.adType
      });
      return;
    }
    const t = Date.now(), n = t - this.lastAttemptTime;
    if (this.currentAttemptCount > 0 && n < R.MIN_RETRY_DELAY && this.lastAttemptTime > 0) {
      const c = R.MIN_RETRY_DELAY - n;
      l.debug("RATE LIMITED: Delaying startAd", {
        adType: e.adType,
        adName: e.name,
        delayMs: c
      }), setTimeout(() => this.startAd(e), c);
      return;
    }
    if (this.lastAttemptTime = t, this.currentAttemptCount++, l.debug("Starting ad attempt", {
      adType: e.adType,
      adName: e.name,
      attemptNumber: this.currentAttemptCount,
      waterfallDepth: this.counterFailedCornerAd
    }), this.adInProgress = !0, this.currentAd = e, this.createCornerAdView(), this.fitCornerToAd(e), e.adType == E.VAST) {
      const c = ((a = (r = (o = this.placement.properties) == null ? void 0 : o.webSettings) == null ? void 0 : r.screens) == null ? void 0 : a[0]) || window.location.pathname;
      Mt(
        this.insideAdCallback,
        e.url,
        this.onAdFinish.bind(this),
        this.startCloseButtonTimer.bind(this),
        // Start timer only when VAST ad loads
        e,
        c
      );
    } else if (e.adType == E.BANNER) {
      C.addCallback(
        this.insideAdCallback,
        this.onAdFinish.bind(this),
        (u) => {
          this.fitCornerToRenderedBanner(u), this.startCloseButtonTimer();
        }
      );
      const c = {
        duration: e.properties.durationInSeconds,
        id: "corner-banner",
        sizes: e.properties.sizes,
        type: "CORNER",
        url: e.url
      };
      C.addBanners([c]);
    } else
      e.adType == E.LOCAL_VIDEO ? $t(
        e,
        this.startCloseButtonTimer.bind(this),
        // Start timer only when the video is playing
        this.onAdFinish.bind(this)
      ) : l.debug("AD TYPE NOT SUPPORTED");
  }
  cornerStyle() {
    var e, t;
    return ((t = (e = this.placement.properties) == null ? void 0 : e.webSettings) == null ? void 0 : t.styles) || `
      position: fixed;
      bottom: 0;
      right: 0;
      z-index: 1000;
      width: 300px;
      height: 250px;
    `;
  }
  createCornerAdView() {
    var n, s, o;
    if (document.getElementById("streann-node")) {
      const r = document.getElementById("cornerCloseButton");
      r && (r.style.display = "none");
      return;
    }
    const t = this.cornerStyle();
    l.debug("Creating corner container", { style: t.replace(/\s+/g, " ").trim() }), (n = document.querySelector("body")) == null || n.insertAdjacentHTML("beforeend", this.cornerElem(t || "")), ((s = this.currentAd) == null ? void 0 : s.adType) != E.BANNER && ((o = document.getElementById("streann-node")) == null || o.style.removeProperty("height"));
  }
  /**
   * A banner needs a box at least as big as its largest size before GPT requests it.
   * The admin height can be smaller than the creative (240px for a 300x250), and after
   * a VAST attempt the reused box has no height at all, so GPT was asked to fill a
   * collapsed slot. min-* wins over the admin height, even when it is !important.
   */
  fitCornerToAd(e) {
    var r;
    const t = document.getElementById("streann-node");
    if (!t)
      return;
    t.setAttribute("style", this.cornerStyle()), e.adType != E.BANNER && t.style.removeProperty("height");
    const n = e.adType == E.BANNER ? ((r = e.properties) == null ? void 0 : r.sizes) ?? [] : [];
    if (!n.length) {
      t.style.removeProperty("min-width"), t.style.removeProperty("min-height");
      return;
    }
    const s = Math.max(...n.map((a) => a.width)), o = Math.max(...n.map((a) => a.height));
    t.style.setProperty("min-width", `min(${s}px, 100vw)`), t.style.setProperty("min-height", `${o}px`);
  }
  /**
   * GPT centers the creative in its slot, so a box wider than the banner (an admin
   * width, or the 320px of a 300x50 / 320x50 slot) leaves the logo and close button
   * at the box edges, floating beside the ad. Once rendered, the box takes the size
   * Google actually served so they sit on the banner's corners.
   */
  fitCornerToRenderedBanner(e) {
    const t = document.getElementById("streann-node");
    if (!t || !Array.isArray(e))
      return;
    const [n, s] = e;
    t.style.removeProperty("min-width"), t.style.removeProperty("min-height"), t.style.setProperty("width", `${n}px`, "important"), t.style.setProperty("height", `${s}px`, "important");
  }
  // Call this when ad successfully loads (from bannerService or ima)
  startCloseButtonTimer() {
    var t, n;
    const e = document.getElementById("streann-node");
    if (e) {
      const s = e.getBoundingClientRect(), { clientWidth: o, clientHeight: r } = document.documentElement;
      l.debug(`Corner ad visible (${(t = this.currentAd) == null ? void 0 : t.adType})`, {
        size: `${Math.round(s.width)}x${Math.round(s.height)}`,
        offset: `right ${Math.round(o - s.right)}px, bottom ${Math.round(r - s.bottom)}px`,
        viewport: `${o}x${r}`,
        appliedStyle: e.getAttribute("style")
      });
    }
    if (((n = this.currentAd) == null ? void 0 : n.adType) == E.BANNER) {
      const s = document.getElementById("streann-logo");
      s && (s.style.display = "block");
    }
    this.showCloseButton();
  }
  showCloseButton() {
    if (this.closeButtonTimer && (clearTimeout(this.closeButtonTimer), this.closeButtonTimer = void 0), this.placement.properties.showCloseButtonAfterSeconds != null) {
      const e = this.placement.properties.showCloseButtonAfterSeconds;
      this.closeButtonTimer = setTimeout(() => {
        const t = document.getElementById("cornerCloseButton");
        t && (t.onclick = this.handleOnCloseButton.bind(this), t.style.setProperty("display", "block"), l.debug(`Close button shown (after ${e}s)`));
      }, Number(e) * 1e3);
    }
  }
  handleOnCloseButton() {
    var e, t, n;
    l.debug("Corner ad close button clicked"), ((e = this.currentAd) == null ? void 0 : e.adType) == E.BANNER ? C.destroyCornerAdBanner() : ((t = this.currentAd) == null ? void 0 : t.adType) == E.VAST ? Ht() : ((n = this.currentAd) == null ? void 0 : n.adType) == E.LOCAL_VIDEO ? pe() : l.debug("Closing UnSupperoted ad type");
  }
  onAdFinish(e = !1) {
    var r, a, c, u, f, h, p, y, B;
    if (this.finishing)
      return;
    this.finishing = !0, this.adInProgress = !1, ((r = this.currentAd) == null ? void 0 : r.adType) == E.BANNER && C.releaseCornerSlot(), this.closeButtonTimer && (clearTimeout(this.closeButtonTimer), this.closeButtonTimer = void 0), l.debug("cornerAd finished", {
      withError: e,
      failedAttempts: this.counterFailedCornerAd,
      currentAdType: (a = this.currentAd) == null ? void 0 : a.adType,
      currentAdName: (c = this.currentAd) == null ? void 0 : c.name,
      hasFallback: !!((u = this.currentAd) != null && u.fallback)
    });
    const t = (f = this.currentAd) == null ? void 0 : f.fallback;
    if (t && e && this.counterFailedCornerAd < 20) {
      l.debug("cornerAd starting waterfall ad", {
        adId: t.id,
        adName: t.name,
        adType: t.adType,
        waterfallDepth: this.counterFailedCornerAd + 1
      }), this.counterFailedCornerAd++;
      const m = document.getElementById("cornerCloseButton"), D = document.getElementById("streann-logo");
      m && (m.style.display = "none"), D && (D.style.display = "none"), this.finishing = !1, setTimeout(() => {
        this.startAd(t);
      }, R.WATERFALL_RETRY_DELAY);
      return;
    }
    e && !t ? l.debug("cornerAd waterfall EXHAUSTED - no more fallbacks", {
      lastAdType: (h = this.currentAd) == null ? void 0 : h.adType,
      lastAdName: (p = this.currentAd) == null ? void 0 : p.name,
      totalAttempts: this.counterFailedCornerAd + 1
    }) : e && this.counterFailedCornerAd >= 20 && l.debug("cornerAd waterfall MAX RETRIES reached", {
      lastAdType: (y = this.currentAd) == null ? void 0 : y.adType,
      lastAdName: (B = this.currentAd) == null ? void 0 : B.name,
      totalAttempts: this.counterFailedCornerAd + 1
    });
    const n = e ? 0 : 1e3;
    this.counterFailedCornerAd = 0, this.currentAttemptCount = 0, this.lastAttemptTime = 0;
    const s = document.getElementById("cornerCloseButton"), o = document.getElementById("streann-logo");
    s && (s.style.display = "none"), o && (o.style.display = "none"), setTimeout(() => {
      const m = document.getElementById("streann-node");
      m && (m.remove(), l.debug("Corner ad removed", m.id)), this.finishing = !1, this.insideAdCallback && this.insideAdCallback.insideAdStop();
    }, n);
  }
};
d(R, "MIN_RETRY_DELAY", 1e3), // 1 second between attempts
d(R, "WATERFALL_RETRY_DELAY", 500);
let de = R;
class zt {
  constructor(e, t) {
    var c, u, f;
    const n = {
      id: "",
      duration: t.properties.durationInSeconds,
      sizes: t.properties.sizes,
      type: "EMBED",
      url: t.url
    }, s = (c = e.properties) == null ? void 0 : c.webSettings;
    if (!s)
      return;
    const { elemId: o, parentXpath: r, advancedScript: a } = s;
    if (o) {
      const h = document.getElementById(o);
      if (!h)
        return;
      const p = (f = (u = e.properties) == null ? void 0 : u.webSettings) == null ? void 0 : f.styles;
      p && h.setAttribute("style", p), n.id = o;
    } else if (r) {
      const h = this.getElementByXpath(r);
      if (!h)
        return;
      if (document.getElementById(e.id))
        n.id = e.id;
      else {
        const y = this.generateElement(e);
        h.appendChild(y), n.id = e.id;
      }
    } else if (a) {
      const h = new Function(a)();
      if (!document.getElementById(h))
        return;
      n.id = h;
    } else
      return;
    C.addBanners([n]);
  }
  getElementByXpath(e) {
    return document.evaluate(
      e,
      document,
      null,
      XPathResult.FIRST_ORDERED_NODE_TYPE,
      null
    ).singleNodeValue;
  }
  generateElement(e) {
    var s, o;
    const t = document.createElement("div");
    t.setAttribute("id", e.id);
    const n = (o = (s = e.properties) == null ? void 0 : s.webSettings) == null ? void 0 : o.styles;
    return n && t.setAttribute("style", n), t;
  }
  randId() {
    return Math.random().toString(36).replace("0.", "inside-ad");
  }
}
class Wt {
  constructor() {
    d(this, "adHeasonElem", `<div id="streann-adhesion">
    <div class="adhesion-container">
        <div id="adhesion">
        </div>
    </div>
    <div class="close-btn-container">
    <button id='adHesionCloseBtn' class="closeButton">x</button>
    </div>
</div>`);
    d(this, "lastShownLocation", "");
    d(this, "adHesionTimeout");
  }
  setAd(e, t) {
    if (this.lastShownLocation == location.pathname)
      return;
    Bt().subscribe({
      next: (s) => {
        switch (s) {
          case "REQUESTED":
            this.lastShownLocation = location.pathname;
            break;
          case "ERROR":
            this.onAdFinish();
            break;
          case "STARTED":
            break;
          case "FINISHED":
            this.onAdFinish();
            break;
        }
      }
    });
    const n = e.properties.startAfterSeconds;
    n != null ? (clearTimeout(this.adHesionTimeout), this.adHesionTimeout = setTimeout(() => {
      this.startAd(t);
    }, Number(n) * 1e3)) : this.startAd(t);
  }
  onCloseButton() {
    C.removeBanner("adhesion");
  }
  createAdHeasonElem() {
    var t;
    (t = document.querySelector("body")) == null || t.insertAdjacentHTML("beforeend", this.adHeasonElem);
    const e = document.getElementById("adHesionCloseBtn");
    e && (e.style.setProperty("display", "block"), e.onclick = this.onCloseButton.bind(this));
  }
  startAd(e) {
    x("REQUESTED"), this.createAdHeasonElem();
    const t = {
      duration: e.properties.durationInSeconds,
      id: "adhesion",
      sizes: e.properties.sizes,
      type: "ADHESION",
      url: e.url
      // url: "/22290518902/flexflix_web_corner_rectangle",
    };
    C.addBanners([t]);
  }
  onAdFinish() {
    var e;
    (e = document.getElementById("streann-adhesion")) == null || e.remove();
  }
}
const We = new Wt(), Be = l.scope("splitAd");
class Yt {
  constructor(e, t, n) {
    d(this, "placement");
    d(this, "ad");
    d(this, "insideAdCallback");
    d(this, "currentAd");
    d(this, "insideAdActive", !1);
    this.placement = e, this.ad = t, this.insideAdCallback = n, setTimeout(() => {
      this.startAd(t);
    }, Number(5) * 1e3), window.addEventListener("popstate", this.removeAd.bind(this)), window.addEventListener("hashchange", this.removeAd.bind(this));
  }
  splitAdElem(e) {
    return `<div id="streann-splitad" style="${e};height: 100vh; background: black; display: flex; justify-content: center; align-items: center; position: relative;">
            <video id="ad-player" style="width: 100%; height: 100%;"></video>
            <button id="cornerUnmuteSplitAdButton" class="split-ad-unmute-btn"></button>
            <button id="cornerCloseSplitAdButton" class="split-ad-close-btn">Skip Ad</button>
        </div>`;
  }
  initLocalVideoAd_(e) {
    const t = document.getElementById("ad-player");
    t ? (t.style.display = "none", t.addEventListener("play", () => {
      t.style.display = "block";
    }), t.src = e.url, t.muted = !0, t.autoplay = !0, t.addEventListener("error", () => {
      var n, s;
      this.failAd(
        this.adError(
          `local video failed to load (${e.url}): ${((n = t.error) == null ? void 0 : n.message) || "unknown media error"}`,
          (s = t.error) == null ? void 0 : s.code
        )
      );
    }), t.play().catch((n) => {
      Be.warn("muted autoplay refused", n);
    }), t.addEventListener("ended", () => {
      var s;
      (s = document.getElementById("streann-splitad")) == null || s.remove();
      const n = document.getElementById("vjsplayer");
      n && (n.style.width = "100%", n.style.float = "none");
    })) : this.failAd(this.adError("ad player element not found"));
  }
  /**
   * Tears the ad down and reports why, so the failure reaches analytics and
   * the host page instead of the slot just staying empty. VAST errors do not
   * come through here - IMA reports those itself.
   */
  failAd(e) {
    this.removeAd(), this.insideAdCallback.insideAdError(e);
  }
  adError(e, t) {
    var n, s, o, r, a;
    return {
      message: e,
      code: t,
      placement: this.placement.viewType,
      adType: (n = this.currentAd) == null ? void 0 : n.adType,
      adName: (s = this.currentAd) == null ? void 0 : s.name,
      screen: ((a = (r = (o = this.placement.properties) == null ? void 0 : o.webSettings) == null ? void 0 : r.screens) == null ? void 0 : a[0]) || window.location.pathname
    };
  }
  startAd(e) {
    var n, s, o;
    if (this.insideAdActive)
      return;
    this.insideAdActive = !0;
    const t = localStorage.getItem("streannShowSplitAd");
    if (this.cleanupExistingAdContainer(), !t || t === "false") {
      Be.warn("no ads in player"), this.insideAdActive = !1;
      return;
    } else {
      this.currentAd = e;
      const r = document.querySelector("body");
      if (r && (r.classList.remove("flex-column"), r.classList.add("flex-row-reverse")), e.adType === "LOCAL_VIDEO")
        this.createSplitAdView(), this.initLocalVideoAd_(e);
      else if (e.adType === "VAST") {
        this.createSplitAdViewVast();
        const a = ((o = (s = (n = this.placement.properties) == null ? void 0 : n.webSettings) == null ? void 0 : s.screens) == null ? void 0 : o[0]) || window.location.pathname;
        _t(this.insideAdCallback, e.url, this.removeAd.bind(this), "split-ad-container", e, a);
      } else
        this.failAd(this.adError(`ad type ${e.adType} is not supported`));
    }
  }
  createSplitAdViewVast() {
    const e = document.createElement("div");
    e.id = "split-ad-container", e.style.setProperty("width", "50%", "important"), e.style.background = "black", e.style.height = "100vh", e.style.display = "flex", e.style.justifyContent = "center", e.style.alignItems = "center", document.body.appendChild(e);
  }
  createSplitAdView() {
    var n, s, o;
    const e = document.getElementById("vjsplayer");
    e && (e.style.width = "50%", e.style.float = "right", e.style.height = "100vh", e.style.display = "flex", e.style.justifyContent = "center", e.style.alignItems = "center");
    const t = ((s = (n = this.placement.properties) == null ? void 0 : n.webSettings) == null ? void 0 : s.styles) || "";
    (o = document.querySelector("body")) == null || o.insertAdjacentHTML("beforeend", this.splitAdElem(t)), this.showCloseButton(), this.showUnmuteButton();
  }
  showCloseButton() {
    if (this.placement.properties.showCloseButtonAfterSeconds != null) {
      const e = document.getElementById("cornerCloseSplitAdButton");
      if (!e)
        return;
      const t = this.placement.properties.showCloseButtonAfterSeconds;
      e.style.setProperty("display", "none"), setTimeout(() => {
        e.onclick = this.handleOnCloseButton.bind(this), e.style.setProperty("display", "block");
      }, Number(t) * 1e3);
    }
  }
  showUnmuteButton() {
    const e = document.getElementById("cornerUnmuteSplitAdButton");
    e && (e.innerHTML = `<svg width="24" height="24" viewBox="0 0 24 24" fill="white">
                <path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/>
            </svg>`, e.onclick = this.toggleMute.bind(this));
  }
  toggleMute() {
    const e = document.getElementById("cornerUnmuteSplitAdButton"), t = document.getElementById("ad-player");
    !t || !e || (t.muted ? (t.muted = !1, e.innerHTML = `<svg width="24" height="24" viewBox="0 0 24 24" fill="white">
                    <path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/>
                </svg>`) : (t.muted = !0, e.innerHTML = `<svg width="24" height="24" viewBox="0 0 24 24" fill="white">
                    <path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/>
                </svg>`));
  }
  handleOnCloseButton() {
    const e = document.getElementById("streann-splitad"), t = document.getElementById("ad-player");
    t && (t.pause(), t.currentTime = 0), e && e.remove();
    const n = document.getElementById("vjsplayer");
    n && (n.style.width = "100%", n.style.float = "none");
  }
  removeAd() {
    var n, s;
    this.insideAdActive = !1, (n = document.getElementById("split-ad-container")) == null || n.remove(), (s = document.getElementById("streann-splitad")) == null || s.remove();
    const e = document.getElementById("vjsplayer");
    e && (e.style.width = "100%", e.style.float = "none");
    const t = document.querySelector("body");
    t && (t.classList.remove("flex-row-reverse"), t.classList.add("flex-column"));
  }
  cleanupExistingAdContainer() {
    const e = document.getElementById("split-ad-container");
    e && e.remove();
    const t = document.getElementById("streann-splitad");
    t && t.remove();
  }
}
const Le = 1e4, qt = 2e4, jt = 1e4, Gt = {
  CANVAS: {
    hostId: "streann-multiview-canvas-host",
    rootId: "streann-multiview-canvas",
    containerId: "multiview-canvas-ad-container",
    playerId: "multiview-canvas-ad-player",
    closeButtonId: "multiviewCanvasCloseButton",
    unmuteButtonId: "multiviewCanvasUnmuteButton",
    rootClass: "multiview-ad multiview-canvas-ad",
    imaSlot: "MULTIVIEW_CANVAS"
  },
  RIGHT_BAR: {
    hostId: "streann-multiview-right-bar-host",
    rootId: "streann-multiview-right-bar",
    containerId: "multiview-right-bar-ad-container",
    playerId: "multiview-right-bar-ad-player",
    closeButtonId: "multiviewRightBarCloseButton",
    unmuteButtonId: "multiviewRightBarUnmuteButton",
    rootClass: "multiview-ad multiview-right-bar-ad",
    imaSlot: "MULTIVIEW_RIGHT_BAR"
  }
}, Re = `<svg width="24" height="24" viewBox="0 0 24 24" fill="white">
        <path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/>
    </svg>`, Kt = `<svg width="24" height="24" viewBox="0 0 24 24" fill="white">
        <path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/>
    </svg>`;
class Ne {
  constructor(e, t, n, s, o) {
    // Tagged "multiview:CANVAS" / "multiview:RIGHT_BAR" so the two placements are
    // told apart in the console. Silence with `window.insideAd.debug = false`.
    d(this, "log");
    d(this, "placement");
    d(this, "ad");
    d(this, "insideAdCallback");
    d(this, "currentAd");
    d(this, "variant");
    d(this, "config");
    d(this, "insideAdActive", !1);
    // The IMA session running this placement's VAST ad.
    d(this, "vastSession");
    // Called when the viewer unmutes this ad, so the other placement's ad can be
    // muted - browsers do not let two videos play with sound at once.
    d(this, "onUnmute");
    d(this, "muted", !0);
    d(this, "startTimeout");
    d(this, "closeButtonTimeout");
    d(this, "hostObserver");
    d(this, "hostObserverTimeout");
    // Armed while an ad has been requested but has not started rendering yet.
    d(this, "renderTimeout");
    d(this, "boundRemoveAd", this.removeAd.bind(this));
    d(this, "boundOnAdFinish", this.onAdFinish.bind(this));
    d(this, "boundOnRenderStart", this.onRenderStart.bind(this));
    var a, c, u;
    this.onUnmute = o, this.placement = e, this.ad = t, this.insideAdCallback = n, this.variant = s, this.config = Gt[s], this.log = l.scope(`multiview:${s}`), this.log.info("created", {
      adType: t.adType,
      adName: t.name,
      url: t.url,
      startAfterSeconds: (a = e.properties) == null ? void 0 : a.startAfterSeconds,
      showCloseButtonAfterSeconds: (c = e.properties) == null ? void 0 : c.showCloseButtonAfterSeconds,
      hostOnly: g.multiviewHostOnly
    });
    const r = (u = e.properties) == null ? void 0 : u.startAfterSeconds;
    r != null ? (this.log.info(`start delayed by ${r}s`), this.startTimeout = setTimeout(() => {
      this.startAd(t);
    }, Number(r) * 1e3)) : this.startAd(t), window.addEventListener("popstate", this.boundRemoveAd), window.addEventListener("hashchange", this.boundRemoveAd);
  }
  startAd(e) {
    var n, s, o;
    if (this.insideAdActive) {
      this.log.warn("startAd ignored - an ad is already active");
      return;
    }
    if (e.adType !== "VAST" && e.adType !== "LOCAL_VIDEO") {
      this.log.warn("ad type not supported", e.adType), this.insideAdCallback.insideAdStop();
      return;
    }
    if (e.adType === "VAST" && !Vt(this.config.imaSlot)) {
      this.skipBecauseVastSessionBusy();
      return;
    }
    this.cleanupExistingAdContainer();
    const t = this.getHostElement();
    if (!t) {
      this.log.info("no host element yet - watching the DOM for one"), this.waitForHostElement(e);
      return;
    }
    if (this.log.info("host element resolved", this.describeHost(t)), this.insideAdActive = !0, this.currentAd = e, this.createAdView(t), e.adType === "LOCAL_VIDEO")
      this.log.info("starting LOCAL_VIDEO ad", e.url), this.initLocalVideoAd_(e);
    else {
      const r = ((o = (s = (n = this.placement.properties) == null ? void 0 : n.webSettings) == null ? void 0 : s.screens) == null ? void 0 : o[0]) || window.location.pathname;
      this.log.info("starting VAST ad", { screen: r, tag: e.url });
      const a = Ut(
        this.insideAdCallback,
        e.url,
        this.boundOnAdFinish,
        this.config.containerId,
        e,
        r,
        this.boundOnRenderStart
      );
      this.vastSession = a ?? void 0, a === null ? (this.log.warn(
        "VAST slot was claimed between the check and the request"
      ), this.insideAdActive = !1, this.currentAd = void 0, this.cleanupExistingAdContainer(), this.skipBecauseVastSessionBusy()) : (this.log.info("claimed VAST session", a.id), this.waitForRenderStart(qt));
    }
  }
  /**
   * Where this ad mounts, most specific first:
   *
   *   1. the element the placement points at (`elemId` / `parentXpath` /
   *      `advancedScript`);
   *   2. the variant's well-known host id, if the page renders one - this is how
   *      a multiview page gets the ad inside a grid tile or its sidebar slot
   *      without the campaign being configured for that page's markup;
   *   3. for the canvas only, a full viewport overlay - unless the page asked
   *      for host-only multiview ads (`multiviewHostOnly`), in which case there
   *      is no step 3 and the ad waits for its host.
   *
   * The right bar never has a step 3: it is a box in the page's own layout, and
   * a fixed full-screen overlay is never a sensible stand-in for it. With no
   * host the ad waits (see waitForHostElement) and then gives up.
   */
  getHostElement() {
    const e = ye(this.placement);
    if (e)
      return e;
    const t = document.getElementById(this.config.hostId);
    return t || (this.variant === "CANVAS" && !g.multiviewHostOnly ? document.body : null);
  }
  /** How a resolved host is reported in the logs. */
  describeHost(e) {
    return {
      source: ye(this.placement) === e ? "placement webSettings" : e.id === this.config.hostId ? `page host #${this.config.hostId}` : "document.body (full viewport)",
      tag: e.tagName.toLowerCase(),
      id: e.id || void 0,
      size: `${e.clientWidth}x${e.clientHeight}`
    };
  }
  /**
   * Watches the DOM for the placement's host element, for SPA sites that render
   * it after the SDK has loaded. Gives up after HOST_WAIT_MS.
   */
  waitForHostElement(e) {
    if (this.hostObserver || !document.body) {
      this.log.warn("cannot watch for a host element", {
        alreadyWatching: !!this.hostObserver,
        hasBody: !!document.body
      });
      return;
    }
    this.hostObserver = new MutationObserver(() => {
      this.getHostElement() && (this.log.info("host element appeared - retrying"), this.stopWaitingForHostElement(), this.startAd(e));
    }), this.hostObserver.observe(document.body, { childList: !0, subtree: !0 }), this.hostObserverTimeout = setTimeout(() => {
      this.log.warn(
        `no host element after ${Le}ms - giving up on this placement`,
        this.variant === "CANVAS" ? `expected #${this.config.hostId} (multiviewHostOnly is on)` : `expected #${this.config.hostId} or a webSettings target`
      ), this.stopWaitingForHostElement(), this.insideAdCallback.insideAdStop();
    }, Le);
  }
  stopWaitingForHostElement() {
    var e;
    (e = this.hostObserver) == null || e.disconnect(), this.hostObserver = void 0, clearTimeout(this.hostObserverTimeout), this.hostObserverTimeout = void 0;
  }
  createAdView(e) {
    var c, u, f, h;
    const t = this.variant === "CANVAS" && e === document.body;
    !t && getComputedStyle(e).position === "static" && (e.style.position = "relative");
    const n = document.createElement("div");
    n.id = this.config.rootId, n.className = this.config.rootClass, t && n.classList.add("multiview-ad-fullscreen");
    const s = document.createElement("div");
    if (s.id = this.config.containerId, s.className = "multiview-ad-content", n.appendChild(s), ((c = this.currentAd) == null ? void 0 : c.adType) === "LOCAL_VIDEO") {
      const p = document.createElement("video");
      p.id = this.config.playerId, p.className = "multiview-ad-player", s.appendChild(p);
    }
    const o = document.createElement("button");
    o.id = this.config.unmuteButtonId, o.className = "multiview-ad-unmute-btn", o.innerHTML = Re, o.onclick = this.toggleMute.bind(this), n.appendChild(o);
    const r = document.createElement("button");
    r.id = this.config.closeButtonId, r.className = "multiview-ad-close-btn", r.textContent = "Skip Ad", r.style.display = "none", n.appendChild(r);
    const a = (f = (u = this.placement.properties) == null ? void 0 : u.webSettings) == null ? void 0 : f.styles;
    a && n.setAttribute("style", `${n.getAttribute("style") || ""};${a}`), e.appendChild(n), this.log.info("view mounted", {
      rootId: this.config.rootId,
      fullViewport: t,
      hasPlayerElement: ((h = this.currentAd) == null ? void 0 : h.adType) === "LOCAL_VIDEO",
      size: `${n.clientWidth}x${n.clientHeight}`,
      customStyles: a || void 0
    }), this.showCloseButton();
  }
  /**
   * Hide the view until the ad renders and start the clock on it, for both ad
   * types: the root is painted black to letterbox the ad, so showing it before
   * there is a picture leaves an empty black box on the page - and an ad that
   * never renders would leave it there for good.
   *
   * Hidden with `visibility` rather than `display` because IMA sizes the ad
   * from the container's box (adsManager.init reads clientWidth/clientHeight),
   * and a display:none container measures 0x0.
   */
  waitForRenderStart(e) {
    const t = document.getElementById(this.config.rootId);
    t && (t.style.visibility = "hidden"), this.log.info(`view hidden, waiting up to ${e}ms for the ad to render`), this.renderTimeout = setTimeout(() => {
      this.renderTimeout = void 0, this.failAd(
        this.adError(`ad never started rendering within ${e}ms`)
      );
    }, e);
  }
  /**
   * This placement's IMA slot still has an ad running, so it sits this refresh
   * cycle out and plays on the next one. Nothing of ours is on the page.
   *
   * The terminal state still arms the refresh as a safety net; the running ad
   * ends later and re-arms it from its own end, so the skip does not move the
   * next cycle earlier.
   */
  skipBecauseVastSessionBusy() {
    this.log.warn(
      "a VAST ad is still running in this slot - skipping until the next refresh"
    ), this.insideAdCallback.insideAdStop();
  }
  /**
   * The ad has started rendering - IMA's STARTED for VAST, the video element's
   * `play` for a local video. Reveal the view and stop waiting for it.
   */
  onRenderStart() {
    if (this.renderTimeout === void 0)
      return;
    this.log.info("ad started rendering - revealing the view"), clearTimeout(this.renderTimeout), this.renderTimeout = void 0;
    const e = document.getElementById(this.config.rootId);
    e && e.style.removeProperty("visibility");
  }
  initLocalVideoAd_(e) {
    var n;
    const t = document.getElementById(this.config.playerId);
    if (!t) {
      this.log.error(`ad player #${this.config.playerId} not found`), this.onAdFinish();
      return;
    }
    this.waitForRenderStart(jt), t.style.display = "none", t.addEventListener("play", () => {
      t.style.display = "block", this.onRenderStart(), this.insideAdCallback.insideAdPlay();
    }), t.addEventListener("error", () => {
      var s, o;
      this.failAd(
        this.adError(
          `local video failed to load (${e.url}): ${((s = t.error) == null ? void 0 : s.message) || "unknown media error"}`,
          (o = t.error) == null ? void 0 : o.code
        )
      );
    }), t.src = e.url, t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.play().catch((s) => {
      this.log.warn("muted autoplay refused - waiting on the render timeout", s);
    }), (n = e.properties) != null && n.clickThroughUrl && (t.style.cursor = "pointer", t.addEventListener("click", () => {
      window.open(e.properties.clickThroughUrl, "_blank"), this.insideAdCallback.insideAdClicked();
    })), t.addEventListener("ended", () => {
      this.log.info("local video ended"), this.removeAd(), this.insideAdCallback.insideAdStop();
    });
  }
  showCloseButton() {
    var n;
    const e = (n = this.placement.properties) == null ? void 0 : n.showCloseButtonAfterSeconds;
    if (e == null)
      return;
    const t = document.getElementById(this.config.closeButtonId);
    if (!t) {
      this.log.warn(`close button #${this.config.closeButtonId} not found`);
      return;
    }
    this.closeButtonTimeout = setTimeout(() => {
      this.log.info("close button shown"), t.onclick = this.handleOnCloseButton.bind(this), t.style.setProperty("display", "block");
    }, Number(e) * 1e3);
  }
  toggleMute() {
    var t, n, s, o;
    const e = document.getElementById(this.config.unmuteButtonId);
    if (!e) {
      this.log.warn(`unmute button #${this.config.unmuteButtonId} not found`);
      return;
    }
    if (this.muted = !this.muted, this.log.info(this.muted ? "muted" : "unmuted", {
      adType: (t = this.currentAd) == null ? void 0 : t.adType
    }), ((n = this.currentAd) == null ? void 0 : n.adType) === "LOCAL_VIDEO") {
      const r = document.getElementById(this.config.playerId);
      if (!r)
        return;
      r.muted = this.muted;
    } else
      (s = this.vastSession) == null || s.setVolume(this.muted ? 0 : 1);
    this.muted || (o = this.onUnmute) == null || o.call(this), e.innerHTML = this.muted ? Re : Kt, this.insideAdCallback.insideAdVolumeChanged(this.muted ? 0 : 1);
  }
  /**
   * Silence this ad from outside, keeping its unmute button in step.
   *
   * The host page needs this when it hands audio to something else - a
   * multiview page unmuting one of its own players, say - because for a VAST ad
   * the audio belongs to IMA and the page cannot reach it. No-op when the ad is
   * already muted or nothing is running.
   */
  muteAd() {
    this.muted || !this.insideAdActive || (this.log.info("muted by the host page"), this.toggleMute());
  }
  handleOnCloseButton() {
    this.log.info("skipped by the viewer"), this.removeAd(), this.insideAdCallback.insideAdSkipped();
  }
  /**
   * Terminal state for this placement, whether IMA finished, errored or we tore
   * the view down ourselves. Mirrors AD_VIEW_DISAPPEARED in the native SDKs:
   * the view goes away and the next ad is scheduled. removeAd stays free of the
   * callback so navigation teardown does not schedule a refresh of its own.
   */
  onAdFinish() {
    this.log.info("ad finished"), this.removeAd(), this.insideAdCallback.insideAdStop();
  }
  /**
   * onAdFinish's counterpart for a failure: the view goes away exactly the
   * same, but the terminal state carries the reason, so it reaches analytics
   * and the host page instead of looking like a normal completion.
   *
   * VAST errors do not come through here - IMA reports those itself.
   */
  failAd(e) {
    this.removeAd(), this.insideAdCallback.insideAdError(e);
  }
  adError(e, t) {
    var n, s, o, r, a;
    return {
      message: e,
      code: t,
      placement: this.placement.viewType,
      adType: (n = this.currentAd) == null ? void 0 : n.adType,
      adName: (s = this.currentAd) == null ? void 0 : s.name,
      screen: ((a = (r = (o = this.placement.properties) == null ? void 0 : o.webSettings) == null ? void 0 : r.screens) == null ? void 0 : a[0]) || window.location.pathname
    };
  }
  removeAd() {
    var n, s, o, r;
    const e = this.insideAdActive;
    this.insideAdActive = !1, clearTimeout(this.startTimeout), clearTimeout(this.closeButtonTimeout), clearTimeout(this.renderTimeout), this.renderTimeout = void 0, this.stopWaitingForHostElement(), window.removeEventListener("popstate", this.boundRemoveAd), window.removeEventListener("hashchange", this.boundRemoveAd);
    const t = document.getElementById(this.config.playerId);
    t && (t.pause(), t.currentTime = 0), this.cleanupExistingAdContainer(), e && ((n = this.currentAd) == null ? void 0 : n.adType) === "VAST" && ((s = this.vastSession) != null && s.isLive()) ? (this.log.info("VAST session still live - destroying IMA", this.vastSession.id), this.vastSession.destroy()) : e && this.log.info("view removed", {
      adType: (o = this.currentAd) == null ? void 0 : o.adType,
      vastSessionId: (r = this.vastSession) == null ? void 0 : r.id,
      vastSessionLive: !1
    }), this.vastSession = void 0;
  }
  cleanupExistingAdContainer() {
    var e, t;
    (e = document.getElementById(this.config.containerId)) == null || e.remove(), (t = document.getElementById(this.config.rootId)) == null || t.remove();
  }
}
const le = {
  version: "3.8.0",
  target: "production",
  commit: "6b4d5b7",
  branch: "development",
  builtAt: "2026-11-06T08:06:00.482Z"
};
function Xt() {
  const { version: i, target: e, builtAt: t } = le, n = new Date(t), s = isNaN(n.getTime()) ? t : `${n.toISOString().slice(0, 16).replace("T", " ")} UTC`;
  return `v${i} · ${e} · built ${s}`;
}
window.insideAd = {
  initialize: Jt,
  muteAds: Qt,
  debug: !0,
  version: le.version,
  build: le
};
function Qt() {
  l.info("muteAds() called by the host page"), A == null || A.muteAd(), v == null || v.muteAd();
}
function Jt(i) {
  g.isAlreadyInit || !i.apiKey && !i.apiToken && !i.baseUrl || (g.apiKey = i.apiKey, g.apiToken = i.apiToken, g.baseUrl = i.baseUrl, g.multiviewHostOnly = i.multiviewHostOnly === !0, g.onAdError = i.onAdError, g.isAlreadyInit = !0, l.info(`Inside Ad SDK ${Xt()}`), l.debug("Debug logs ON (disable with ?debug=false)", {
    baseUrl: i.baseUrl,
    apiKey: i.apiKey,
    url: window.location.href,
    viewport: `${document.documentElement.clientWidth}x${document.documentElement.clientHeight}`,
    innerWidth: window.innerWidth,
    userAgent: navigator.userAgent
  }), i.apiKey && $.initialize(i.apiKey), ke(), me());
}
let ce, A, v, w;
async function me() {
  var c;
  const i = await Je();
  l.debug(`main(): ${i.length} campaign(s) received`, i);
  const { campaign: e, filteredPlacements: t } = ot(i);
  if (!e || t.length === 0) {
    l.warn("no campaign or no placements passed the filters - nothing to show", {
      campaign: e == null ? void 0 : e.name,
      path: window.location.pathname,
      innerWidth: window.innerWidth
    });
    return;
  }
  l.info(`campaign "${e.name}" selected`, {
    intervalInMinutes: (c = e.properties) == null ? void 0 : c.intervalInMinutes,
    placements: t.map((u) => {
      var f, h;
      return `${u.name} [${u.viewType}] -> ${(f = u.ad) == null ? void 0 : f.adType} "${(h = u.ad) == null ? void 0 : h.name}"`;
    })
  }), w == null || w.dispose(), w = new ut(e, me), (A || v) && l.info("disposing the previous refresh cycle's multiview ads"), A == null || A.removeAd(), A = void 0, v == null || v.removeAd(), v = void 0;
  const n = t.find(
    (u) => u.viewType == L.CORNER
  );
  n || l.debug("main(): NO CORNER placement matches this page/screen"), n && (ce = new de(
    n,
    n.ad,
    w
  ));
  const s = t.find(
    (u) => u.viewType == L.SPLIT_AD
  );
  s && new Yt(
    s,
    s.ad,
    w
  );
  const o = t.find(
    (u) => u.viewType == L.MULTIVIEW_CANVAS
  );
  o && (l.info("MULTIVIEW_CANVAS placement found"), A = new Ne(
    o,
    o.ad,
    w,
    "CANVAS",
    () => v == null ? void 0 : v.muteAd()
  ));
  const r = t.find(
    (u) => u.viewType == L.MULTIVIEW_RIGHT_BAR
  );
  r && (l.info("MULTIVIEW_RIGHT_BAR placement found"), v = new Ne(
    r,
    r.ad,
    w,
    "RIGHT_BAR",
    () => A == null ? void 0 : A.muteAd()
  ));
  const a = t.find(
    (u) => u.viewType == L.ADHESION
  );
  a && We.setAd(a, a.ad), t.filter((u) => u.viewType == L.EMBED).forEach((u) => new zt(u, u.ad));
}
let Oe = window.location.pathname;
function Zt() {
  Oe != window.location.pathname && (l.info("path changed - clearing ads and refreshing", {
    from: Oe,
    to: window.location.pathname
  }), C.clearAllSlots(), ce && ce.handleOnCloseButton(), A && A.removeAd(), v && v.removeAd(), We.onAdFinish(), me());
}
window.addEventListener("locationchange", function() {
  Zt();
});
(() => {
  let i = history.pushState;
  history.pushState = function() {
    let n = i.apply(this, arguments);
    return window.dispatchEvent(new Event("pushstate")), window.dispatchEvent(new Event("locationchange")), n;
  };
  let e = history.replaceState;
  history.replaceState = function() {
    let n = e.apply(this, arguments);
    return window.dispatchEvent(new Event("replacestate")), window.dispatchEvent(new Event("locationchange")), n;
  }, window.addEventListener("popstate", () => {
    window.dispatchEvent(new Event("locationchange"));
  });
})();
