"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.PickerBase = exports.Picker = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _Changeable = _interopRequireDefault(require("@enact/ui/Changeable"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clamp = _interopRequireDefault(require("ramda/src/clamp"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _react = require("react");
var _Picker = _interopRequireWildcard(require("../internal/Picker"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "max", "value"];
/**
 * A component for selecting values from a list of values.
 *
 * @example
 * <Picker>
 * 	{['A', 'B', 'C']}
 * </Picker>
 *
 * @module agate/Picker
 * @exports Picker
 * @exports PickerBase
 */
/**
 * The base `Picker` component.
 *
 * This version is not {@link spotlight/Spottable.Spottable|spottable}.
 *
 * @class PickerBase
 * @memberof agate/Picker
 * @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 PickerBase = exports.PickerBase = (0, _kind["default"])({
  name: 'Picker',
  propTypes: /** @lends agate/Picker.PickerBase.prototype */{
    /**
     * Picker value list.
     *
     * @type {Array}
     * @required
     * @public
     */
    children: _propTypes["default"].array.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}
     * @public
     */
    'aria-label': _propTypes["default"].string,
    /**
     * Sets the hint string read when focusing the decrement button.
     *
     * @default 'previous item'
     * @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 'next item'
     * @type {String}
     * @public
     */
    incrementAriaLabel: _propTypes["default"].string,
    /**
     * Disables transition animation.
     *
     * @type {Boolean}
     * @public
     */
    noAnimation: _propTypes["default"].bool,
    /**
     * Called when the `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']),
    /**
     * Index of the selected child.
     *
     * @type {Number}
     * @default 0
     * @public
     */
    value: _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
  },
  defaultProps: {
    orientation: 'vertical',
    value: 0
  },
  computed: {
    children: function children(_ref) {
      var _children = _ref.children;
      return _react.Children.map(_children, function (child) {
        return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker.PickerItem, {
          children: child
        });
      });
    },
    disabled: function disabled(_ref2) {
      var children = _ref2.children,
        _disabled = _ref2.disabled;
      return _react.Children.count(children) > 1 ? _disabled : true;
    },
    max: function max(_ref3) {
      var children = _ref3.children;
      return children && children.length ? children.length - 1 : 0;
    },
    value: function value(_ref4) {
      var _value = _ref4.value,
        children = _ref4.children;
      var max = children && children.length ? children.length - 1 : 0;
      return (0, _clamp["default"])(0, max, _value);
    }
  },
  render: function render(props) {
    var children = props.children,
      max = props.max,
      value = props.value,
      rest = _objectWithoutProperties(props, _excluded);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], _objectSpread(_objectSpread({}, rest), {}, {
      index: value,
      min: 0,
      max: max,
      value: value,
      children: children
    }));
  }
});

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

/**
 * A Picker component that allows selecting values from a list of values.
 *
 * By default, `Picker` 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 Picker
 * @memberof agate/Picker
 * @extends agate/Picker.PickerBase
 * @ui
 * @public
 */
var Picker = exports.Picker = PickerDecorator(PickerBase);

/**
 * Default index of the selected child.
 *
 * *Note*: Changing `defaultValue` after initial render has no effect.
 *
 * @name defaultValue
 * @memberof agate/Picker.Picker.prototype
 * @type {Number}
 * @public
 */
var _default = exports["default"] = Picker;