"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DateComponentPickerBase = exports.DateComponentPicker = 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 _propTypes = _interopRequireDefault(require("prop-types"));

var _react = require("react");

var _Picker = _interopRequireWildcard(require("../Picker"));

var _DateComponentPickerModule = _interopRequireDefault(require("./DateComponentPicker.module.css"));

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

/**
 * {@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
 */
var 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, ["accessibilityHint", "aria-valuetext", "children", "max", "value", "wrap"]);

    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
 */

exports.DateComponentPickerBase = DateComponentPickerBase;
var DateComponentPicker = (0, _Changeable["default"])(DateComponentPickerBase);
exports.DateComponentPicker = DateComponentPicker;
var _default = DateComponentPicker;
exports["default"] = _default;