import { commonjsGlobal as P } from "../../../../../../_virtual/_commonjsHelpers.mjs";
import R from "react";
import { c as S } from "../../../../deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.mjs";
import C from "../../../../../../_virtual/memoize-one.esm.mjs";
import { r as E } from "../../../../react-fast-compare@3.2.2/node_modules/react-fast-compare/index.mjs";
import { p as I } from "./props.mjs";
import { u as T } from "./utils.mjs";
import { P as j } from "./Player.mjs";
var k = Object.create, u = Object.defineProperty, A = Object.getOwnPropertyDescriptor, D = Object.getOwnPropertyNames, x = Object.getPrototypeOf, L = Object.prototype.hasOwnProperty, U = (r, s, a) => s in r ? u(r, s, { enumerable: !0, configurable: !0, writable: !0, value: a }) : r[s] = a, N = (r, s) => {
  for (var a in s)
    u(r, a, { get: s[a], enumerable: !0 });
}, _ = (r, s, a, e) => {
  if (s && typeof s == "object" || typeof s == "function")
    for (let t of D(s))
      !L.call(r, t) && t !== a && u(r, t, { get: () => s[t], enumerable: !(e = A(s, t)) || e.enumerable });
  return r;
}, c = (r, s, a) => (a = r != null ? k(x(r)) : {}, _(
  // 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.
  s || !r || !r.__esModule ? u(a, "default", { value: r, enumerable: !0 }) : a,
  r
)), z = (r) => _(u({}, "__esModule", { value: !0 }), r), i = (r, s, a) => (U(r, typeof s != "symbol" ? s + "" : s, a), a), v = {};
N(v, {
  createReactPlayer: () => J
});
var te = z(v), o = c(R), M = c(S), d = c(C), m = c(E), p = I, w = T, B = c(j);
const F = (0, w.lazy)(() => import(
  /* webpackChunkName: 'reactPlayerPreview' */
  "./Preview.mjs"
).then((r) => r.P)), G = typeof window < "u" && window.document && typeof document < "u", W = typeof P < "u" && P.window && P.window.document, $ = Object.keys(p.propTypes), q = G || W ? o.Suspense : () => null, l = [], J = (r, s) => {
  var a;
  return a = class extends o.Component {
    constructor() {
      super(...arguments), i(this, "state", {
        showPreview: !!this.props.light
      }), i(this, "references", {
        wrapper: (e) => {
          this.wrapper = e;
        },
        player: (e) => {
          this.player = e;
        }
      }), i(this, "handleClickPreview", (e) => {
        this.setState({ showPreview: !1 }), this.props.onClickPreview(e);
      }), i(this, "showPreview", () => {
        this.setState({ showPreview: !0 });
      }), i(this, "getDuration", () => this.player ? this.player.getDuration() : null), i(this, "getCurrentTime", () => this.player ? this.player.getCurrentTime() : null), i(this, "getSecondsLoaded", () => this.player ? this.player.getSecondsLoaded() : null), i(this, "getInternalPlayer", (e = "player") => this.player ? this.player.getInternalPlayer(e) : null), i(this, "seekTo", (e, t, n) => {
        if (!this.player)
          return null;
        this.player.seekTo(e, t, n);
      }), i(this, "handleReady", () => {
        this.props.onReady(this);
      }), i(this, "getActivePlayer", (0, d.default)((e) => {
        for (const t of [...l, ...r])
          if (t.canPlay(e))
            return t;
        return s || null;
      })), i(this, "getConfig", (0, d.default)((e, t) => {
        const { config: n } = this.props;
        return M.default.all([
          p.defaultProps.config,
          p.defaultProps.config[t] || {},
          n,
          n[t] || {}
        ]);
      })), i(this, "getAttributes", (0, d.default)((e) => (0, w.omit)(this.props, $))), i(this, "renderActivePlayer", (e) => {
        if (!e)
          return null;
        const t = this.getActivePlayer(e);
        if (!t)
          return null;
        const n = this.getConfig(e, t.key);
        return /* @__PURE__ */ o.default.createElement(
          B.default,
          {
            ...this.props,
            key: t.key,
            ref: this.references.player,
            config: n,
            activePlayer: t.lazyPlayer || t,
            onReady: this.handleReady
          }
        );
      });
    }
    shouldComponentUpdate(e, t) {
      return !(0, m.default)(this.props, e) || !(0, m.default)(this.state, t);
    }
    componentDidUpdate(e) {
      const { light: t } = this.props;
      !e.light && t && this.setState({ showPreview: !0 }), e.light && !t && this.setState({ showPreview: !1 });
    }
    renderPreview(e) {
      if (!e)
        return null;
      const { light: t, playIcon: n, previewTabIndex: h, oEmbedUrl: y, previewAriaLabel: f } = this.props;
      return /* @__PURE__ */ o.default.createElement(
        F,
        {
          url: e,
          light: t,
          playIcon: n,
          previewTabIndex: h,
          previewAriaLabel: f,
          oEmbedUrl: y,
          onClick: this.handleClickPreview
        }
      );
    }
    render() {
      const { url: e, style: t, width: n, height: h, fallback: y, wrapper: f } = this.props, { showPreview: g } = this.state, b = this.getAttributes(e), O = typeof f == "string" ? this.references.wrapper : void 0;
      return /* @__PURE__ */ o.default.createElement(f, { ref: O, style: { ...t, width: n, height: h }, ...b }, /* @__PURE__ */ o.default.createElement(q, { fallback: y }, g ? this.renderPreview(e) : this.renderActivePlayer(e)));
    }
  }, i(a, "displayName", "ReactPlayer"), i(a, "propTypes", p.propTypes), i(a, "defaultProps", p.defaultProps), i(a, "addCustomPlayer", (e) => {
    l.push(e);
  }), i(a, "removeCustomPlayers", () => {
    l.length = 0;
  }), i(a, "canPlay", (e) => {
    for (const t of [...l, ...r])
      if (t.canPlay(e))
        return !0;
    return !1;
  }), i(a, "canEnablePIP", (e) => {
    for (const t of [...l, ...r])
      if (t.canEnablePIP && t.canEnablePIP(e))
        return !0;
    return !1;
  }), a;
};
export {
  te as R
};
//# sourceMappingURL=ReactPlayer.mjs.map
