"use strict";

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

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

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

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

/**
 * A date selection component.
 *
 * This component is most often not used directly but may be composed within another component as it
 * is within [DatePicker]{@link agate/DatePicker.DatePicker}.
 *
 * @class DatePickerBase
 * @memberof agate/DatePicker
 * @ui
 * @public
 */
var 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, ["disabled", "day", "dayAriaLabel", "dayReverseTransition", "maxDays", "maxMonths", "maxYear", "minYear", "month", "monthAriaLabel", "onDateChange", "onMonthChange", "onYearChange", "onSpotlightDisappear", "order", "spotlightDisabled", "year", "yearAriaLabel"]);

    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), {}, {
      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;
      })
    }));
  }
});
exports.DatePickerBase = DatePickerBase;
var _default = DatePickerBase;
exports["default"] = _default;