import React, { Component } from "react";
import { Player } from "./player.js";
import { DEPRECATED_CONFIG_PROPS, defaultProps, propTypes } from "./props.js";
import { getConfig, isEqual, omit } from "./utils.js";
const SUPPORTED_PROPS = Object.keys(propTypes);
function createSinglePlayer(activePlayer) {
  var _a;
  return _a = class extends Component {
    constructor() {
      super(...arguments);
      this.config = getConfig(this.props, defaultProps, 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.ref = (player) => {
        this.player = player;
      };
    }
    shouldComponentUpdate(nextProps) {
      return !isEqual(this.props, nextProps);
    }
    componentDidUpdate() {
      this.config = getConfig(this.props, defaultProps);
    }
    render() {
      const { forceVideo, forceAudio, forceHLS, forceDASH } = this.config.file;
      const skipCanPlay = forceVideo || forceAudio || forceHLS || forceDASH;
      if (!activePlayer.canPlay(this.props.url) && !skipCanPlay) {
        return null;
      }
      const { style, width, height, wrapper: Wrapper } = this.props;
      const otherProps = omit(this.props, SUPPORTED_PROPS, DEPRECATED_CONFIG_PROPS);
      return /* @__PURE__ */ React.createElement(Wrapper, { style: { ...style, width, height }, ...otherProps }, /* @__PURE__ */ React.createElement(Player, { ...this.props, ref: this.ref, activePlayer, config: this.config }));
    }
  }, _a.displayName = `${activePlayer.displayName}Player`, _a.propTypes = propTypes, _a.defaultProps = defaultProps, _a.canPlay = activePlayer.canPlay, _a;
}
export {
  createSinglePlayer
};
//# sourceMappingURL=single-player.js.map
