import { G as e } from "./vidstack-D9mvYVIz-DesuYgKV.js";
import { c as t, i as n, r } from "./useVidstackSrc-epUQZhkL.js";
import { r as i } from "./vidstack-mvRkf9tF-CoFf7dS9.js";
import { c as a, i as o, l as s, n as c, o as l, r as u, t as d, u as f } from "./vidstack-DATGlkSz2-BnlUxvSa.js";
//#region node_modules/vidstack/prod/chunks/vidstack-DUnfBERX2.js
var p = class {
	name = "google-cast";
	target;
	#e;
	get cast() {
		return d();
	}
	mediaType() {
		return "video";
	}
	canPlay(e) {
		return r && !n && t(e);
	}
	async prompt(t) {
		let n, r, i;
		try {
			n = await this.#t(t), this.#e || (this.#e = new cast.framework.RemotePlayer(), new cast.framework.RemotePlayerController(this.#e)), r = t.player.createEvent("google-cast-prompt-open", { trigger: n }), t.player.dispatchEvent(r), this.#i(t, "connecting", r), await this.#n(e(t.$props.googleCast)), t.$state.remotePlaybackInfo.set({ deviceName: o()?.getCastDevice().friendlyName }), f() && this.#i(t, "connected", r);
		} catch (e) {
			let a = e instanceof Error ? e : this.#a((e + "").toUpperCase(), "Prompt failed.");
			throw i = t.player.createEvent("google-cast-prompt-error", {
				detail: a,
				trigger: r ?? n,
				cancelable: !0
			}), t.player.dispatch(i), this.#i(t, f() ? "connected" : "disconnected", i), a;
		} finally {
			t.player.dispatch("google-cast-prompt-close", { trigger: i ?? r ?? n });
		}
	}
	async load(e) {
		if (!this.#e) throw Error("[vidstack] google cast player was not initialized");
		return new (await (import("./vidstack-google-cast-COyApZ_Z.js"))).GoogleCastProvider(this.#e, e);
	}
	async #t(e) {
		if (a()) return;
		let t = e.player.createEvent("google-cast-load-start");
		e.player.dispatch(t), await i(u()), await customElements.whenDefined("google-cast-launcher");
		let n = e.player.createEvent("google-cast-loaded", { trigger: t });
		if (e.player.dispatch(n), !s()) throw this.#a("CAST_NOT_AVAILABLE", "Google Cast not available on this platform.");
		return n;
	}
	async #n(e) {
		this.#r(e);
		let t = await this.cast.requestSession();
		if (t) throw this.#a(t.toUpperCase(), c(t));
	}
	#r(e) {
		this.cast?.setOptions({
			...l(),
			...e
		});
	}
	#i(e, t, n) {
		let r = {
			type: "google-cast",
			state: t
		};
		e.notify("remote-playback-change", r, n);
	}
	#a(e, t) {
		let n = Error(t);
		return n.code = e, n;
	}
};
//#endregion
export { p as GoogleCastLoader };
