"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // 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.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var react_player_exports = {};
__export(react_player_exports, {
  ReactPlayer: () => ReactPlayer
});
module.exports = __toCommonJS(react_player_exports);
var import_react = __toESM(require("react"));
var import_player = require("./player.js");
var import_file_player = require("./players/file-player.js");
var import_players = require("./players/index.js");
var import_preload = require("./preload.js");
var import_preview = require("./preview.js");
var import_props = require("./props.js");
var import_utils = require("./utils.js");
const SUPPORTED_PROPS = Object.keys(import_props.propTypes);
let customPlayers = [];
class ReactPlayer extends import_react.default.Component {
  constructor(props) {
    super(props);
    this.handleClickPreview = () => {
      this.setState({ showPreview: false });
    };
    this.showPreview = () => {
      this.setState({ showPreview: true });
    };
    this.getDuration = () => {
      if (!this.player) {
        return null;
      }
      return this.player.getDuration();
    };
    this.getCurrentTime = () => {
      if (!this.player) {
        return null;
      }
      return this.player.getCurrentTime();
    };
    this.getSecondsLoaded = () => {
      if (!this.player) {
        return null;
      }
      return this.player.getSecondsLoaded();
    };
    this.getInternalPlayer = (key = "player") => {
      if (!this.player) {
        return null;
      }
      return this.player.getInternalPlayer(key);
    };
    this.seekTo = (fraction, type) => {
      if (!this.player) {
        return null;
      }
      this.player.seekTo(fraction, type);
    };
    this.handleReady = () => {
      this.props.onReady?.();
    };
    this.wrapperRef = (wrapper) => {
      this.wrapper = wrapper;
    };
    this.activePlayerRef = (player) => {
      this.player = player;
    };
    this.config = (0, import_utils.getConfig)(props, import_props.defaultProps, true);
    this.state = {
      showPreview: !!props.light
    };
  }
  componentDidMount() {
    if (this.props.progressFrequency) {
      const message = "ReactPlayer: %cprogressFrequency%c is deprecated, please use %cprogressInterval%c instead";
      console.warn(message, "font-weight: bold", "", "font-weight: bold", "");
    }
  }
  shouldComponentUpdate(nextProps, nextState) {
    return !(0, import_utils.isEqual)(this.props, nextProps) || !(0, import_utils.isEqual)(this.state, nextState);
  }
  componentDidUpdate(prevProps) {
    const { light } = this.props;
    this.config = (0, import_utils.getConfig)(this.props, import_props.defaultProps);
    if (!prevProps.light && light) {
      this.setState({ showPreview: true });
    }
    if (prevProps.light && !light) {
      this.setState({ showPreview: false });
    }
  }
  getActivePlayer(url) {
    const allPlayers = [...customPlayers, ...import_players.players];
    for (const Player2 of allPlayers) {
      if (Player2.canPlay(url)) {
        return Player2;
      }
    }
    return import_file_player.FilePlayer;
  }
  renderActivePlayer(url, activePlayer) {
    if (!url) {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_player.Player,
      {
        ...this.props,
        key: activePlayer.displayName,
        ref: this.activePlayerRef,
        config: this.config,
        activePlayer,
        onReady: this.handleReady
      }
    );
  }
  sortPlayers(a, b) {
    if (a && b) {
      return a.key < b.key ? -1 : 1;
    }
    return 0;
  }
  render() {
    const {
      url,
      controls,
      style,
      width,
      height,
      light,
      playIcon,
      wrapper: Wrapper,
      previewTabIndex,
      previewAriaLabel
    } = this.props;
    const showPreview = this.state.showPreview && url;
    const otherProps = (0, import_utils.omit)(this.props, SUPPORTED_PROPS, import_props.DEPRECATED_CONFIG_PROPS);
    const activePlayer = this.getActivePlayer(url);
    const renderedActivePlayer = this.renderActivePlayer(url, activePlayer);
    const preloadPlayers = (0, import_preload.renderPreloadPlayers)(url, controls, this.config);
    const players2 = [renderedActivePlayer, ...preloadPlayers].sort(this.sortPlayers);
    const preview = /* @__PURE__ */ import_react.default.createElement(
      import_preview.Preview,
      {
        url,
        light,
        playIcon,
        onClick: this.handleClickPreview,
        previewTabIndex,
        previewAriaLabel
      }
    );
    return /* @__PURE__ */ import_react.default.createElement(Wrapper, { ref: this.wrapperRef, style: { ...style, width, height }, ...otherProps }, showPreview ? preview : players2);
  }
}
ReactPlayer.addCustomPlayer = (player) => {
  customPlayers.push(player);
};
ReactPlayer.removeCustomPlayers = () => {
  customPlayers = [];
};
ReactPlayer.displayName = "ReactPlayer";
ReactPlayer.propTypes = import_props.propTypes;
ReactPlayer.defaultProps = import_props.defaultProps;
ReactPlayer.canPlay = (url) => {
  const allPlayers = [...customPlayers, ...import_players.players];
  for (const Player2 of allPlayers) {
    if (Player2.canPlay(url)) {
      return true;
    }
  }
  return false;
};
ReactPlayer.canEnablePIP = (url) => {
  const allPlayers = [...customPlayers, ...import_players.players];
  for (const Player2 of allPlayers) {
    if (Player2.canEnablePIP && Player2.canEnablePIP(url)) {
      return true;
    }
  }
  return false;
};
//# sourceMappingURL=react-player.js.map
