import _pt from "prop-types";
var _excluded = ["id", "errorId"];

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

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

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

import DateInput from './DateInput';
import React from 'react';
import defaultDateFormatter from './defaultDateFormatter';
import { FormLabel, useFormLabel } from '../FormLabel';
import { t } from '../i18n';
export function MultiInputDateField(props) {
  var _useFormLabel = useFormLabel(_objectSpread(_objectSpread({
    label: t('dateField.label'),
    hint: t('dateField.hint'),
    dayName: 'day',
    monthName: 'month',
    yearName: 'year',
    dateFormatter: defaultDateFormatter
  }, props), {}, {
    labelComponent: 'legend',
    wrapperIsFieldset: true
  })),
      labelProps = _useFormLabel.labelProps,
      fieldProps = _useFormLabel.fieldProps,
      wrapperProps = _useFormLabel.wrapperProps,
      bottomError = _useFormLabel.bottomError; // Throw away the properties we don't need by destructuring


  var id = fieldProps.id,
      errorId = fieldProps.errorId,
      inputProps = _objectWithoutProperties(fieldProps, _excluded);

  return /*#__PURE__*/React.createElement("fieldset", wrapperProps, /*#__PURE__*/React.createElement(FormLabel, labelProps), /*#__PURE__*/React.createElement(DateInput, _extends({}, inputProps, {
    labelId: labelProps.id
  })), bottomError);
}
MultiInputDateField.propTypes = {
  /**
     * Adds `autocomplete` attributes `bday-day`, `bday-month` and `bday-year` to the corresponding `<MultiInputDateField>` inputs
     */
  autoComplete: _pt.bool,

  /**
     * Optional method to format the `input` field values. If this
     * method is provided, the returned value will be passed as a second argument
     * to the `onBlur` and `onChange` callbacks. This method receives an object as
     * its only argument, in the shape of: `{ day, month, year }`
     *
     * By default `dateFormatter` will be set to the `defaultDateFormatter` function, which prevents days/months more than 2 digits & years more than 4 digits.
     */
  dateFormatter: _pt.func,

  /**
     * The primary label, rendered above the individual month/day/year fields
     */
  label: _pt.node,

  /**
     * A unique ID to be used for the MultiInputDateField label. If one isn't provided, a unique ID will be generated.
     */
  labelId: _pt.string,

  /**
     * Text showing the requirement ("Required", "Optional", etc.). See [Required and Optional Fields]({{root}}/guidelines/forms/#required-and-optional-fields).
     */
  requirementLabel: _pt.node,

  /**
     * Called anytime any date input is blurred
     */
  onBlur: _pt.func,

  /**
     * Called when any date input is blurred and the focus does not land on one
     * of the other date inputs inside this component (i.e., when the whole
     * component loses focus)
     */
  onComponentBlur: _pt.func,

  /**
     * Called anytime any date input is changed
     */
  onChange: _pt.func,

  /**
     * Label for the day field
     */
  dayLabel: _pt.node,

  /**
     * `name` for the day `input` field
     */
  dayName: _pt.string,

  /**
     * Initial value for the day `input` field. Use this for an uncontrolled
     * component; otherwise, use the `dayValue` property.
     */
  dayDefaultValue: _pt.oneOfType([_pt.string, _pt.number]),

  /**
     * Access a reference to the day `input`
     */
  dayFieldRef: _pt.func,

  /**
     * Apply error styling to the day `input`
     */
  dayInvalid: _pt.bool,

  /**
     * Sets the day input's `value`. Use this in combination with `onChange`
     * for a controlled component; otherwise, set `dayDefaultValue`.
     */
  dayValue: _pt.oneOfType([_pt.string, _pt.number]),

  /**
     * Label for the month field
     */
  monthLabel: _pt.node,

  /**
     * `name` for the month `input` field
     */
  monthName: _pt.string,

  /**
     * Initial value for the month `input` field. Use this for an uncontrolled
     * component; otherwise, use the `monthValue` property.
     */
  monthDefaultValue: _pt.oneOfType([_pt.string, _pt.number]),

  /**
     * Access a reference to the month `input`
     */
  monthFieldRef: _pt.func,

  /**
     * Apply error styling to the month `input`
     */
  monthInvalid: _pt.bool,

  /**
     * Sets the month input's `value`. Use this in combination with `onChange`
     * for a controlled component; otherwise, set `monthDefaultValue`.
     */
  monthValue: _pt.oneOfType([_pt.string, _pt.number]),

  /**
     * Initial value for the year `input` field. Use this for an uncontrolled
     * component; otherwise, use the `yearValue` property.
     */
  yearDefaultValue: _pt.oneOfType([_pt.string, _pt.number]),

  /**
     * Access a reference to the year `input`
     */
  yearFieldRef: _pt.func,

  /**
     * Apply error styling to the year `input`
     */
  yearInvalid: _pt.bool,

  /**
     * Label for the year `input` field
     */
  yearLabel: _pt.node,

  /**
     * `name` for the year field
     */
  yearName: _pt.string
};
export default MultiInputDateField;