"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.DateComponentPickerBase = exports.DateComponentPicker = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _util = require("@enact/core/util");
var _Changeable = _interopRequireDefault(require("@enact/ui/Changeable"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = require("react");
var _Picker = _interopRequireWildcard(require("../Picker"));
var _DateComponentPickerModule = _interopRequireDefault(require("./DateComponentPicker.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["accessibilityHint", "aria-valuetext", "children", "max", "value", "wrap"];
/**
 * {@link agate/internal/DataComponentPicker.DateComponentPickerBase} allows the selection of one
 * part of the date or time using a {@link agate/internal/Picker.Picker}.
 *
 * @class DateComponentPickerBase
 * @memberof agate/internal/DateComponentPicker
 * @ui
 * @private
 */
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 DateComponentPickerBase = exports.DateComponentPickerBase = (0, _kind["default"])({
  name: 'DateComponentPicker',
  propTypes: /** @lends agate/internal/DateComponentPicker.DateComponentPickerBase.prototype */{
    /**
     * Display values representing the `value` to select
     *
     * @type {String[]}
     * @required
     * @public
     */
    children: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired,
    /**
     * The value of the date component
     *
     * @type {Number}
     * @required
     * @public
     */
    value: _propTypes["default"].number.isRequired,
    /**
     * Sets the hint string read when focusing the picker.
     *
     * @type {String}
     * @public
     */
    accessibilityHint: _propTypes["default"].string,
    /**
     * Overrides the `aria-valuetext` for the picker. By default, `aria-valuetext` is set
     * to the current selected child and accessibilityHint text.
     *
     * @type {String}
     * @public
     */
    'aria-valuetext': _propTypes["default"].string,
    /**
     * When `true`, allow the picker to continue from the opposite end of the list of options.
     *
     * @type {Boolean}
     * @public
     */
    wrap: _propTypes["default"].bool
  },
  styles: {
    css: _DateComponentPickerModule["default"],
    className: 'dateComponentPicker'
  },
  computed: {
    children: function children(_ref) {
      var _children = _ref.children;
      return (0, _util.mapAndFilterChildren)(_children, function (child) {
        return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker.PickerItem, {
          children: child
        });
      });
    },
    max: function max(_ref2) {
      var children = _ref2.children;
      return children ? _react.Children.count(children) - 1 : 0;
    }
  },
  render: function render(_ref3) {
    var accessibilityHint = _ref3.accessibilityHint,
      ariaValuetext = _ref3['aria-valuetext'],
      children = _ref3.children,
      max = _ref3.max,
      value = _ref3.value,
      wrap = _ref3.wrap,
      rest = _objectWithoutProperties(_ref3, _excluded);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], _objectSpread(_objectSpread({}, rest), {}, {
      accessibilityHint: accessibilityHint,
      "aria-valuetext": accessibilityHint == null ? ariaValuetext : null,
      css: _DateComponentPickerModule["default"],
      index: value,
      max: max,
      min: 0,
      orientation: "vertical",
      value: value,
      wrap: wrap,
      children: children
    }));
  }
});

/**
 * {@link agate/internal/DateComponentPickerBase.DateComponentPicker} allows the selection of one part of
 * the date (date, month, or year). It is a stateful component but allows updates by providing a new
 * `value` via props.
 *
 * @class DateComponentPicker
 * @memberof agate/internal/DateComponentPicker
 * @mixes ui/Changeable.Changeable
 * @ui
 * @private
 */
var DateComponentPicker = exports.DateComponentPicker = (0, _Changeable["default"])(DateComponentPickerBase);
var _default = exports["default"] = DateComponentPicker;