import x from "react";
import { __require as F } from "../utils.js";
import { __require as K } from "../patterns.js";
var c, v;
function G() {
  if (v) return c;
  v = 1;
  var m = Object.create, i = Object.defineProperty, f = Object.getOwnPropertyDescriptor, E = Object.getOwnPropertyNames, L = Object.getPrototypeOf, g = Object.prototype.hasOwnProperty, w = (t, e, r) => e in t ? i(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, O = (t, e) => {
    for (var r in e)
      i(t, r, { get: e[r], enumerable: !0 });
  }, _ = (t, e, r, u) => {
    if (e && typeof e == "object" || typeof e == "function")
      for (let s of E(e))
        !g.call(t, s) && s !== r && i(t, s, { get: () => e[s], enumerable: !(u = f(e, s)) || u.enumerable });
    return t;
  }, T = (t, e, r) => (r = t != null ? m(L(t)) : {}, _(
    // If the importer is in node compatibility mode or this is not an ESM
    // file that has been converted to a CommonJS file using a Babel-
    // compatible transform (i.e. "__esModule" has not been set), then set
    // "default" to the CommonJS "module.exports" for node compatibility.
    !t || !t.__esModule ? i(r, "default", { value: t, enumerable: !0 }) : r,
    t
  )), D = (t) => _(i({}, "__esModule", { value: !0 }), t), a = (t, e, r) => (w(t, typeof e != "symbol" ? e + "" : e, r), r), d = {};
  O(d, {
    default: () => p
  }), c = D(d);
  var y = T(x), o = /* @__PURE__ */ F(), l = /* @__PURE__ */ K();
  const b = "https://player.twitch.tv/js/embed/v1.js", C = "Twitch", N = "twitch-player-";
  class p extends y.Component {
    constructor() {
      super(...arguments), a(this, "callPlayer", o.callPlayer), a(this, "playerID", this.props.config.playerId || `${N}${(0, o.randomString)()}`), a(this, "mute", () => {
        this.callPlayer("setMuted", !0);
      }), a(this, "unmute", () => {
        this.callPlayer("setMuted", !1);
      });
    }
    componentDidMount() {
      this.props.onMount && this.props.onMount(this);
    }
    load(e, r) {
      const { playsinline: u, onError: s, config: I, controls: M } = this.props, n = l.MATCH_URL_TWITCH_CHANNEL.test(e), h = n ? e.match(l.MATCH_URL_TWITCH_CHANNEL)[1] : e.match(l.MATCH_URL_TWITCH_VIDEO)[1];
      if (r) {
        n ? this.player.setChannel(h) : this.player.setVideo("v" + h);
        return;
      }
      (0, o.getSDK)(b, C).then((P) => {
        this.player = new P.Player(this.playerID, {
          video: n ? "" : h,
          channel: n ? h : "",
          height: "100%",
          width: "100%",
          playsinline: u,
          autoplay: this.props.playing,
          muted: this.props.muted,
          // https://github.com/CookPete/react-player/issues/733#issuecomment-549085859
          controls: n ? !0 : M,
          time: (0, o.parseStartTime)(e),
          ...I.options
        });
        const { READY: S, PLAYING: A, PAUSE: R, ENDED: H, ONLINE: j, OFFLINE: q, SEEK: U } = P.Player;
        this.player.addEventListener(S, this.props.onReady), this.player.addEventListener(A, this.props.onPlay), this.player.addEventListener(R, this.props.onPause), this.player.addEventListener(H, this.props.onEnded), this.player.addEventListener(U, this.props.onSeek), this.player.addEventListener(j, this.props.onLoaded), this.player.addEventListener(q, this.props.onLoaded);
      }, s);
    }
    play() {
      this.callPlayer("play");
    }
    pause() {
      this.callPlayer("pause");
    }
    stop() {
      this.callPlayer("pause");
    }
    seekTo(e, r = !0) {
      this.callPlayer("seek", e), r || this.pause();
    }
    setVolume(e) {
      this.callPlayer("setVolume", e);
    }
    getDuration() {
      return this.callPlayer("getDuration");
    }
    getCurrentTime() {
      return this.callPlayer("getCurrentTime");
    }
    getSecondsLoaded() {
      return null;
    }
    render() {
      const e = {
        width: "100%",
        height: "100%"
      };
      return /* @__PURE__ */ y.default.createElement("div", { style: e, id: this.playerID });
    }
  }
  return a(p, "displayName", "Twitch"), a(p, "canPlay", l.canPlay.twitch), a(p, "loopOnEnded", !0), c;
}
export {
  G as __require
};
//# sourceMappingURL=Twitch.js.map
