"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MediaControls = exports["default"] = void 0;

var _jsxRuntime = require("react/jsx-runtime");

var _kind = _interopRequireDefault(require("@enact/core/kind"));

var _SpotlightContainerDecorator = require("@enact/spotlight/SpotlightContainerDecorator");

var _classnames = _interopRequireDefault(require("classnames"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _$L = _interopRequireDefault(require("../internal/$L"));

var _Button = _interopRequireDefault(require("../Button"));

var _Icon = _interopRequireDefault(require("../Icon"));

var _MediaControlsModule = _interopRequireDefault(require("./MediaControls.module.css"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var badges = {
  none: '',
  one: '1',
  all: 'A'
};
var Container = (0, _SpotlightContainerDecorator.SpotlightContainerDecorator)({
  enterTo: 'default-element'
}, 'div');
/**
 * A set of components for controlling media playback and rendering additional components.
 *
 * @class MediaControls
 * @memberof agate/MediaPlayer
 * @ui
 * @private
 */

var MediaControls = (0, _kind["default"])({
  name: 'MediaControls',
  propTypes:
  /** @lends agate/MediaPlayer.MediaControls.prototype */
  {
    /**
     * A string which is sent to the `menu` icon of the player controls. This can be
     * anything that is accepted by {@link agate/Icon.Icon}.
     *
     * @type {String}
     * @default 'menu'
     * @public
     */
    menuIcon: _propTypes["default"].string,

    /**
     * A string which is sent to the `nextTrack` icon of the player controls. This can be
     * anything that is accepted by {@link agate/Icon.Icon}.
     *
     * @type {String}
     * @default 'nexttrack'
     * @public
     */
    nextTrackIcon: _propTypes["default"].string,

    /**
     * Called when the user clicks the Next button.
     *
     * @type {Function}
     * @public
     */
    onNext: _propTypes["default"].func,

    /**
     * Called when the user clicks the Pause button.
     *
     * @type {Function}
     * @public
     */
    onPause: _propTypes["default"].func,

    /**
     * Called when the user clicks the Play button.
     *
     * @type {Function}
     * @public
     */
    onPlay: _propTypes["default"].func,

    /**
     * Called when the user clicks the Previous button.
     *
     * @type {Function}
     * @public
     */
    onPrevious: _propTypes["default"].func,

    /**
     * Called when the user clicks the Loop button.
     *
     * @type {Function}
     * @public
     */
    onRepeat: _propTypes["default"].func,

    /**
     * Called when the user clicks the Shuffle button.
     *
     * @type {Function}
     * @public
     */
    onShuffle: _propTypes["default"].func,

    /**
     * `true` when the media is paused.
     *
     * @type {Boolean}
     * @default true
     * @public
     */
    paused: _propTypes["default"].bool,

    /**
     * A string which is sent to the `pause` icon of the player controls. This can be
     * anything that is accepted by [Icon]{@link agate/Icon.Icon}. This will be temporarily replaced by
     * the [playIcon]{@link agate/MediaPlayer.MediaControls.playIcon} when the
     * [paused]{@link agate/MediaPlayer.MediaControls.paused} boolean is `false`.
     *
     * @type {String}
     * @default 'pause'
     * @public
     */
    pauseIcon: _propTypes["default"].string,

    /**
     * A string which is sent to the `play` icon of the player controls. This can be
     * anything that is accepted by {@link agate/Icon.Icon}. This will be temporarily replaced by
     * the [pauseIcon]{@link agate/MediaPlayer.MediaControls.pauseIcon} when the
     * [paused]{@link agate/MediaPlayer.MediaControls.paused} boolean is `true`.
     *
     * @type {String}
     * @default 'play'
     * @public
     */
    playIcon: _propTypes["default"].string,

    /**
     * A string which is sent to the `previousTrack` icon of the player controls. This can be
     * anything that is accepted by {@link agate/Icon.Icon}.
     *
     * @type {String}
     * @default 'previoustrack'
     * @public
     */
    previousTrackIcon: _propTypes["default"].string,

    /**
     * The repeat mode of the media playlist.
     *
     * @type {('none'|'one'|'all')}
     * @default 'none'
     * @public
     */
    repeat: _propTypes["default"].oneOf(['none', 'one', 'all']),

    /**
     * A string which is sent to the `repeat` icon of the player controls. This can be
     * anything that is accepted by {@link agate/Icon.Icon}.
     *
     * @type {String}
     * @default 'repeat'
     * @public
     */
    repeatIcon: _propTypes["default"].string,

    /**
     * `true` when the media playlist is shuffled.
     *
     * @type {Boolean}
     * @public
     */
    shuffle: _propTypes["default"].bool,

    /**
     * A string which is sent to the `shuffle` icon of the player controls. This can be
     * anything that is accepted by {@link agate/Icon.Icon}.
     *
     * @type {String}
     * @default 'shuffle'
     * @public
     */
    shuffleIcon: _propTypes["default"].string
  },
  defaultProps: {
    menuIcon: 'menu',
    nextTrackIcon: 'nexttrack',
    pauseIcon: 'pause',
    paused: true,
    playIcon: 'play',
    previousTrackIcon: 'previoustrack',
    repeat: 'none',
    repeatIcon: 'repeat',
    shuffleIcon: 'shuffle'
  },
  styles: {
    css: _MediaControlsModule["default"],
    className: 'controlsFrame'
  },
  computed: {
    badge: function badge(_ref) {
      var repeat = _ref.repeat;
      return badges[repeat];
    }
  },
  render: function render(_ref2) {
    var badge = _ref2.badge,
        menuIcon = _ref2.menuIcon,
        nextTrackIcon = _ref2.nextTrackIcon,
        onNext = _ref2.onNext,
        onPause = _ref2.onPause,
        onPlay = _ref2.onPlay,
        onPrevious = _ref2.onPrevious,
        onRepeat = _ref2.onRepeat,
        onShuffle = _ref2.onShuffle,
        paused = _ref2.paused,
        pauseIcon = _ref2.pauseIcon,
        playIcon = _ref2.playIcon,
        previousTrackIcon = _ref2.previousTrackIcon,
        repeatIcon = _ref2.repeatIcon,
        shuffle = _ref2.shuffle,
        shuffleIcon = _ref2.shuffleIcon,
        rest = _objectWithoutProperties(_ref2, ["badge", "menuIcon", "nextTrackIcon", "onNext", "onPause", "onPlay", "onPrevious", "onRepeat", "onShuffle", "paused", "pauseIcon", "playIcon", "previousTrackIcon", "repeatIcon", "shuffle", "shuffleIcon"]);

    return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
          "aria-label": (0, _$L["default"])('Repeat'),
          backgroundOpacity: "transparent",
          badge: badge,
          css: _MediaControlsModule["default"],
          icon: repeatIcon,
          onClick: onRepeat,
          size: "large"
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
          "aria-label": (0, _$L["default"])('Shuffle'),
          backgroundOpacity: "transparent",
          className: shuffle ? _MediaControlsModule["default"].repeat : '',
          css: _MediaControlsModule["default"],
          icon: shuffleIcon,
          onClick: onShuffle,
          size: "large"
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
          "aria-label": (0, _$L["default"])('Previous'),
          backgroundOpacity: "transparent",
          css: _MediaControlsModule["default"],
          icon: previousTrackIcon,
          onClick: onPrevious,
          size: "large"
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
          "aria-label": paused ? (0, _$L["default"])('Play') : (0, _$L["default"])('Pause'),
          backgroundOpacity: "transparent",
          className: (0, _classnames["default"])(_MediaControlsModule["default"].playPauseButton, _SpotlightContainerDecorator.spotlightDefaultClass),
          css: _MediaControlsModule["default"],
          minWidth: false,
          onClick: paused ? onPlay : onPause,
          size: "large",
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon["default"], {
            css: _MediaControlsModule["default"],
            children: paused ? playIcon : pauseIcon
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
          "aria-label": (0, _$L["default"])('Next'),
          backgroundOpacity: "transparent",
          css: _MediaControlsModule["default"],
          icon: nextTrackIcon,
          onClick: onNext,
          size: "large"
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
          "aria-label": (0, _$L["default"])('Menu'),
          backgroundOpacity: "transparent",
          css: _MediaControlsModule["default"],
          icon: menuIcon,
          size: "large"
        })]
      })
    }));
  }
});
exports.MediaControls = MediaControls;
var _default = MediaControls;
exports["default"] = _default;