"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.SliderButtonDecorator = exports.SliderButtonBase = exports.SliderButton = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));
var _Changeable = _interopRequireDefault(require("@enact/ui/Changeable"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _Layout = require("@enact/ui/Layout");
var _Slider = _interopRequireDefault(require("@enact/ui/Slider"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _SliderButtonBehaviorDecorator = _interopRequireDefault(require("./SliderButtonBehaviorDecorator"));
var _SliderButtonModule = _interopRequireDefault(require("./SliderButton.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "css", "values"],
  _excluded2 = ["css", "children", "max"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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; }
function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
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); } /**
 * Provides an Agate-themed button group.
 *
 * @example
 * <SliderButton>{['Light Speed', 'Ridiculous Speed', 'Ludicrous Speed']}</SliderButton>
 *
 * @module agate/SliderButton
 * @exports SliderButton
 * @exports SliderButtonBase
 * @exports SliderButtonDecorator
 */ /**
 * Renders the slider knob.
 *
 * @class SliderKnob
 * @memberof agate/SliderButton
 * @ui
 * @private
 */
var SliderKnob = (0, _kind["default"])({
  name: 'SliderKnob',
  propTypes: /** @lends agate/SliderButton.SliderKnob.prototype */{
    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,
    /**
     * Value of SliderButton.
     *
     * @type {Number}
     * @public
     */
    value: _propTypes["default"].number
  },
  styles: {
    css: _SliderButtonModule["default"],
    className: 'knob'
  },
  computed: {
    style: function style(_ref) {
      var _style = _ref.style,
        value = _ref.value;
      // const factor = Math.abs((value - Math.round(value))) / 4;
      return _objectSpread({
        '--knob-value': value
      }, _style);
    }
  },
  render: function render(_ref2) {
    var rest = Object.assign({}, (_objectDestructuringEmpty(_ref2), _ref2));
    delete rest.value;
    // eslint-disable-next-line enact/prop-types
    delete rest.tooltipComponent;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, rest));
  }
});

/**
 * Renders the slider progress.
 *
 * @class SliderProgress
 * @memberof agate/SliderButton
 * @ui
 * @private
 */
var SliderProgress = (0, _kind["default"])({
  name: 'SliderProgress',
  propTypes: /** @lends agate/SliderButton.SliderProgress.prototype */{
    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,
    /**
     * Value of SliderProgress.
     *
     * @type {String[]}
     * @public
     */
    values: _propTypes["default"].arrayOf(_propTypes["default"].string)
  },
  styles: {
    css: _SliderButtonModule["default"],
    className: 'track'
  },
  render: function render(_ref3) {
    var children = _ref3.children,
      css = _ref3.css,
      values = _ref3.values,
      rest = _objectWithoutProperties(_ref3, _excluded);
    // eslint-disable-next-line enact/prop-types
    delete rest.progressAnchor;
    // eslint-disable-next-line enact/prop-types
    delete rest.backgroundProgress;
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Layout.Row, _objectSpread(_objectSpread({}, rest), {}, {
      align: "center",
      children: [children, values ? values.map(function (child) {
        return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
          className: css.client,
          children: child
        }, child);
      }) : null]
    }));
  }
});

/**
 * Renders the base level DOM structure of the component.
 *
 * @class SliderButtonBase
 * @memberof agate/SliderButton
 * @extends ui/Slider.Slider
 * @ui
 * @public
 */
var SliderButtonBase = exports.SliderButtonBase = (0, _kind["default"])({
  name: 'SliderButton',
  propTypes: /** @lends agate/SliderButton.SliderButtonBase.prototype */{
    /**
     * The value options of SliderButtonBase.
     *
     * @type {Array}
     * @required
     * @public
     */
    children: _propTypes["default"].array.isRequired,
    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object
  },
  styles: {
    css: _SliderButtonModule["default"],
    className: 'sliderButton',
    publicClassNames: true
  },
  computed: {
    max: function max(_ref4) {
      var children = _ref4.children;
      return children && children.length ? children.length - 1 : 0;
    },
    style: function style(_ref5) {
      var children = _ref5.children,
        _style2 = _ref5.style;
      return _objectSpread({
        '--sliderbutton-item-count': children && children.length || 0
      }, _style2);
    }
  },
  render: function render(_ref6) {
    var css = _ref6.css,
      children = _ref6.children,
      max = _ref6.max,
      rest = _objectWithoutProperties(_ref6, _excluded2);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Slider["default"], _objectSpread(_objectSpread({}, rest), {}, {
      css: css,
      knobComponent: /*#__PURE__*/(0, _jsxRuntime.jsx)(SliderKnob, {
        css: css
      }),
      progressBarComponent: /*#__PURE__*/(0, _jsxRuntime.jsx)(SliderProgress, {
        values: children
      }),
      step: 1,
      min: 0,
      max: max
    }));
  }
});

/**
 * Agate specific behaviors to apply to {@link agate/SliderButton.SliderButtonBase|SliderButton}.
 *
 * @hoc
 * @memberof agate/SliderButton
 * @mixes ui/Changeable.Changeable
 * @mixes spotlight/Spottable.Spottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */
var SliderButtonDecorator = exports.SliderButtonDecorator = (0, _compose["default"])(_Pure["default"], _Changeable["default"], _SliderButtonBehaviorDecorator["default"], _Spottable["default"], _Skinnable["default"]);

/**
 * Renders a slider that appears as a series of connected buttons.
 *
 * @class SliderButton
 * @memberof agate/SliderButton
 * @extends agate/SliderButton.SliderButtonBase
 * @mixes agate/SliderButton.SliderButtonDecorator
 * @ui
 * @public
 */
var SliderButton = exports.SliderButton = SliderButtonDecorator(SliderButtonBase);
var _default = exports["default"] = SliderButton;