'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 _DateRangePickerWrapper = require('./styles/DateRangePickerWrapper');

var _DateRangePickerWrapper2 = _interopRequireDefault(_DateRangePickerWrapper);

var _DateRangePickerLineSeparator = require('./styles/DateRangePickerLineSeparator');

var _DateRangePickerLineSeparator2 = _interopRequireDefault(_DateRangePickerLineSeparator);

var _lodash = require('lodash');

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

/**
 * 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 `startDate`, `endDate` and `onDatesChange`.
 * `startDate` and `endDate` should be set to moment objects of the currently selected dates,
 * while `onDatesChange` should be a function that handles the dates when they
 * change.
 *
 * **NOTE: ** The range picker uses `onDatesChange` not `onDateChange`.
 */
var DateRangePicker = function (_React$PureComponent) {
  (0, _inherits3.default)(DateRangePicker, _React$PureComponent);

  function DateRangePicker() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = DateRangePicker.__proto__ || (0, _getPrototypeOf2.default)(DateRangePicker)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
      internalFocusedInput: null
    }, _this.handleFocusChange = function (internalFocusedInput) {
      return _this.setState({ internalFocusedInput: internalFocusedInput });
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

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

      return _react2.default.createElement(
        Wrapper,
        {
          className: this.focusedInput && 'focused-' + this.focusedInput,
          openDirection: this.props.openDirection,
          disabled: this.props.disabled,
          invalid: this.props.invalid
        },
        _react2.default.createElement(_reactDates.DateRangePicker, (0, _extends3.default)({
          navPrev: _react2.default.createElement(_Icon2.default, { name: 'back', size: '12px' }),
          navNext: _react2.default.createElement(_Icon2.default, { name: 'forward', size: '12px' }),
          weekDayFormat: 'dd',
          displayFormat: 'MMM DD YYYY',
          customArrowIcon: _react2.default.createElement(LineSeparator, null),
          daySize: 37,
          horizontalMargin: 0,
          hideKeyboardShortcutsPanel: true,
          numberOfMonths: this.props.disabled ? 1 : 2,
          minimumNights: 0,
          focusedInput: this.focusedInput,
          anchorDirection: this.focusedInput === 'endDate' ? 'right' : 'left',
          onFocusChange: this.handleFocusChange
        }, (0, _lodash.pick)(rest, (0, _keys2.default)(_reactDates.DateRangePickerShape))))
      );
    }
  }, {
    key: 'focusedInput',
    get: function get() {
      return this.props.disabled !== this.state.internalFocusedInput && this.state.internalFocusedInput;
    }
  }]);
  return DateRangePicker;
}(_react2.default.PureComponent);

DateRangePicker.propTypes = (0, _extends3.default)({}, (0, _lodash.omit)(_reactDates.DateRangePickerShape, ['onFocusChange']), {
  startDateId: _propTypes2.default.string,
  endDateId: _propTypes2.default.string,
  /**
   * A component to wrap and control styles of the underlying react-dates DatePicker
   */
  Wrapper: _propTypes2.default.func,
  /**
   * A component that renders the separator line between the two inputs
   */
  LineSeparator: _propTypes2.default.func,
  /**
   * Set to true if the component's value is invalid
   */
  invalid: _propTypes2.default.bool,
  /**
   * Set to true if the component should be disabled. Alternatively, set to either 'startDate' or 'endDate'
   * to disable a particular part of the component.
   */
  disabled: _propTypes2.default.oneOfType([_propTypes2.default.bool, _propTypes2.default.string])
});
DateRangePicker.defaultProps = {
  Wrapper: _DateRangePickerWrapper2.default,
  LineSeparator: _DateRangePickerLineSeparator2.default,
  invalid: false,
  disabled: false
};
exports.default = DateRangePicker;