"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.RangePickerDecorator = exports.RangePickerBase = exports.RangePicker = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _util = require("@enact/core/util");
var _Changeable = _interopRequireDefault(require("@enact/ui/Changeable"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _Picker = _interopRequireWildcard(require("../internal/Picker"));
var _PickerItem = _interopRequireDefault(require("../internal/Picker/PickerItem"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["value"];
/**
 * A component for selecting a number from a range of numbers.
 *
 * @example
 * <RangePicker defaultValue={70} min={0} max={100} />
 *
 * @module agate/RangePicker
 * @exports RangePicker
 * @exports RangePickerBase
 * @exports RangePickerDecorator
 */
/**
 * RangePicker base component.
 *
 * @class RangePickerBase
 * @memberof agate/RangePicker
 * @ui
 * @public
 */
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
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 RangePickerBase = exports.RangePickerBase = (0, _kind["default"])({
  name: 'RangePicker',
  propTypes: /** @lends agate/RangePicker.RangePickerBase.prototype */{
    /**
     * The maximum value selectable by the picker (inclusive).
     *
     * The range between `min` and `max` should be evenly divisible by
     * {@link agate/RangePicker.RangePickerBase.step|step}.
     *
     * @type {Number}
     * @required
     * @public
     */
    max: _propTypes["default"].number.isRequired,
    /**
     * The minimum value selectable by the picker (inclusive).
     *
     * The range between `min` and `max` should be evenly divisible by
     * {@link agate/RangePicker.RangePickerBase.step|step}.
     *
     * @type {Number}
     * @required
     * @public
     */
    min: _propTypes["default"].number.isRequired,
    /**
     * Current value.
     *
     * @type {Number}
     * @required
     * @public
     */
    value: _propTypes["default"].number.isRequired,
    /**
     * Overrides the `aria-valuetext` for the picker. By default, `aria-valuetext` is set
     * to the current value. This should only be used when the parent controls the value of
     * the picker directly through the props.
     *
     * @type {String|Number}
     * @public
     */
    'aria-valuetext': _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
    /**
     * Children from which to pick.
     *
     * @type {Node}
     * @public
     */
    children: _propTypes["default"].node,
    /**
     * Class name for component.
     *
     * @type {String}
     * @public
     */
    className: _propTypes["default"].string,
    /**
     * Sets the hint string read when focusing the decrement button.
     *
     * @default 'decrease the value'
     * @type {String}
     * @public
     */
    decrementAriaLabel: _propTypes["default"].string,
    /**
     * Disables the picker.
     *
     * @type {Boolean}
     * @public
     */
    disabled: _propTypes["default"].bool,
    /**
     * Sets the hint string read when focusing the increment button.
     *
     * @default 'increase the value'
     * @type {String}
     * @public
     */
    incrementAriaLabel: _propTypes["default"].string,
    /**
     * Disables animation.
     *
     * By default, the picker will animate transitions between items, provided a `width` is
     * defined.
     *
     * @type {Boolean}
     * @public
     */
    noAnimation: _propTypes["default"].bool,
    /**
     * Called when `value` changes.
     *
     * @type {Function}
     * @public
     */
    onChange: _propTypes["default"].func,
    /**
     * Orientation of the picker.
     *
     * Controls whether the buttons are arranged horizontally or vertically around the value.
     *
     * * Values: `'horizontal'`, `'vertical'`
     *
     * @type {String}
     * @default 'vertical'
     * @public
     */
    orientation: _propTypes["default"].oneOf(['horizontal', 'vertical']),
    /**
     * The smallest value change allowed for the picker.
     *
     * For example, a step of `2` would cause the picker to increment from 0 to 2 to 4, etc.
     * It must evenly divide into the range designated by `min` and `max`.
     *
     * @type {Number}
     * @default 1
     * @public
     */
    step: _propTypes["default"].number,
    /**
     * Allows picker to continue from the start of the list after it reaches the end and
     * vice-versa.
     *
     * @type {Boolean}
     * @public
     */
    wrap: _propTypes["default"].bool
  },
  computed: {
    disabled: function disabled(_ref) {
      var _disabled = _ref.disabled,
        max = _ref.max,
        min = _ref.min;
      return min >= max ? true : _disabled;
    },
    value: function value(_ref2) {
      var min = _ref2.min,
        max = _ref2.max,
        _value = _ref2.value;
      return (0, _util.clamp)(min, max, _value);
    }
  },
  render: function render(_ref3) {
    var value = _ref3.value,
      rest = _objectWithoutProperties(_ref3, _excluded);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], _objectSpread(_objectSpread({}, rest), {}, {
      index: 0,
      type: "number",
      value: value,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickerItem["default"], {
        marqueeDisabled: true,
        style: {
          direction: 'ltr'
        },
        children: value
      }, value)
    }));
  }
});

/**
 * Applies Agate specific behaviors to {@link agate/RangePicker.RangePickerBase|RangePickerBase} components.
 *
 * @hoc
 * @memberof agate/RangePicker
 * @mixes ui/Changeable.Changeable
 * @public
 */
var RangePickerDecorator = exports.RangePickerDecorator = (0, _compose["default"])(_Pure["default"], _Changeable["default"], _Picker.ChangeAdapter);

/**
 * A component that lets the user select a number from a range of numbers.
 *
 * By default, `RangePicker` maintains the state of its `value` property. Supply the `defaultValue`
 * property to control its initial value. If you wish to directly control updates to the component,
 * supply a value to `value` at creation time and update it in response to `onChange` events.
 *
 * @class RangePicker
 * @memberof agate/RangePicker
 * @extends agate/RangePicker.RangePickerBase
 * @mixes agate/RangePicker.RangePickerDecorator
 * @ui
 * @public
 */
var RangePicker = exports.RangePicker = RangePickerDecorator(RangePickerBase);

/**
 * Default value
 *
 * @name defaultValue
 * @memberof agate/RangePicker.RangePicker.prototype
 * @type {Number}
 * @public
 */
var _default = exports["default"] = RangePicker;