"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.DatePickerBase = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _$L = _interopRequireDefault(require("../internal/$L"));
var _DateComponentPicker = require("../internal/DateComponentPicker");
var _DateTime = _interopRequireDefault(require("../internal/DateTime"));
var _DatePickerModule = _interopRequireDefault(require("./DatePicker.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["disabled", "day", "dayAriaLabel", "dayReverseTransition", "maxDays", "maxMonths", "maxYear", "minYear", "month", "monthAriaLabel", "onDateChange", "onMonthChange", "onYearChange", "onSpotlightDisappear", "order", "spotlightDisabled", "year", "yearAriaLabel"];
/**
 * A date selection component.
 *
 * This component is most often not used directly but may be composed within another component as it
 * is within {@link agate/DatePicker.DatePicker|DatePicker}.
 *
 * @class DatePickerBase
 * @memberof agate/DatePicker
 * @ui
 * @public
 */
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 DatePickerBase = exports.DatePickerBase = (0, _kind["default"])({
  name: 'DatePickerBase',
  propTypes: /** @lends agate/DatePicker.DatePickerBase.prototype */{
    /**
     * The `day` component of the Date.
     *
     * The value should be a number between 1 and `maxDays`.
     *
     * @type {Number}
     * @required
     * @public
     */
    day: _propTypes["default"].number.isRequired,
    /**
     * The number of days in the month.
     *
     * @type {Number}
     * @required
     * @public
     */
    maxDays: _propTypes["default"].number.isRequired,
    /**
     * The number of months in the year.
     *
     * @type {Number}
     * @required
     * @public
     */
    maxMonths: _propTypes["default"].number.isRequired,
    /**
     * The `month` component of the Date.
     *
     * The value should be a number between 1 and `maxMonths`.
     *
     * @type {Number}
     * @required
     * @public
     */
    month: _propTypes["default"].number.isRequired,
    /**
     * The order in which the component pickers are displayed.
     *
     * The value should be an array of 3 strings containing one of `'m'`, `'d'`, and `'y'`.
     *
     * @type {String[]}
     * @required
     * @public
     */
    order: _propTypes["default"].arrayOf(_propTypes["default"].oneOf(['m', 'd', 'y'])).isRequired,
    /**
     * The `year` component of the Date.
     *
     * @type {Number}
     * @required
     * @public
     */
    year: _propTypes["default"].number.isRequired,
    /**
     * The "aria-label" for the day picker.
     *
     * If not specified, the "aria-label" for the day picker will be
     * a combination of the current value and 'day change a value with up down button'.
     *
     * @type {String}
     * @public
     */
    dayAriaLabel: _propTypes["default"].string,
    /**
     * When it's `true`, it changes the direction of the transition animation for the day.
     *
     * @type {Boolean}
     * @public
     */
    dayReverseTransition: _propTypes["default"].bool,
    /**
     * Disables the `DatePicker`.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    disabled: _propTypes["default"].bool,
    /**
     * The maximum selectable `year` value.
     *
     * @type {Number}
     * @default 2099
     * @public
     */
    maxYear: _propTypes["default"].number,
    /**
     * The minimum selectable `year` value.
     *
     * @type {Number}
     * @default 1900
     * @public
     */
    minYear: _propTypes["default"].number,
    /**
     * The "aria-label" for the month picker.
     *
     * If not specified, the "aria-label" for the month picker will be
     * a combination of the current value and 'month change a value with up down button'.
     *
     * @type {String}
     * @public
     */
    monthAriaLabel: _propTypes["default"].string,
    /**
     * Called when the `date` component of the Date changes.
     *
     * @type {Function}
     * @public
     */
    onDateChange: _propTypes["default"].func,
    /**
     * Called when the `month` component of the Date changes.
     *
     * @type {Function}
     * @public
     */
    onMonthChange: _propTypes["default"].func,
    /**
     * Called when the component is removed when it had focus.
     *
     * @type {Function}
     * @param {Object} event
     * @public
     */
    onSpotlightDisappear: _propTypes["default"].func,
    /**
     * Called when the `year` component of the Date changes.
     *
     * @type {Function}
     * @public
     */
    onYearChange: _propTypes["default"].func,
    /**
     * Indicates the content's text direction is right-to-left.
     *
     * @type {Boolean}
     * @private
     */
    rtl: _propTypes["default"].bool,
    /**
     * Disables 5-way spotlight from navigating into the component.
     *
     * @type {Boolean}
     * @public
     */
    spotlightDisabled: _propTypes["default"].bool,
    /**
     * The "aria-label" for the year picker.
     *
     * If not specified, the "aria-label" for the year picker will be
     * a combination of the current value and 'year change a value with up down button'.
     *
     * @type {String}
     * @public
     */
    yearAriaLabel: _propTypes["default"].string
  },
  defaultProps: {
    maxYear: 2099,
    minYear: 1900,
    disabled: false
  },
  styles: {
    css: _DatePickerModule["default"],
    className: 'datePicker',
    publicClassNames: true
  },
  render: function render(_ref) {
    var disabled = _ref.disabled,
      day = _ref.day,
      dayAriaLabel = _ref.dayAriaLabel,
      dayReverseTransition = _ref.dayReverseTransition,
      maxDays = _ref.maxDays,
      maxMonths = _ref.maxMonths,
      maxYear = _ref.maxYear,
      minYear = _ref.minYear,
      month = _ref.month,
      monthAriaLabel = _ref.monthAriaLabel,
      onDateChange = _ref.onDateChange,
      onMonthChange = _ref.onMonthChange,
      onYearChange = _ref.onYearChange,
      onSpotlightDisappear = _ref.onSpotlightDisappear,
      order = _ref.order,
      spotlightDisabled = _ref.spotlightDisabled,
      year = _ref.year,
      yearAriaLabel = _ref.yearAriaLabel,
      rest = _objectWithoutProperties(_ref, _excluded);
    var dayAccessibilityHint = (0, _$L["default"])('day');
    var monthAccessibilityHint = (0, _$L["default"])('month');
    var yearAccessibilityHint = (0, _$L["default"])('year');
    delete rest.rtl;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateTime["default"], _objectSpread(_objectSpread({}, rest), {}, {
      disabled: disabled,
      children: order && order.map(function (picker) {
        switch (picker) {
          case 'd':
            return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateComponentPicker.DateComponentRangePicker, {
              accessibilityHint: dayAccessibilityHint,
              "aria-label": dayAriaLabel,
              className: _DatePickerModule["default"].day,
              disabled: disabled,
              max: maxDays,
              min: 1,
              onChange: onDateChange,
              onSpotlightDisappear: onSpotlightDisappear,
              reverseTransition: dayReverseTransition,
              spotlightDisabled: spotlightDisabled,
              value: day,
              width: 2,
              wrap: true
            }, "day-picker");
          case 'm':
            return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateComponentPicker.DateComponentRangePicker, {
              accessibilityHint: monthAccessibilityHint,
              "aria-label": monthAriaLabel,
              className: _DatePickerModule["default"].month,
              disabled: disabled,
              max: maxMonths,
              min: 1,
              onChange: onMonthChange,
              onSpotlightDisappear: onSpotlightDisappear,
              spotlightDisabled: spotlightDisabled,
              value: month,
              width: 2,
              wrap: true
            }, "month-picker");
          case 'y':
            return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateComponentPicker.DateComponentRangePicker, {
              accessibilityHint: yearAccessibilityHint,
              "aria-label": yearAriaLabel,
              className: _DatePickerModule["default"].year,
              disabled: disabled,
              max: maxYear,
              min: minYear,
              onChange: onYearChange,
              onSpotlightDisappear: onSpotlightDisappear,
              spotlightDisabled: spotlightDisabled,
              value: year,
              width: 4,
              wrap: true
            }, "year-picker");
        }
        return null;
      })
    }));
  }
});
var _default = exports["default"] = DatePickerBase;