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