import { C as e, F as t, G as n, Q as r, V as i, g as a, h as o, v as s } from "./vidstack-D9mvYVIz-DesuYgKV.js";
import { i as c } from "./vidstack-mvRkf9tF-CoFf7dS9.js";
import { getVimeoVideoInfo as l, resolveVimeoVideoId as u } from "./vidstack-q-9soyHT-CiZ4hFSF.js";
import { n as d, t as f } from "./vidstack-ijoHbXQB-DBClSWHE.js";
import { t as p } from "./vidstack-DYPyTdYw-BzqKxwCK.js";
import { t as m } from "./vidstack-_E7LrUjK-DaCLs8ge.js";
import { t as h } from "./vidstack-CdfyZegh-Bn47J4h6.js";
import { t as g } from "./vidstack-CceZzgm4-C37rtwSQ.js";
//#region node_modules/vidstack/prod/providers/vidstack-vimeo.js
var _ = [
	"bufferend",
	"bufferstart",
	"durationchange",
	"ended",
	"enterpictureinpicture",
	"error",
	"fullscreenchange",
	"leavepictureinpicture",
	"loaded",
	"playProgress",
	"loadProgress",
	"pause",
	"play",
	"playbackratechange",
	"qualitychange",
	"seeked",
	"seeking",
	"timeupdate",
	"volumechange",
	"waiting"
], v = class extends g {
	$$PROVIDER_TYPE = "VIMEO";
	scope = o();
	fullscreen;
	#e;
	#t = r("");
	#n = r(!1);
	#r = null;
	#i = null;
	#a = !1;
	#o = new h(0, 0);
	#s = new d(this.#h.bind(this));
	#c = null;
	#l = null;
	#u = /* @__PURE__ */ new Map();
	#d = null;
	constructor(e, t) {
		super(e), this.#e = t;
		let n = this;
		this.fullscreen = {
			get active() {
				return n.#a;
			},
			supported: !0,
			enter: () => this.#L("requestFullscreen"),
			exit: () => this.#L("exitFullscreen")
		};
	}
	cookies = !1;
	title = !0;
	byline = !0;
	portrait = !0;
	color = "00ADEF";
	get type() {
		return "vimeo";
	}
	get currentSrc() {
		return this.#i;
	}
	get videoId() {
		return this.#t();
	}
	get hash() {
		return this.#r;
	}
	get isPro() {
		return this.#n();
	}
	preconnect() {
		c(this.getOrigin());
	}
	setup() {
		super.setup(), s(this.#f.bind(this)), s(this.#p.bind(this)), s(this.#m.bind(this)), this.#e.notify("provider-setup", this);
	}
	destroy() {
		this.#R(), this.fullscreen = void 0;
		for (let e of this.#u.values()) for (let { reject: t } of e) t("provider destroyed");
		this.#u.clear(), this.#L("destroy");
	}
	async play() {
		return this.#L("play");
	}
	async pause() {
		return this.#L("pause");
	}
	setMuted(e) {
		this.#L("setMuted", e);
	}
	setCurrentTime(e) {
		this.#L("seekTo", e), this.#e.notify("seeking", e);
	}
	setVolume(e) {
		this.#L("setVolume", e), this.#L("setMuted", n(this.#e.$state.muted));
	}
	setPlaybackRate(e) {
		this.#L("setPlaybackRate", e);
	}
	async loadSource(e) {
		if (!t(e.src)) {
			this.#i = null, this.#r = null, this.#t.set("");
			return;
		}
		let { videoId: n, hash: r } = u(e.src);
		this.#t.set(n ?? ""), this.#r = r ?? null, this.#i = e;
	}
	#f() {
		this.#R();
		let e = this.#t();
		if (!e) {
			this.src.set("");
			return;
		}
		this.src.set(`${this.getOrigin()}/video/${e}`), this.#e.notify("load-start");
	}
	#p() {
		let e = this.#t();
		if (!e) return;
		let t = a(), n = new AbortController();
		return this.#d = t, l(e, n, this.#r).then((e) => {
			t.resolve(e);
		}).catch((e) => {
			t.reject();
		}), () => {
			t.reject(), n.abort();
		};
	}
	#m() {
		let e = this.#n(), { $state: t, qualities: n } = this.#e;
		if (t.canSetPlaybackRate.set(e), n[f.setReadonly](!e), e) return i(n, "change", () => {
			if (n.auto) return;
			let e = n.selected?.id;
			e && this.#L("setQuality", e);
		});
	}
	getOrigin() {
		return "https://player.vimeo.com";
	}
	buildParams() {
		let { keyDisabled: e } = this.#e.$props, { playsInline: t, nativeControls: n } = this.#e.$state, r = n();
		return {
			title: this.title,
			byline: this.byline,
			color: this.color,
			portrait: this.portrait,
			controls: r,
			h: this.hash,
			keyboard: r && !e(),
			transparent: !0,
			playsinline: t(),
			dnt: !this.cookies
		};
	}
	#h() {
		this.#L("getCurrentTime");
	}
	#g = !1;
	#_(e, t) {
		if (this.#g && e === 0) return;
		let { realCurrentTime: n, paused: r, bufferedEnd: i, seekableEnd: a, live: o } = this.#e.$state;
		if (n() === e) return;
		let s = n();
		this.#e.notify("time-change", e, t), Math.abs(s - e) > 1.5 && (this.#e.notify("seeking", e, t), !r() && i() < e && this.#e.notify("waiting", void 0, t)), !o() && a() - e < .01 && (this.#e.notify("end", void 0, t), this.#g = !0, setTimeout(() => {
			this.#g = !1;
		}, 500));
	}
	#v(e, t) {
		this.#e.notify("seeked", e, t);
	}
	#y(e) {
		let t = this.#t();
		this.#d?.promise.then((t) => {
			if (!t) return;
			let { title: n, poster: r, duration: i, pro: a } = t;
			this.#n.set(a), this.#e.notify("title-change", n, e), this.#e.notify("poster-change", r, e), this.#e.notify("duration-change", i, e), this.#b(i, e);
		}).catch(() => {
			t === this.#t() && (this.#L("getVideoTitle"), this.#L("getDuration"));
		});
	}
	#b(e, t) {
		let { nativeControls: n } = this.#e.$state, r = n();
		this.#o = new h(0, e);
		let i = {
			buffered: new h(0, 0),
			seekable: this.#o,
			duration: e
		};
		this.#e.delegate.ready(i, t), r || this.#L("_hideOverlay"), this.#L("getQualities"), this.#L("getChapters");
	}
	#x(t, r, i) {
		switch (t) {
			case "getVideoTitle":
				let t = r;
				this.#e.notify("title-change", t, i);
				break;
			case "getDuration":
				let a = r;
				this.#e.$state.canPlay() ? this.#e.notify("duration-change", a, i) : this.#b(a, i);
				break;
			case "getCurrentTime":
				this.#_(r, i);
				break;
			case "getBuffered":
				e(r) && r.length && this.#E(r[r.length - 1][1], i);
				break;
			case "setMuted":
			case "getMuted":
				this.#A(n(this.#e.$state.volume), r, i);
				break;
			case "getChapters":
				this.#j(r);
				break;
			case "getQualities":
				this.#N(r, i);
				break;
		}
		this.#z(t)?.resolve();
	}
	#S() {
		for (let e of _) this.#L("addEventListener", e);
	}
	#C(e) {
		this.#s.stop(), this.#e.notify("pause", void 0, e);
	}
	async #w(e) {
		this.#s.start(), await this.#L("getMuted"), this.#e.notify("play", void 0, e);
	}
	#T(e) {
		let { paused: t } = this.#e.$state;
		!t() && !this.#g && this.#e.notify("playing", void 0, e);
	}
	#E(e, t) {
		let n = {
			buffered: new h(0, e),
			seekable: this.#o
		};
		this.#e.notify("progress", n, t);
	}
	#D(e) {
		this.#e.notify("waiting", void 0, e);
	}
	#O(e) {
		let { paused: t } = this.#e.$state;
		t() || this.#e.notify("playing", void 0, e);
	}
	async #k(e) {
		let { paused: t } = this.#e.$state;
		t() && (await this.#L("getMuted"), this.#e.notify("play", void 0, e)), this.#e.notify("waiting", void 0, e);
	}
	#A(e, t, n) {
		let r = {
			volume: e,
			muted: t
		};
		this.#e.notify("volume-change", r, n);
	}
	#j(e) {
		if (this.#M(), !e.length) return;
		let t = new p({
			kind: "chapters",
			default: !0
		}), { seekableEnd: n } = this.#e.$state;
		for (let r = 0; r < e.length; r++) {
			let i = e[r], a = e[r + 1];
			t.addCue(new window.VTTCue(i.startTime, a?.startTime ?? n(), i.title));
		}
		this.#l = t, this.#e.textTracks.add(t);
	}
	#M() {
		this.#l &&= (this.#e.textTracks.remove(this.#l), null);
	}
	#N(e, t) {
		this.#e.qualities[m.enableAuto] = e.some((e) => e.id === "auto") ? () => this.#L("setQuality", "auto") : void 0;
		for (let n of e) {
			if (n.id === "auto") continue;
			let e = +n.id.slice(0, -1);
			isNaN(e) || this.#e.qualities[f.add]({
				id: n.id,
				width: 16 / 9 * e,
				height: e,
				codec: "avc1,h.264",
				bitrate: -1
			}, t);
		}
		this.#P(e.find((e) => e.active), t);
	}
	#P({ id: e } = {}, t) {
		if (!e) return;
		let n = e === "auto", r = this.#e.qualities.getById(e);
		n ? (this.#e.qualities[m.setAuto](n, t), this.#e.qualities[f.select](void 0, !0, t)) : this.#e.qualities[f.select](r ?? void 0, !0, t);
	}
	#F(e, t, r) {
		switch (e) {
			case "ready":
				this.#S();
				break;
			case "loaded":
				this.#y(r);
				break;
			case "play":
				this.#w(r);
				break;
			case "playProgress":
				this.#T(r);
				break;
			case "pause":
				this.#C(r);
				break;
			case "loadProgress":
				this.#E(t.seconds, r);
				break;
			case "waiting":
				this.#k(r);
				break;
			case "bufferstart":
				this.#D(r);
				break;
			case "bufferend":
				this.#O(r);
				break;
			case "volumechange":
				this.#A(t.volume, n(this.#e.$state.muted), r);
				break;
			case "durationchange":
				this.#o = new h(0, t.duration), this.#e.notify("duration-change", t.duration, r);
				break;
			case "playbackratechange":
				this.#e.notify("rate-change", t.playbackRate, r);
				break;
			case "qualitychange":
				this.#P(t, r);
				break;
			case "fullscreenchange":
				this.#a = t.fullscreen, this.#e.notify("fullscreen-change", t.fullscreen, r);
				break;
			case "enterpictureinpicture":
				this.#e.notify("picture-in-picture-change", !0, r);
				break;
			case "leavepictureinpicture":
				this.#e.notify("picture-in-picture-change", !1, r);
				break;
			case "ended":
				this.#e.notify("end", void 0, r);
				break;
			case "error":
				this.#I(t, r);
				break;
			case "seek":
			case "seeked":
				this.#v(t.seconds, r);
				break;
		}
	}
	#I(e, t) {
		let { message: n, method: r } = e;
		r === "setPlaybackRate" && this.#n.set(!1), r && this.#z(r)?.reject(n);
	}
	onMessage(e, t) {
		e.event ? this.#F(e.event, e.data, t) : e.method && this.#x(e.method, e.value, t);
	}
	onLoad() {}
	async #L(e, t) {
		let n = a(), r = this.#u.get(e);
		return r || this.#u.set(e, r = []), r.push(n), this.postMessage({
			method: e,
			value: t
		}), n.promise;
	}
	#R() {
		this.#s.stop(), this.#o = new h(0, 0), this.#d = null, this.#c = null, this.#n.set(!1), this.#M();
	}
	#z(e) {
		return this.#u.get(e)?.shift();
	}
};
//#endregion
export { v as VimeoProvider };
