import { s as l, an as o, ao as u, ap as p, o as h, l as P, D as f, n as g } from "./useVidstackSrc-CNo2sIR4.js";
import { H as k, a as m } from "./vidstack-Bq6c3Bam-C1Xh6KV8.js";
import { T as x, b as n } from "./wt-vidstack-player-DL-84dHQ.js";
class T {
  #t;
  #i;
  constructor(t, e) {
    this.#t = t, this.#i = e, t.textTracks.onaddtrack = this.#e.bind(this), h(this.#s.bind(this));
  }
  #e(t) {
    const e = t.track;
    if (!e || y(this.#t, e)) return;
    const i = new x({
      id: e.id,
      kind: e.kind,
      label: e.label ?? "",
      language: e.language,
      type: "vtt"
    });
    i[n.native] = { track: e }, i[n.readyState] = 2, i[n.nativeHLS] = !0;
    let a = 0;
    const c = (d) => {
      if (e.cues)
        for (let r = a; r < e.cues.length; r++)
          i.addCue(e.cues[r], d), a++;
    };
    c(t), e.oncuechange = c, this.#i.textTracks.add(i, t), i.setMode(e.mode, t);
  }
  #s() {
    this.#t.textTracks.onaddtrack = null;
    for (const t of this.#i.textTracks) {
      const e = t[n.native]?.track;
      e?.oncuechange && (e.oncuechange = null);
    }
  }
}
function y(s, t) {
  return Array.from(s.children).find((e) => e.track === t);
}
class v {
  #t;
  #i;
  constructor(t, e) {
    this.#t = t, this.#i = e, new g(t).add("enterpictureinpicture", this.#e.bind(this)).add("leavepictureinpicture", this.#s.bind(this));
  }
  get active() {
    return document.pictureInPictureElement === this.#t;
  }
  get supported() {
    return u(this.#t);
  }
  async enter() {
    return this.#t.requestPictureInPicture();
  }
  exit() {
    return document.exitPictureInPicture();
  }
  #e(t) {
    this.#n(!0, t);
  }
  #s(t) {
    this.#n(!1, t);
  }
  #n = (t, e) => {
    this.#i.notify("picture-in-picture-change", t, e);
  };
}
class M {
  #t;
  #i;
  #e = "inline";
  get mode() {
    return this.#e;
  }
  constructor(t, e) {
    this.#t = t, this.#i = e, P(t, "webkitpresentationmodechanged", this.#s.bind(this));
  }
  get supported() {
    return o(this.#t);
  }
  async setPresentationMode(t) {
    this.#e !== t && this.#t.webkitSetPresentationMode(t);
  }
  #s(t) {
    const e = this.#e;
    this.#e = this.#t.webkitPresentationMode, this.#i.player?.dispatch(
      new f("video-presentation-change", {
        detail: this.#e,
        trigger: t
      })
    ), ["fullscreen", "picture-in-picture"].forEach((i) => {
      (this.#e === i || e === i) && this.#i.notify(`${i}-change`, this.#e === i, t);
    });
  }
}
class b {
  #t;
  get active() {
    return this.#t.mode === "fullscreen";
  }
  get supported() {
    return this.#t.supported;
  }
  constructor(t) {
    this.#t = t;
  }
  async enter() {
    this.#t.setPresentationMode("fullscreen");
  }
  async exit() {
    this.#t.setPresentationMode("inline");
  }
}
class w {
  #t;
  get active() {
    return this.#t.mode === "picture-in-picture";
  }
  get supported() {
    return this.#t.supported;
  }
  constructor(t) {
    this.#t = t;
  }
  async enter() {
    this.#t.setPresentationMode("picture-in-picture");
  }
  async exit() {
    this.#t.setPresentationMode("inline");
  }
}
class A extends k {
  $$PROVIDER_TYPE = "VIDEO";
  get type() {
    return "video";
  }
  airPlay;
  fullscreen;
  pictureInPicture;
  constructor(t, e) {
    super(t, e), l(() => {
      if (this.airPlay = new m(t, e), o(t)) {
        const i = new M(t, e);
        this.fullscreen = new b(i), this.pictureInPicture = new w(i);
      } else u(t) && (this.pictureInPicture = new v(t, e));
    }, this.scope);
  }
  setup() {
    super.setup(), p(this.video) && new T(this.video, this.ctx), this.ctx.textRenderers.attachVideo(this.video), h(() => {
      this.ctx.textRenderers.attachVideo(null);
    }), this.type === "video" && this.ctx.notify("provider-setup", this);
  }
  /**
   * The native HTML `<video>` element.
   *
   * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement}
   */
  get video() {
    return this.media;
  }
}
export {
  A as VideoProvider
};
