"use strict";

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

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

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"));

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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; }

/**
 * RangePicker base component.
 *
 * @class RangePickerBase
 * @memberof agate/RangePicker
 * @ui
 * @public
 */
var 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
     * [step]{@link agate/RangePicker.RangePickerBase.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
     * [step]{@link agate/RangePicker.RangePickerBase.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, ["value"]);

    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 [RangePickerBase]{@link agate/RangePicker.RangePickerBase} components.
 *
 * @hoc
 * @memberof agate/RangePicker
 * @mixes ui/Changeable.Changeable
 * @public
 */

exports.RangePickerBase = RangePickerBase;
var 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
 */

exports.RangePickerDecorator = RangePickerDecorator;
var RangePicker = RangePickerDecorator(RangePickerBase);
/**
 * Default value
 *
 * @name defaultValue
 * @memberof agate/RangePicker.RangePicker.prototype
 * @type {Number}
 * @public
 */

exports.RangePicker = RangePicker;
var _default = RangePicker;
exports["default"] = _default;