import { b as e, e as t } from "./chunk.BlbRoQQ3.js";
import { b as n } from "./patterns.CVV2epWU.js";
import "./cjs.S1Glohke.js";
var r = /* @__PURE__ */ e(((exports, r) => {
	var i = Object.create, a = Object.defineProperty, o = Object.getOwnPropertyDescriptor, s = Object.getOwnPropertyNames, c = Object.getPrototypeOf, l = Object.prototype.hasOwnProperty, u = (e, t, n) => t in e ? a(e, t, {
		enumerable: !0,
		configurable: !0,
		writable: !0,
		value: n
	}) : e[t] = n, d = (e, t) => {
		for (var n in t) a(e, n, {
			get: t[n],
			enumerable: !0
		});
	}, f = (e, t, n, r) => {
		if (t && typeof t == "object" || typeof t == "function") for (let i of s(t)) !l.call(e, i) && i !== n && a(e, i, {
			get: () => t[i],
			enumerable: !(r = o(t, i)) || r.enumerable
		});
		return e;
	}, p = (e, t, n) => (n = e == null ? {} : i(c(e)), f(t || !e || !e.__esModule ? a(n, "default", {
		value: e,
		enumerable: !0
	}) : n, e)), m = (e) => f(a({}, "__esModule", { value: !0 }), e), h = (e, t, n) => (u(e, typeof t == "symbol" ? t : t + "", n), n), g = {};
	d(g, { default: () => y }), r.exports = m(g);
	var _ = p(t("react")), v = n(), y = class extends _.Component {
		constructor() {
			super(...arguments), h(this, "onReady", (...e) => this.props.onReady(...e)), h(this, "onPlay", (...e) => this.props.onPlay(...e)), h(this, "onBuffer", (...e) => this.props.onBuffer(...e)), h(this, "onBufferEnd", (...e) => this.props.onBufferEnd(...e)), h(this, "onPause", (...e) => this.props.onPause(...e)), h(this, "onEnded", (...e) => this.props.onEnded(...e)), h(this, "onError", (...e) => this.props.onError(...e)), h(this, "onPlayBackRateChange", (e) => this.props.onPlaybackRateChange(e.target.playbackRate)), h(this, "onEnablePIP", (...e) => this.props.onEnablePIP(...e)), h(this, "onSeek", (e) => {
				this.props.onSeek(e.target.currentTime);
			}), h(this, "onDurationChange", () => {
				let e = this.getDuration();
				this.props.onDuration(e);
			}), h(this, "mute", () => {
				this.player.muted = !0;
			}), h(this, "unmute", () => {
				this.player.muted = !1;
			}), h(this, "ref", (e) => {
				this.player = e;
			});
		}
		componentDidMount() {
			this.props.onMount && this.props.onMount(this), this.addListeners(this.player);
			let e = this.getPlaybackId(this.props.url);
			e && (this.player.playbackId = e);
		}
		componentWillUnmount() {
			this.player.playbackId = null, this.removeListeners(this.player);
		}
		addListeners(e) {
			let { playsinline: t } = this.props;
			e.addEventListener("play", this.onPlay), e.addEventListener("waiting", this.onBuffer), e.addEventListener("playing", this.onBufferEnd), e.addEventListener("pause", this.onPause), e.addEventListener("seeked", this.onSeek), e.addEventListener("ended", this.onEnded), e.addEventListener("error", this.onError), e.addEventListener("ratechange", this.onPlayBackRateChange), e.addEventListener("enterpictureinpicture", this.onEnablePIP), e.addEventListener("leavepictureinpicture", this.onDisablePIP), e.addEventListener("webkitpresentationmodechanged", this.onPresentationModeChange), e.addEventListener("canplay", this.onReady), t && e.setAttribute("playsinline", "");
		}
		removeListeners(e) {
			e.removeEventListener("canplay", this.onReady), e.removeEventListener("play", this.onPlay), e.removeEventListener("waiting", this.onBuffer), e.removeEventListener("playing", this.onBufferEnd), e.removeEventListener("pause", this.onPause), e.removeEventListener("seeked", this.onSeek), e.removeEventListener("ended", this.onEnded), e.removeEventListener("error", this.onError), e.removeEventListener("ratechange", this.onPlayBackRateChange), e.removeEventListener("enterpictureinpicture", this.onEnablePIP), e.removeEventListener("leavepictureinpicture", this.onDisablePIP), e.removeEventListener("canplay", this.onReady);
		}
		async load(e) {
			var t;
			let { onError: n, config: r } = this.props;
			if (!(t = globalThis.customElements)?.get("mux-player")) try {
				let e = "https://cdn.jsdelivr.net/npm/@mux/mux-player@VERSION/dist/mux-player.mjs".replace("VERSION", r.version);
				await import(
					/* webpackIgnore: true */
					`${e}`
), this.props.onLoaded();
			} catch (e) {
				n(e);
			}
			let [, i] = e.match(v.MATCH_URL_MUX);
			this.player.playbackId = i;
		}
		play() {
			let e = this.player.play();
			e && e.catch(this.props.onError);
		}
		pause() {
			this.player.pause();
		}
		stop() {
			this.player.playbackId = null;
		}
		seekTo(e, t = !0) {
			this.player.currentTime = e, t || this.pause();
		}
		setVolume(e) {
			this.player.volume = e;
		}
		enablePIP() {
			this.player.requestPictureInPicture && document.pictureInPictureElement !== this.player && this.player.requestPictureInPicture();
		}
		disablePIP() {
			document.exitPictureInPicture && document.pictureInPictureElement === this.player && document.exitPictureInPicture();
		}
		setPlaybackRate(e) {
			try {
				this.player.playbackRate = e;
			} catch (e) {
				this.props.onError(e);
			}
		}
		getDuration() {
			if (!this.player) return null;
			let { duration: e, seekable: t } = this.player;
			return e === Infinity && t.length > 0 ? t.end(t.length - 1) : e;
		}
		getCurrentTime() {
			return this.player ? this.player.currentTime : null;
		}
		getSecondsLoaded() {
			if (!this.player) return null;
			let { buffered: e } = this.player;
			if (e.length === 0) return 0;
			let t = e.end(e.length - 1), n = this.getDuration();
			return t > n ? n : t;
		}
		getPlaybackId(e) {
			let [, t] = e.match(v.MATCH_URL_MUX);
			return t;
		}
		render() {
			let { url: e, playing: t, loop: n, controls: r, muted: i, config: a, width: o, height: s } = this.props, c = {
				width: o === "auto" ? o : "100%",
				height: s === "auto" ? s : "100%"
			};
			return r === !1 && (c["--controls"] = "none"), /* @__PURE__ */ _.default.createElement("mux-player", {
				ref: this.ref,
				"playback-id": this.getPlaybackId(e),
				style: c,
				preload: "auto",
				autoPlay: t || void 0,
				muted: i ? "" : void 0,
				loop: n ? "" : void 0,
				...a.attributes
			});
		}
	};
	h(y, "displayName", "Mux"), h(y, "canPlay", v.canPlay.mux);
}));
export default r();

//# sourceMappingURL=Mux.C3jiDfUK.js.map