text: import _pt from "prop-types";
  
  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 _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 _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 React from 'react';
  import uuid from 'uuid/v4';
  import FormField, { partitionFieldProps } from '../FormField';
  import DateTime from '../DateTime';
  import createDateTime from '../../utils/createDateTime';
  import { mdyCalendarBundle } from '../../messages';
  import PrivatePickerInput from './Input';
  
  /** A controlled input field that opens a date picker. */
  export default class DatePickerInput extends React.Component {
    constructor() {
      super(...arguments);
  
      _defineProperty(this, "state", {
        id: uuid()
      });
  
      _defineProperty(this, "handleChange", event => {
        const {
          value
        } = event.currentTarget;
        const date = this.parseDate(value);
        this.props.onChange(value, date || null, event);
      });
  
      _defineProperty(this, "handleDayChange", day => {
        // Day is undefined when the user is typing into the field
        // manually. We want to avoid overriding `onChange`.
        if (!day) {
          return;
        } // Update the parent form with the selected value.
        // We also don't have a real event object, so fake it.
  
  
        this.props.onChange(this.formatDate(day), day, // @ts-ignore
        {});
      });
  
      _defineProperty(this, "parseDate", (value, format, locale) => {
        try {
          return createDateTime(value, {
            sourceFormat: format || this.getFormat(),
            locale: locale || this.props.locale
          }).toJSDate();
        } catch (error) {
          return undefined;
        }
      });
  
      _defineProperty(this, "formatDate", (date, baseFormat, locale) => {
        const format = baseFormat || this.getFormat();
        return DateTime.format({
          at: date,
          format,
          sourceFormat: format,
          locale: locale || this.props.locale,
          noTime: true,
          noTimezone: true
        });
      });
    }
  
    getFormat() {
      return this.props.format || mdyCalendarBundle.get(this.props.locale);
    }
  
    render() {
      const {
        fieldProps,
        inputProps
      } = partitionFieldProps(this.props);
  
      const {
        clearOnDayClick,
        datePickerProps,
        dropdownProps,
        hideOnDayClick,
        locale,
        onHidePicker
      } = inputProps,
            restProps = _objectWithoutPropertiesLoose(inputProps, ["clearOnDayClick", "datePickerProps", "dropdownProps", "hideOnDayClick", "locale", "onHidePicker"]);
  
      const {
        id
      } = this.state;
      const format = this.getFormat();
  
      const pickerProps = _extends({}, datePickerProps, {
        locale
      });
  
      return React.createElement(FormField, _extends({}, fieldProps, {
        id: id
      }), React.createElement(PrivatePickerInput, {
        keepFocus: true,
        value: restProps.value,
        dayPickerProps: pickerProps,
        dropdownProps: dropdownProps,
        inputProps: _extends({}, restProps, {
          id,
          onChange: this.handleChange
        }),
        format: format,
        clickUnselectsDay: clearOnDayClick,
        hideOnDayClick: hideOnDayClick,
        placeholder: restProps.placeholder || format.toUpperCase(),
        parseDate: this.parseDate,
        formatDate: this.formatDate,
        onDayPickerHide: onHidePicker,
        onDayChange: this.handleDayChange
      }));
    }
  
  }
  
  _defineProperty(DatePickerInput, "propTypes", {
    datePickerProps: _pt.any,
    dropdownProps: _pt.any,
    format: _pt.string,
    locale: _pt.any,
    onChange: _pt.func.isRequired,
    value: _pt.oneOfType([_pt.string, _pt.instanceOf(Date)])
  });
  
  _defineProperty(DatePickerInput, "defaultProps", {
    hideOnDayClick: false
  });