"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.MediaControls = void 0;
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 _MediaControlsModule = _interopRequireDefault(require("./MediaControls.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["badge", "disabled", "menuIcon", "nextTrackIcon", "onNext", "onPause", "onPlay", "onPrevious", "onRepeat", "onShuffle", "paused", "pauseIcon", "playIcon", "previousTrackIcon", "repeatIcon", "shuffle", "shuffleIcon", "type"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
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 = exports.MediaControls = (0, _kind["default"])({
  name: 'MediaControls',
  propTypes: /** @lends agate/MediaPlayer.MediaControls.prototype */{
    /**
     * Disables MediaControls and makes it non-interactive.
     *
     * @type {Boolean}
     * @public
     */
    disabled: _propTypes["default"].bool,
    /**
     * 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 {@link agate/Icon.Icon|Icon}. This will be temporarily replaced by
     * the {@link agate/MediaPlayer.MediaControls.playIcon|playIcon} when the
     * {@link agate/MediaPlayer.MediaControls.paused|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 {@link agate/MediaPlayer.MediaControls.pauseIcon|pauseIcon} when the
     * {@link agate/MediaPlayer.MediaControls.paused|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,
    /**
     * Specifies what kind of layout the MediaPlayer should have.
     *
     * @type {('full'|'tiny')}
     * @default 'full'
     * @public
     */
    type: _propTypes["default"].oneOf(['full', 'tiny'])
  },
  defaultProps: {
    menuIcon: 'menu',
    nextTrackIcon: 'nexttrack',
    pauseIcon: 'pause',
    paused: true,
    playIcon: 'play',
    previousTrackIcon: 'previoustrack',
    repeat: 'none',
    repeatIcon: 'repeat',
    shuffleIcon: 'shuffle',
    type: 'full'
  },
  styles: {
    css: _MediaControlsModule["default"],
    className: 'controlsFrame'
  },
  computed: {
    badge: function badge(_ref) {
      var repeat = _ref.repeat;
      return badges[repeat];
    },
    className: function className(_ref2) {
      var type = _ref2.type,
        styler = _ref2.styler;
      return styler.append(type);
    }
  },
  render: function render(_ref3) {
    var badge = _ref3.badge,
      disabled = _ref3.disabled,
      menuIcon = _ref3.menuIcon,
      nextTrackIcon = _ref3.nextTrackIcon,
      onNext = _ref3.onNext,
      onPause = _ref3.onPause,
      onPlay = _ref3.onPlay,
      onPrevious = _ref3.onPrevious,
      onRepeat = _ref3.onRepeat,
      onShuffle = _ref3.onShuffle,
      paused = _ref3.paused,
      pauseIcon = _ref3.pauseIcon,
      playIcon = _ref3.playIcon,
      previousTrackIcon = _ref3.previousTrackIcon,
      repeatIcon = _ref3.repeatIcon,
      shuffle = _ref3.shuffle,
      shuffleIcon = _ref3.shuffleIcon,
      type = _ref3.type,
      rest = _objectWithoutProperties(_ref3, _excluded);
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, _objectSpread(_objectSpread({}, rest), {}, {
      children: [type === 'full' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        "aria-label": (0, _$L["default"])('Repeat'),
        backgroundOpacity: "transparent",
        badge: badge,
        css: _MediaControlsModule["default"],
        disabled: disabled,
        icon: repeatIcon,
        onClick: onRepeat
      }) : null, type === 'full' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        "aria-label": (0, _$L["default"])('Shuffle'),
        backgroundOpacity: "transparent",
        className: shuffle ? _MediaControlsModule["default"].repeat : '',
        css: _MediaControlsModule["default"],
        disabled: disabled,
        icon: shuffleIcon,
        onClick: onShuffle
      }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        "aria-label": (0, _$L["default"])('Previous'),
        backgroundOpacity: "transparent",
        css: _MediaControlsModule["default"],
        disabled: disabled,
        icon: previousTrackIcon,
        onClick: onPrevious
      }), /*#__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"],
        disabled: disabled,
        icon: paused ? playIcon : pauseIcon,
        minWidth: false,
        onClick: paused ? onPlay : onPause
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        "aria-label": (0, _$L["default"])('Next'),
        backgroundOpacity: "transparent",
        css: _MediaControlsModule["default"],
        disabled: disabled,
        icon: nextTrackIcon,
        onClick: onNext
      }), type === 'full' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        "aria-label": (0, _$L["default"])('Menu'),
        backgroundOpacity: "transparent",
        css: _MediaControlsModule["default"],
        disabled: disabled,
        icon: menuIcon
      }) : null]
    }));
  }
});
var _default = exports["default"] = MediaControls;