import { b as e, e as t } from "./chunk.BlbRoQQ3.js";
import { b as n, c as r } from "./patterns.CVV2epWU.js";
import "./cjs.S1Glohke.js";
var i = /* @__PURE__ */ e(((exports, i) => {
	var a = Object.create, o = Object.defineProperty, s = Object.getOwnPropertyDescriptor, c = Object.getOwnPropertyNames, l = Object.getPrototypeOf, u = Object.prototype.hasOwnProperty, d = (e, t, n) => t in e ? o(e, t, {
		enumerable: !0,
		configurable: !0,
		writable: !0,
		value: n
	}) : e[t] = n, f = (e, t) => {
		for (var n in t) o(e, n, {
			get: t[n],
			enumerable: !0
		});
	}, p = (e, t, n, r) => {
		if (t && typeof t == "object" || typeof t == "function") for (let i of c(t)) !u.call(e, i) && i !== n && o(e, i, {
			get: () => t[i],
			enumerable: !(r = s(t, i)) || r.enumerable
		});
		return e;
	}, m = (e, t, n) => (n = e == null ? {} : a(l(e)), p(t || !e || !e.__esModule ? o(n, "default", {
		value: e,
		enumerable: !0
	}) : n, e)), h = (e) => p(o({}, "__esModule", { value: !0 }), e), g = (e, t, n) => (d(e, typeof t == "symbol" ? t : t + "", n), n), _ = {};
	f(_, { default: () => w }), i.exports = h(_);
	var v = m(t("react")), y = r(), b = n();
	let x = /[?&](?:list|channel)=([a-zA-Z0-9_-]+)/, S = /user\/([a-zA-Z0-9_-]+)\/?/, C = /youtube-nocookie\.com/;
	var w = class extends v.Component {
		constructor() {
			super(...arguments), g(this, "callPlayer", y.callPlayer), g(this, "parsePlaylist", (e) => {
				if (e instanceof Array) return {
					listType: "playlist",
					playlist: e.map(this.getID).join(",")
				};
				if (x.test(e)) {
					let [, t] = e.match(x);
					return {
						listType: "playlist",
						list: t.replace(/^UC/, "UU")
					};
				}
				if (S.test(e)) {
					let [, t] = e.match(S);
					return {
						listType: "user_uploads",
						list: t
					};
				}
				return {};
			}), g(this, "onStateChange", (e) => {
				let { data: t } = e, { onPlay: n, onPause: r, onBuffer: i, onBufferEnd: a, onEnded: o, onReady: s, loop: c, config: { playerVars: l, onUnstarted: u } } = this.props, { UNSTARTED: d, PLAYING: f, PAUSED: p, BUFFERING: m, ENDED: h, CUED: g } = window.YT.PlayerState;
				if (t === d && u(), t === f && (n(), a()), t === p && r(), t === m && i(), t === h) {
					let e = !!this.callPlayer("getPlaylist");
					c && !e && (l.start ? this.seekTo(l.start) : this.play()), o();
				}
				t === g && s();
			}), g(this, "mute", () => {
				this.callPlayer("mute");
			}), g(this, "unmute", () => {
				this.callPlayer("unMute");
			}), g(this, "ref", (e) => {
				this.container = e;
			});
		}
		componentDidMount() {
			this.props.onMount && this.props.onMount(this);
		}
		getID(e) {
			return !e || e instanceof Array || x.test(e) ? null : e.match(b.MATCH_URL_YOUTUBE)[1];
		}
		load(e, t) {
			let { playing: n, muted: r, playsinline: i, controls: a, loop: o, config: s, onError: c } = this.props, { playerVars: l, embedOptions: u } = s, d = this.getID(e);
			if (t) {
				if (x.test(e) || S.test(e) || e instanceof Array) {
					this.player.loadPlaylist(this.parsePlaylist(e));
					return;
				}
				this.player.cueVideoById({
					videoId: d,
					startSeconds: (0, y.parseStartTime)(e) || l.start,
					endSeconds: (0, y.parseEndTime)(e) || l.end
				});
				return;
			}
			(0, y.getSDK)("https://www.youtube.com/iframe_api", "YT", "onYouTubeIframeAPIReady", (e) => e.loaded).then((t) => {
				this.container && (this.player = new t.Player(this.container, {
					width: "100%",
					height: "100%",
					videoId: d,
					playerVars: {
						autoplay: n ? 1 : 0,
						mute: r ? 1 : 0,
						controls: a ? 1 : 0,
						start: (0, y.parseStartTime)(e),
						end: (0, y.parseEndTime)(e),
						origin: window.location.origin,
						playsinline: i ? 1 : 0,
						...this.parsePlaylist(e),
						...l
					},
					events: {
						onReady: () => {
							o && this.player.setLoop(!0), this.props.onReady();
						},
						onPlaybackRateChange: (e) => this.props.onPlaybackRateChange(e.data),
						onPlaybackQualityChange: (e) => this.props.onPlaybackQualityChange(e),
						onStateChange: this.onStateChange,
						onError: (e) => c(e.data)
					},
					host: C.test(e) ? "https://www.youtube-nocookie.com" : void 0,
					...u
				}));
			}, c), u.events && console.warn("Using `embedOptions.events` will likely break things. Use ReactPlayer’s callback props instead, eg onReady, onPlay, onPause");
		}
		play() {
			this.callPlayer("playVideo");
		}
		pause() {
			this.callPlayer("pauseVideo");
		}
		stop() {
			document.body.contains(this.callPlayer("getIframe")) && this.callPlayer("stopVideo");
		}
		seekTo(e, t = !1) {
			this.callPlayer("seekTo", e), !t && !this.props.playing && this.pause();
		}
		setVolume(e) {
			this.callPlayer("setVolume", e * 100);
		}
		setPlaybackRate(e) {
			this.callPlayer("setPlaybackRate", e);
		}
		setLoop(e) {
			this.callPlayer("setLoop", e);
		}
		getDuration() {
			return this.callPlayer("getDuration");
		}
		getCurrentTime() {
			return this.callPlayer("getCurrentTime");
		}
		getSecondsLoaded() {
			return this.callPlayer("getVideoLoadedFraction") * this.getDuration();
		}
		render() {
			let { display: e } = this.props, t = {
				width: "100%",
				height: "100%",
				display: e
			};
			return /* @__PURE__ */ v.default.createElement("div", { style: t }, /* @__PURE__ */ v.default.createElement("div", { ref: this.ref }));
		}
	};
	g(w, "displayName", "YouTube"), g(w, "canPlay", b.canPlay.youtube);
}));
export default i();

//# sourceMappingURL=YouTube.D2Got9Av.js.map