import { v as e, l as i, m as a, x as o, d as n } from "./useVidstackSrc-CNo2sIR4.js";
import { f as c } from "./wt-vidstack-player-DL-84dHQ.js";
class g {
  #t;
  src = e("");
  /**
   * Defines which referrer is sent when fetching the resource.
   *
   * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/referrerPolicy}
   */
  referrerPolicy = null;
  get iframe() {
    return this.#t;
  }
  constructor(t) {
    this.#t = t, t.setAttribute("frameBorder", "0"), t.setAttribute("aria-hidden", "true"), t.setAttribute(
      "allow",
      "autoplay; fullscreen; encrypted-media; picture-in-picture; accelerometer; gyroscope"
    ), this.referrerPolicy !== null && t.setAttribute("referrerpolicy", this.referrerPolicy);
  }
  setup() {
    i(window, "message", this.#r.bind(this)), i(this.#t, "load", this.onLoad.bind(this)), a(this.#s.bind(this));
  }
  #s() {
    const t = this.src();
    if (!t.length) {
      this.#t.setAttribute("src", "");
      return;
    }
    const s = o(() => this.buildParams());
    this.#t.setAttribute("src", c(t, s));
  }
  postMessage(t, s) {
    this.#t.contentWindow?.postMessage(JSON.stringify(t), s ?? "*");
  }
  #r(t) {
    const s = this.getOrigin();
    if ((t.source === null || t.source === this.#t?.contentWindow) && (!n(s) || s === t.origin)) {
      try {
        const r = JSON.parse(t.data);
        r && this.onMessage(r, t);
        return;
      } catch {
      }
      t.data && this.onMessage(t.data, t);
    }
  }
}
export {
  g as E
};
