import { g as e } from "./alasql-f60045ee.js";
import t from "react";
import { u as a, p as r } from "./index-abe53b6f.js";
function o(e2, t2) {
  for (var a2 = 0; a2 < t2.length; a2++) {
    const r2 = t2[a2];
    if ("string" != typeof r2 && !Array.isArray(r2)) {
      for (const t3 in r2)
        if ("default" !== t3 && !(t3 in e2)) {
          const a3 = Object.getOwnPropertyDescriptor(r2, t3);
          a3 && Object.defineProperty(e2, t3, a3.get ? a3 : { enumerable: true, get: () => r2[t3] });
        }
    }
  }
  return Object.freeze(Object.defineProperty(e2, Symbol.toStringTag, { value: "Module" }));
}
var s = Object.create, l = Object.defineProperty, n = Object.getOwnPropertyDescriptor, i = Object.getOwnPropertyNames, p = Object.getPrototypeOf, y = Object.prototype.hasOwnProperty, c = (e2, t2, a2, r2) => {
  if (t2 && "object" == typeof t2 || "function" == typeof t2)
    for (let o2 of i(t2))
      y.call(e2, o2) || o2 === a2 || l(e2, o2, { get: () => t2[o2], enumerable: !(r2 = n(t2, o2)) || r2.enumerable });
  return e2;
}, u = (e2, t2, a2) => (((e3, t3, a3) => {
  t3 in e3 ? l(e3, t3, { enumerable: true, configurable: true, writable: true, value: a3 }) : e3[t3] = a3;
})(e2, "symbol" != typeof t2 ? t2 + "" : t2, a2), a2), d = {};
((e2, t2) => {
  for (var a2 in t2)
    l(e2, a2, { get: t2[a2], enumerable: true });
})(d, { default: () => v });
var h, f = (h = d, c(l({}, "__esModule", { value: true }), h)), m = ((e2, t2, a2) => (a2 = null != e2 ? s(p(e2)) : {}, c(!t2 && e2 && e2.__esModule ? a2 : l(a2, "default", { value: e2, enumerable: true }), e2)))(t), P = a, g = r;
const b = /[?&](?:list|channel)=([a-zA-Z0-9_-]+)/, T = /user\/([a-zA-Z0-9_-]+)\/?/, w = /youtube-nocookie\.com/;
class v extends m.Component {
  constructor() {
    super(...arguments), u(this, "callPlayer", P.callPlayer), u(this, "parsePlaylist", (e2) => {
      if (e2 instanceof Array)
        return { listType: "playlist", playlist: e2.map(this.getID).join(",") };
      if (b.test(e2)) {
        const [, t2] = e2.match(b);
        return { listType: "playlist", list: t2.replace(/^UC/, "UU") };
      }
      if (T.test(e2)) {
        const [, t2] = e2.match(T);
        return { listType: "user_uploads", list: t2 };
      }
      return {};
    }), u(this, "onStateChange", (e2) => {
      const { data: t2 } = e2, { onPlay: a2, onPause: r2, onBuffer: o2, onBufferEnd: s2, onEnded: l2, onReady: n2, loop: i2, config: { playerVars: p2, onUnstarted: y2 } } = this.props, { UNSTARTED: c2, PLAYING: u2, PAUSED: d2, BUFFERING: h2, ENDED: f2, CUED: m2 } = window.YT.PlayerState;
      if (t2 === c2 && y2(), t2 === u2 && (a2(), s2()), t2 === d2 && r2(), t2 === h2 && o2(), t2 === f2) {
        const e3 = !!this.callPlayer("getPlaylist");
        i2 && !e3 && (p2.start ? this.seekTo(p2.start) : this.play()), l2();
      }
      t2 === m2 && n2();
    }), u(this, "mute", () => {
      this.callPlayer("mute");
    }), u(this, "unmute", () => {
      this.callPlayer("unMute");
    }), u(this, "ref", (e2) => {
      this.container = e2;
    });
  }
  componentDidMount() {
    this.props.onMount && this.props.onMount(this);
  }
  getID(e2) {
    return !e2 || e2 instanceof Array || b.test(e2) ? null : e2.match(g.MATCH_URL_YOUTUBE)[1];
  }
  load(e2, t2) {
    const { playing: a2, muted: r2, playsinline: o2, controls: s2, loop: l2, config: n2, onError: i2 } = this.props, { playerVars: p2, embedOptions: y2 } = n2, c2 = this.getID(e2);
    if (t2)
      return b.test(e2) || T.test(e2) || e2 instanceof Array ? void this.player.loadPlaylist(this.parsePlaylist(e2)) : void this.player.cueVideoById({ videoId: c2, startSeconds: (0, P.parseStartTime)(e2) || p2.start, endSeconds: (0, P.parseEndTime)(e2) || p2.end });
    (0, P.getSDK)("https://www.youtube.com/iframe_api", "YT", "onYouTubeIframeAPIReady", (e3) => e3.loaded).then((t3) => {
      this.container && (this.player = new t3.Player(this.container, { width: "100%", height: "100%", videoId: c2, playerVars: { autoplay: a2 ? 1 : 0, mute: r2 ? 1 : 0, controls: s2 ? 1 : 0, start: (0, P.parseStartTime)(e2), end: (0, P.parseEndTime)(e2), origin: window.location.origin, playsinline: o2 ? 1 : 0, ...this.parsePlaylist(e2), ...p2 }, events: { onReady: () => {
        l2 && this.player.setLoop(true), this.props.onReady();
      }, onPlaybackRateChange: (e3) => this.props.onPlaybackRateChange(e3.data), onPlaybackQualityChange: (e3) => this.props.onPlaybackQualityChange(e3), onStateChange: this.onStateChange, onError: (e3) => i2(e3.data) }, host: w.test(e2) ? "https://www.youtube-nocookie.com" : void 0, ...y2 }));
    }, i2), y2.events;
  }
  play() {
    this.callPlayer("playVideo");
  }
  pause() {
    this.callPlayer("pauseVideo");
  }
  stop() {
    document.body.contains(this.callPlayer("getIframe")) && this.callPlayer("stopVideo");
  }
  seekTo(e2, t2 = false) {
    this.callPlayer("seekTo", e2), t2 || this.props.playing || this.pause();
  }
  setVolume(e2) {
    this.callPlayer("setVolume", 100 * e2);
  }
  setPlaybackRate(e2) {
    this.callPlayer("setPlaybackRate", e2);
  }
  setLoop(e2) {
    this.callPlayer("setLoop", e2);
  }
  getDuration() {
    return this.callPlayer("getDuration");
  }
  getCurrentTime() {
    return this.callPlayer("getCurrentTime");
  }
  getSecondsLoaded() {
    return this.callPlayer("getVideoLoadedFraction") * this.getDuration();
  }
  render() {
    const { display: e2 } = this.props, t2 = { width: "100%", height: "100%", display: e2 };
    return m.default.createElement("div", { style: t2 }, m.default.createElement("div", { ref: this.ref }));
  }
}
u(v, "displayName", "YouTube"), u(v, "canPlay", g.canPlay.youtube);
const O = o({ __proto__: null, default: e(f) }, [f]);
export {
  O as Y
};
