import { A as e, F as t, G as n, Q as r, V as i, W as a, X as o, h as s, i as c, r as l, v as u } from "./vidstack-D9mvYVIz-DesuYgKV.js";
import { b as d, i as f, o as p, v as m } from "./useVidstackSrc-epUQZhkL.js";
import { n as h, t as g } from "./vidstack-ijoHbXQB-DBClSWHE.js";
import { n as _ } from "./vidstack-CZQo98ic-D3uTuzB9.js";
//#region node_modules/vidstack/prod/chunks/vidstack-BFrlqsuF.js
var v = null, y = [], b = [];
function x() {
	return v ??= new AudioContext();
}
function S() {
	let e = x(), t = e.createGain();
	return t.connect(e.destination), y.push(t), t;
}
function C(e, t) {
	let n = x().createMediaElementSource(e);
	return t && n.connect(t), b.push(n), n;
}
function w(e) {
	let t = y.indexOf(e);
	t !== -1 && (y.splice(t, 1), e.disconnect(), E());
}
function T(e) {
	let t = b.indexOf(e);
	t !== -1 && (b.splice(t, 1), e.disconnect(), E());
}
function E() {
	v && y.length === 0 && b.length === 0 && v.close().then(() => {
		v = null;
	});
}
var D = class {
	#e;
	#t;
	#n = null;
	#r = null;
	get currentGain() {
		return this.#n?.gain?.value ?? null;
	}
	get supported() {
		return !0;
	}
	constructor(e, t) {
		this.#e = e, this.#t = t;
	}
	setGain(e) {
		let t = this.currentGain;
		if (e !== this.currentGain) {
			if (e === 1 && t !== 1) {
				this.removeGain();
				return;
			}
			this.#n || (this.#n = S(), this.#r && this.#r.connect(this.#n)), this.#r ||= C(this.#e, this.#n), this.#n.gain.value = e, this.#t(e);
		}
	}
	removeGain() {
		this.#n && (this.#r && this.#r.connect(x().destination), this.#a(), this.#t(null));
	}
	destroy() {
		this.#i(), this.#a();
	}
	#i() {
		if (this.#r) try {
			T(this.#r);
		} catch {} finally {
			this.#r = null;
		}
	}
	#a() {
		if (this.#n) try {
			w(this.#n);
		} catch {} finally {
			this.#n = null;
		}
	}
}, O = [
	"focus",
	"blur",
	"visibilitychange",
	"pageshow",
	"pagehide"
], k = class {
	#e = r(A());
	#t = r(document.visibilityState);
	#n;
	connect() {
		let e = new c(window), t = this.#r.bind(this);
		for (let n of O) e.add(n, t);
		p && e.add("beforeunload", (e) => {
			this.#n = setTimeout(() => {
				e.defaultPrevented || e.returnValue.length > 0 || (this.#e.set("hidden"), this.#t.set("hidden"));
			}, 0);
		});
	}
	get pageState() {
		return this.#e();
	}
	get visibility() {
		return this.#t();
	}
	#r(e) {
		p && window.clearTimeout(this.#n), (e.type !== "blur" || this.#e() === "active") && (this.#e.set(A(e)), this.#t.set(document.visibilityState == "hidden" ? "hidden" : "visible"));
	}
};
function A(e) {
	return e?.type === "blur" || document.visibilityState === "hidden" ? "hidden" : document.hasFocus() ? "active" : "passive";
}
var j = class {
	#e;
	#t;
	#n = !1;
	#r = !1;
	#i = !1;
	#a = new h(this.#f.bind(this));
	#o = new k();
	#s;
	get #c() {
		return this.#e.media;
	}
	constructor(e, t) {
		this.#e = e, this.#t = t, this.#s = new c(e.media), this.#p(), this.#o.connect(), u(this.#N.bind(this)), a(this.#l.bind(this));
	}
	#l() {
		this.#r = !1, this.#i = !1, this.#a.stop(), this.#s.abort(), this.#g?.clear();
	}
	#u = 0;
	#d = -1;
	#f() {
		let e = this.#c.currentTime;
		!(p && e - this.#d < .35) && this.#u !== e && (this.#v(e), this.#u = e);
	}
	#p() {
		this.#_("loadstart", this.#y), this.#_("abort", this.#b), this.#_("emptied", this.#x), this.#_("error", this.#H), this.#_("volumechange", this.#I);
	}
	#m() {
		this.#r ||= (this.#_("loadeddata", this.#S), this.#_("loadedmetadata", this.#C), this.#_("canplay", this.#D), this.#_("canplaythrough", this.#O), this.#_("durationchange", this.#F), this.#_("play", this.#T), this.#_("progress", this.#z), this.#_("stalled", this.#A), this.#_("suspend", this.#B), this.#_("ratechange", this.#V), !0);
	}
	#h() {
		this.#i ||= (this.#_("pause", this.#E), this.#_("playing", this.#k), this.#_("seeked", this.#L), this.#_("seeking", this.#R), this.#_("ended", this.#M), this.#_("waiting", this.#j), !0);
	}
	#g = void 0;
	#_(e, t) {
		this.#s.add(e, t.bind(this));
	}
	#v(e, t) {
		let n = Math.min(e, this.#t.$state.seekableEnd());
		this.#t.notify("time-change", n, t);
	}
	#y(e) {
		if (this.#c.networkState === 3) {
			this.#b(e);
			return;
		}
		this.#m(), this.#t.notify("load-start", void 0, e);
	}
	#b(e) {
		this.#t.notify("abort", void 0, e);
	}
	#x(e) {
		this.#t.notify("emptied", void 0, e);
	}
	#S(e) {
		this.#t.notify("loaded-data", void 0, e);
	}
	#C(e) {
		this.#u = 0, this.#d = -1, this.#h(), this.#t.notify("loaded-metadata", void 0, e), (f || p && m(this.#t.$state.source())) && this.#t.delegate.ready(this.#w(), e);
	}
	#w() {
		return {
			provider: n(this.#t.$provider),
			duration: this.#c.duration,
			buffered: this.#c.buffered,
			seekable: this.#c.seekable
		};
	}
	#T(e) {
		this.#t.$state.canPlay() && this.#t.notify("play", void 0, e);
	}
	#E(e) {
		this.#c.readyState === 1 && !this.#n || (this.#n = !1, this.#a.stop(), this.#t.notify("pause", void 0, e));
	}
	#D(e) {
		this.#t.delegate.ready(this.#w(), e);
	}
	#O(e) {
		this.#t.$state.started() || this.#t.notify("can-play-through", this.#w(), e);
	}
	#k(e) {
		this.#c.paused || (this.#n = !1, this.#t.notify("playing", void 0, e), this.#a.start());
	}
	#A(e) {
		this.#t.notify("stalled", void 0, e), this.#c.readyState < 3 && (this.#n = !0, this.#t.notify("waiting", void 0, e));
	}
	#j(e) {
		this.#c.readyState < 3 && (this.#n = !0, this.#t.notify("waiting", void 0, e));
	}
	#M(t) {
		this.#a.stop(), this.#v(this.#c.duration, t), this.#t.notify("end", void 0, t), this.#t.$state.loop() && e(this.#c.controls) && (this.#c.controls = !1);
	}
	#N() {
		let e = this.#t.$state.paused(), t = this.#o.visibility === "hidden";
		(e || t) && i(this.#c, "timeupdate", this.#P.bind(this));
	}
	#P(e) {
		this.#v(this.#c.currentTime, e);
	}
	#F(e) {
		this.#t.$state.ended() && this.#v(this.#c.duration, e), this.#t.notify("duration-change", this.#c.duration, e);
	}
	#I(e) {
		let t = {
			volume: this.#c.volume,
			muted: this.#c.muted
		};
		this.#t.notify("volume-change", t, e);
	}
	#L(e) {
		this.#d = this.#c.currentTime, this.#v(this.#c.currentTime, e), this.#t.notify("seeked", this.#c.currentTime, e), Math.trunc(this.#c.currentTime) === Math.trunc(this.#c.duration) && _(this.#c.duration) > _(this.#c.currentTime) && (this.#v(this.#c.duration, e), this.#c.ended || this.#t.player.dispatch(new l("media-play-request", { trigger: e })));
	}
	#R(e) {
		this.#t.notify("seeking", this.#c.currentTime, e);
	}
	#z(e) {
		let t = {
			buffered: this.#c.buffered,
			seekable: this.#c.seekable
		};
		this.#t.notify("progress", t, e);
	}
	#B(e) {
		this.#t.notify("suspend", void 0, e);
	}
	#V(e) {
		this.#t.notify("rate-change", this.#c.playbackRate, e);
	}
	#H(e) {
		let t = this.#c.error;
		if (!t) return;
		let n = {
			message: t.message,
			code: t.code,
			mediaError: t
		};
		this.#t.notify("error", n, e);
	}
}, M = class {
	#e;
	#t;
	get #n() {
		return this.#e.media.audioTracks;
	}
	constructor(e, t) {
		this.#e = e, this.#t = t, this.#n.onaddtrack = this.#r.bind(this), this.#n.onremovetrack = this.#i.bind(this), this.#n.onchange = this.#a.bind(this), i(this.#t.audioTracks, "change", this.#s.bind(this));
	}
	#r(e) {
		let t = e.track;
		if (t.label === "") return;
		let n = {
			id: t.id.toString() || `native-audio-${this.#t.audioTracks.length}`,
			label: t.label,
			language: t.language,
			kind: t.kind,
			selected: !1
		};
		this.#t.audioTracks[g.add](n, e), t.enabled && (n.selected = !0);
	}
	#i(e) {
		let t = this.#t.audioTracks.getById(e.track.id);
		t && this.#t.audioTracks[g.remove](t, e);
	}
	#a(e) {
		let t = this.#o();
		if (!t) return;
		let n = this.#t.audioTracks.getById(t.id);
		n && this.#t.audioTracks[g.select](n, !0, e);
	}
	#o() {
		return Array.from(this.#n).find((e) => e.enabled);
	}
	#s(e) {
		let { current: t } = e.detail;
		if (!t) return;
		let n = this.#n.getTrackById(t.id);
		if (n) {
			let e = this.#o();
			e && (e.enabled = !1), n.enabled = !0;
		}
	}
}, N = class {
	media;
	ctx;
	scope = s();
	currentSrc = null;
	audioGain;
	constructor(e, t) {
		this.media = e, this.ctx = t, this.audioGain = new D(e, (e) => {
			this.ctx.notify("audio-gain-change", e);
		});
	}
	setup() {
		new j(this, this.ctx), "audioTracks" in this.media && new M(this, this.ctx), a(() => {
			this.audioGain.destroy(), this.media.srcObject = null, this.media.removeAttribute("src");
			for (let e of this.media.querySelectorAll("source")) e.remove();
			this.media.load();
		});
	}
	get type() {
		return "";
	}
	setPlaybackRate(e) {
		this.media.playbackRate = e;
	}
	async play() {
		return this.media.play();
	}
	async pause() {
		return this.media.pause();
	}
	setMuted(e) {
		this.media.muted = e;
	}
	setVolume(e) {
		this.media.volume = e;
	}
	setCurrentTime(e) {
		this.media.currentTime = e;
	}
	setPlaysInline(e) {
		o(this.media, "playsinline", e);
	}
	async loadSource({ src: e, type: n }, r) {
		this.media.preload = r || "", d(e) ? (this.removeSource(), this.media.srcObject = e) : (this.media.srcObject = null, t(e) ? n === "?" ? (this.removeSource(), this.media.src = this.#e(e)) : this.appendSource({
			src: e,
			type: n
		}) : (this.removeSource(), this.media.src = window.URL.createObjectURL(e))), this.media.load(), this.currentSrc = {
			src: e,
			type: n
		};
	}
	appendSource(e, t) {
		let n = this.media.querySelector("source[data-vds]"), r = n ?? document.createElement("source");
		o(r, "src", this.#e(e.src)), o(r, "type", e.type === "?" ? t : e.type), o(r, "data-vds", ""), n || this.media.append(r);
	}
	removeSource() {
		this.media.querySelector("source[data-vds]")?.remove();
	}
	#e(e) {
		let { clipStartTime: t, clipEndTime: n } = this.ctx.$state, r = t(), i = n();
		return r > 0 && i > 0 ? `${e}#t=${r},${i}` : r > 0 ? `${e}#t=${r}` : i > 0 ? `${e}#t=0,${i}` : e;
	}
}, P = class {
	#e;
	#t;
	#n;
	#r = r(!1);
	get supported() {
		return this.#r();
	}
	constructor(e, t) {
		this.#e = e, this.#t = t, this.#i();
	}
	#i() {
		!this.#e?.remote || !this.canPrompt || (this.#e.remote.watchAvailability((e) => {
			this.#r.set(e);
		}).catch(() => {
			this.#r.set(!1);
		}), u(this.#a.bind(this)));
	}
	#a() {
		if (!this.#r()) return;
		let e = [
			"connecting",
			"connect",
			"disconnect"
		], t = this.#o.bind(this);
		t(), i(this.#e, "playing", t);
		let n = new c(this.#e.remote);
		for (let r of e) n.add(r, t);
	}
	async prompt() {
		if (!this.supported) throw Error("Not supported on this platform.");
		return this.type === "airplay" && this.#e.webkitShowPlaybackTargetPicker ? this.#e.webkitShowPlaybackTargetPicker() : this.#e.remote.prompt();
	}
	#o(e) {
		let t = this.#e.remote.state;
		if (t === this.#n) return;
		let n = {
			type: this.type,
			state: t
		};
		this.#t.notify("remote-playback-change", n, e), this.#n = t;
	}
}, F = class extends P {
	type = "airplay";
	get canPrompt() {
		return "WebKitPlaybackTargetAvailabilityEvent" in window;
	}
};
//#endregion
export { N as n, F as t };
