import w from "react";
import { __require as I } from "../../../../react-fast-compare@3.2.2/node_modules/react-fast-compare/index.js";
import { __require as M } from "./props.js";
import { __require as N } from "./utils.js";
var h, m;
function V() {
  if (m) return h;
  m = 1;
  var _ = Object.create, l = Object.defineProperty, O = Object.getOwnPropertyDescriptor, R = Object.getOwnPropertyNames, b = Object.getPrototypeOf, v = Object.prototype.hasOwnProperty, k = (a, e, t) => e in a ? l(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t, T = (a, e) => {
    for (var t in e)
      l(a, t, { get: e[t], enumerable: !0 });
  }, d = (a, e, t, r) => {
    if (e && typeof e == "object" || typeof e == "function")
      for (let i of R(e))
        !v.call(a, i) && i !== t && l(a, i, { get: () => e[i], enumerable: !(r = O(e, i)) || r.enumerable });
    return a;
  }, u = (a, e, t) => (t = a != null ? _(b(a)) : {}, d(
    // 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.
    !a || !a.__esModule ? l(t, "default", { value: a, enumerable: !0 }) : t,
    a
  )), L = (a) => d(l({}, "__esModule", { value: !0 }), a), s = (a, e, t) => (k(a, typeof e != "symbol" ? e + "" : e, t), t), p = {};
  T(p, {
    default: () => n
  }), h = L(p);
  var y = u(w), D = u(I()), f = /* @__PURE__ */ M(), C = /* @__PURE__ */ N();
  const S = 5e3;
  class n extends y.Component {
    constructor() {
      super(...arguments), s(this, "mounted", !1), s(this, "isReady", !1), s(this, "isPlaying", !1), s(this, "isLoading", !0), s(this, "loadOnReady", null), s(this, "startOnPlay", !0), s(this, "seekOnPlay", null), s(this, "onDurationCalled", !1), s(this, "handlePlayerMount", (e) => {
        if (this.player) {
          this.progress();
          return;
        }
        this.player = e, this.player.load(this.props.url), this.progress();
      }), s(this, "getInternalPlayer", (e) => this.player ? this.player[e] : null), s(this, "progress", () => {
        if (this.props.url && this.player && this.isReady) {
          const e = this.getCurrentTime() || 0, t = this.getSecondsLoaded(), r = this.getDuration();
          if (r) {
            const i = {
              playedSeconds: e,
              played: e / r
            };
            t !== null && (i.loadedSeconds = t, i.loaded = t / r), (i.playedSeconds !== this.prevPlayed || i.loadedSeconds !== this.prevLoaded) && this.props.onProgress(i), this.prevPlayed = i.playedSeconds, this.prevLoaded = i.loadedSeconds;
          }
        }
        this.progressTimeout = setTimeout(this.progress, this.props.progressFrequency || this.props.progressInterval);
      }), s(this, "handleReady", () => {
        if (!this.mounted)
          return;
        this.isReady = !0, this.isLoading = !1;
        const { onReady: e, playing: t, volume: r, muted: i } = this.props;
        e(), !i && r !== null && this.player.setVolume(r), this.loadOnReady ? (this.player.load(this.loadOnReady, !0), this.loadOnReady = null) : t && this.player.play(), this.handleDurationCheck();
      }), s(this, "handlePlay", () => {
        this.isPlaying = !0, this.isLoading = !1;
        const { onStart: e, onPlay: t, playbackRate: r } = this.props;
        this.startOnPlay && (this.player.setPlaybackRate && r !== 1 && this.player.setPlaybackRate(r), e(), this.startOnPlay = !1), t(), this.seekOnPlay && (this.seekTo(this.seekOnPlay), this.seekOnPlay = null), this.handleDurationCheck();
      }), s(this, "handlePause", (e) => {
        this.isPlaying = !1, this.isLoading || this.props.onPause(e);
      }), s(this, "handleEnded", () => {
        const { activePlayer: e, loop: t, onEnded: r } = this.props;
        e.loopOnEnded && t && this.seekTo(0), t || (this.isPlaying = !1, r());
      }), s(this, "handleError", (...e) => {
        this.isLoading = !1, this.props.onError(...e);
      }), s(this, "handleDurationCheck", () => {
        clearTimeout(this.durationCheckTimeout);
        const e = this.getDuration();
        e ? this.onDurationCalled || (this.props.onDuration(e), this.onDurationCalled = !0) : this.durationCheckTimeout = setTimeout(this.handleDurationCheck, 100);
      }), s(this, "handleLoaded", () => {
        this.isLoading = !1;
      });
    }
    componentDidMount() {
      this.mounted = !0;
    }
    componentWillUnmount() {
      clearTimeout(this.progressTimeout), clearTimeout(this.durationCheckTimeout), this.isReady && this.props.stopOnUnmount && (this.player.stop(), this.player.disablePIP && this.player.disablePIP()), this.mounted = !1;
    }
    componentDidUpdate(e) {
      if (!this.player)
        return;
      const { url: t, playing: r, volume: i, muted: o, playbackRate: c, pip: P, loop: g, activePlayer: E, disableDeferredLoading: q } = this.props;
      if (!(0, D.default)(e.url, t)) {
        if (this.isLoading && !E.forceLoad && !q && !(0, C.isMediaStream)(t)) {
          console.warn(`ReactPlayer: the attempt to load ${t} is being deferred until the player has loaded`), this.loadOnReady = t;
          return;
        }
        this.isLoading = !0, this.startOnPlay = !0, this.onDurationCalled = !1, this.player.load(t, this.isReady);
      }
      !e.playing && r && !this.isPlaying && this.player.play(), e.playing && !r && this.isPlaying && this.player.pause(), !e.pip && P && this.player.enablePIP && this.player.enablePIP(), e.pip && !P && this.player.disablePIP && this.player.disablePIP(), e.volume !== i && i !== null && this.player.setVolume(i), e.muted !== o && (o ? this.player.mute() : (this.player.unmute(), i !== null && setTimeout(() => this.player.setVolume(i)))), e.playbackRate !== c && this.player.setPlaybackRate && this.player.setPlaybackRate(c), e.loop !== g && this.player.setLoop && this.player.setLoop(g);
    }
    getDuration() {
      return this.isReady ? this.player.getDuration() : null;
    }
    getCurrentTime() {
      return this.isReady ? this.player.getCurrentTime() : null;
    }
    getSecondsLoaded() {
      return this.isReady ? this.player.getSecondsLoaded() : null;
    }
    seekTo(e, t, r) {
      if (!this.isReady) {
        e !== 0 && (this.seekOnPlay = e, setTimeout(() => {
          this.seekOnPlay = null;
        }, S));
        return;
      }
      if (t ? t === "fraction" : e > 0 && e < 1) {
        const o = this.player.getDuration();
        if (!o) {
          console.warn("ReactPlayer: could not seek using fraction – duration not yet available");
          return;
        }
        this.player.seekTo(o * e, r);
        return;
      }
      this.player.seekTo(e, r);
    }
    render() {
      const e = this.props.activePlayer;
      return e ? /* @__PURE__ */ y.default.createElement(
        e,
        {
          ...this.props,
          onMount: this.handlePlayerMount,
          onReady: this.handleReady,
          onPlay: this.handlePlay,
          onPause: this.handlePause,
          onEnded: this.handleEnded,
          onLoaded: this.handleLoaded,
          onError: this.handleError
        }
      ) : null;
    }
  }
  return s(n, "displayName", "Player"), s(n, "propTypes", f.propTypes), s(n, "defaultProps", f.defaultProps), h;
}
export {
  V as __require
};
//# sourceMappingURL=Player.js.map
