'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _keys = require('babel-runtime/core-js/object/keys');

var _keys2 = _interopRequireDefault(_keys);

var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');

var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

require('react-dates/initialize');

var _reactDates = require('react-dates');

var _Icon = require('../Icon');

var _Icon2 = _interopRequireDefault(_Icon);

var _DatePickerWrapper = require('./styles/DatePickerWrapper');

var _DatePickerWrapper2 = _interopRequireDefault(_DatePickerWrapper);

var _DateRangePicker = require('./DateRangePicker');

var _DateRangePicker2 = _interopRequireDefault(_DateRangePicker);

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

var _lodash = require('lodash');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

_moment2.default.updateLocale('en', {
  weekdaysMin: ['S', 'M', 'T', 'W', 'T', 'F', 'S']
});

/**
 * This is a styling wrapper around [react-dates](https://github.com/airbnb/react-dates).
 * Please see [here](https://github.com/airbnb/react-dates#singledatepicker) for prop types.
 *
 * The picker can be controlled by setting the props `date` and `onDateChange`.
 * `date` should be set to a moment object of the currently selected date,
 * while `onDateChange` should be a function that handles the date when it
 * changes.
 */
var DatePicker = function (_React$PureComponent) {
  (0, _inherits3.default)(DatePicker, _React$PureComponent);

  function DatePicker() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, DatePicker);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = DatePicker.__proto__ || (0, _getPrototypeOf2.default)(DatePicker)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
      focused: false
    }, _this.handleFocusChange = function (_ref2) {
      var focused = _ref2.focused;
      return _this.setState({ focused: focused });
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(DatePicker, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          Wrapper = _props.Wrapper,
          rest = (0, _objectWithoutProperties3.default)(_props, ['Wrapper']);
      var focused = this.state.focused;

      return _react2.default.createElement(
        Wrapper,
        {
          className: focused && 'focused',
          openDirection: this.props.openDirection,
          invalid: this.props.invalid,
          disabled: this.props.disabled
        },
        _react2.default.createElement(_reactDates.SingleDatePicker, (0, _extends3.default)({
          navPrev: _react2.default.createElement(_Icon2.default, { name: 'back' }),
          navNext: _react2.default.createElement(_Icon2.default, { name: 'forward' }),
          weekDayFormat: 'dd',
          daySize: 37,
          horizontalMargin: 0,
          numberOfMonths: 1,
          hideKeyboardShortcutsPanel: true,
          focused: focused,
          onFocusChange: this.handleFocusChange
        }, (0, _lodash.pick)(rest, (0, _keys2.default)(_reactDates.SingleDatePickerShape))))
      );
    }
  }]);
  return DatePicker;
}(_react2.default.PureComponent);

DatePicker.Range = _DateRangePicker2.default;
DatePicker.propTypes = (0, _extends3.default)({}, (0, _lodash.omit)(_reactDates.SingleDatePickerShape, ['onFocusChange']), {
  id: _propTypes2.default.string,
  /**
   * A component to wrap and control styles of the underlying react-dates DatePicker
   */
  Wrapper: _propTypes2.default.func,
  /**
   * Format to pass to moment to control the input's value
   */
  displayFormat: _propTypes2.default.string,
  /**
   * Set to true if the component's value is invalid
   */
  invalid: _propTypes2.default.bool,
  /**
   * Set to true if the component should be disabled.
   */
  disabled: _propTypes2.default.bool
});
DatePicker.defaultProps = {
  Wrapper: _DatePickerWrapper2.default,
  displayFormat: 'MMM DD YYYY',
  invalid: false,
  disabled: false
};
exports.default = DatePicker;