'use strict';

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

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _styledComponents = require('styled-components');

var _styledComponents2 = _interopRequireDefault(_styledComponents);

var _reactDatetime = require('react-datetime');

var _reactDatetime2 = _interopRequireDefault(_reactDatetime);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var BaseDateInput = (0, _styledComponents2.default)(_reactDatetime2.default).withConfig({
  displayName: 'DateInput__BaseDateInput'
})(['position:relative;.form-control{display:block;width:', ';height:40px;min-height:40px;padding:6px 12px;box-sizing:border-box;font-family:\'Montserrat\',Helvetica,sans-serif;font-size:14px;font-weight:300;color:', ';background-color:', ';background-image:none;outline-width:0;user-select:text;border:1px solid  ', ';}.rdtPicker{display:none;position:absolute;width:250px;padding:4px;margin-top:1px;z-index:99999 !important;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.1);border:1px solid ', ';border-radius:5px;}&.rdtOpen .rdtPicker{display:block;}&.rdtStatic .rdtPicker{box-shadow:none;position:static;}.rdtPicker .rdtTimeToggle{text-align:center;}.rdtPicker table{width:100%;margin:0;}.rdtPicker td,.rdtPicker th{text-align:center;height:28px;}.rdtPicker td{font-family:\'Montserrat\',Helvetica,sans-serif;font-size:14px;font-weight:500;cursor:pointer;}.rdtPicker td.rdtDay:hover,.rdtPicker td.rdtHour:hover,.rdtPicker td.rdtMinute:hover,.rdtPicker td.rdtSecond:hover,.rdtPicker .rdtTimeToggle:hover{cursor:pointer;background:', ';border:1px solid ', ';border-radius:5px;box-sizing:border-box;}.rdtPicker td.rdtOld,.rdtPicker td.rdtNew{color:', ';}.rdtPicker td.rdtToday{position:relative;}.rdtPicker td.rdtToday:before{content:\'\';display:inline-block;border-left:7px solid transparent;border-bottom:7px solid #428bca;border-top-color:rgba(0,0,0,0.2);position:absolute;bottom:4px;right:4px;}.rdtPicker td.rdtActive,.rdtPicker td.rdtActive:hover{background-color:', ';color:', ';text-shadow:0 -1px 0 rgba(0,0,0,0.25);border:1px solid ', ';border-radius:5px;box-sizing:border-box;}.rdtPicker td.rdtActive.rdtToday:before{border-bottom-color:', ';}.rdtPicker td.rdtDisabled,.rdtPicker td.rdtDisabled:hover{background:none;color:', ';cursor:not-allowed;}.rdtPicker td span.rdtOld{color:', ';}.rdtPicker td span.rdtDisabled,.rdtPicker td span.rdtDisabled:hover{background:none;color:', ';cursor:not-allowed;}.rdtPicker th{border-bottom:1px solid #f9f9f9;}.rdtPicker .dow{width:14.2857%;border-bottom:none;cursor:default;font-family:\'Montserrat\',Helvetica,sans-serif;font-size:14px;font-weight:300;color:', ';}.rdtPicker th.rdtSwitch{width:100px;height:30px;font-family:\'Montserrat\',Helvetica,sans-serif;font-size:14px;font-weight:300;border:1px solid ', ';border-radius:5px;box-sizing:border-box;}.rdtPicker th.rdtNext,.rdtPicker th.rdtPrev{display:flex;flex-direction:row;justify-content:center;align-items:center;width:30px;height:30px;font-family:\'Montserrat\',Helvetica,sans-serif;font-size:24px;font-weight:300;border:1px solid ', ';border-radius:5px;box-sizing:border-box;}.rdtPrev span,.rdtNext span{display:block;line-height:0;user-select:none;}.rdtPicker th.rdtDisabled,.rdtPicker th.rdtDisabled:hover{background:none;color:', ';cursor:not-allowed;}.rdtPicker thead tr:first-child th{cursor:pointer;}.rdtPicker thead tr:first-child th:hover{background:#eeeeee;}.rdtPicker tfoot{border-top:1px solid #f9f9f9;}.rdtPicker button{border:none;background:none;cursor:pointer;}.rdtPicker button:hover{background-color:', ';}.rdtPicker thead button{width:100%;height:100%;}td.rdtMonth,td.rdtYear{height:50px;width:25%;cursor:pointer;}td.rdtMonth:hover,td.rdtYear:hover{background:#eee;}.rdtCounters{display:inline-block;}.rdtCounters > div{float:left;}.rdtCounter{height:100px;}.rdtCounter{width:40px;}.rdtCounterSeparator{line-height:100px;}.rdtCounter .rdtBtn{height:40%;line-height:40px;cursor:pointer;display:block;user-select:none;}.rdtCounter .rdtBtn:hover{background:#eee;}.rdtCounter .rdtCount{height:20%;font-size:1.2em;}.rdtMilli{vertical-align:middle;padding-left:8px;width:48px;}.rdtMilli input{width:100%;font-size:1.2em;margin-top:37px;}.rdtTime td{cursor:default;}'], function (props) {
  return props.fullwidth ? '100%' : '150px';
}, function (props) {
  return props.theme['gray-5'];
}, function (props) {
  return props.theme['white'];
}, function (props) {
  return props.theme[props.borderColor];
}, function (props) {
  return props.theme['gray-2'];
}, function (props) {
  return props.theme['gray-1'];
}, function (props) {
  return props.theme['gray-1'];
}, function (props) {
  return props.theme['gray-3'];
}, function (props) {
  return props.theme['brand-secondary'];
}, function (props) {
  return props.theme['white'];
}, function (props) {
  return props.theme['brand-secondary'];
}, function (props) {
  return props.theme['white'];
}, function (props) {
  return props.theme['gray-1'];
}, function (props) {
  return props.theme['gray-3'];
}, function (props) {
  return props.theme['gray-1'];
}, function (props) {
  return props.theme['gray-5'];
}, function (props) {
  return props.theme['gray-1'];
}, function (props) {
  return props.theme['gray-1'];
}, function (props) {
  return props.theme['gray-1'];
}, function (props) {
  return props.theme['gray-1'];
});

var selectBorderColor = function selectBorderColor(state) {
  switch (state) {
    case 'initial':
      return 'gray-2';
    case 'invalid':
      return 'error';
    case 'valid':
      return 'success';
    default:
      return 'gray-2';
  }
};

var DateInput = function DateInput(props) {
  var errorState = props.errorState,
      rest = _objectWithoutProperties(props, ['errorState']);

  var borderColor = selectBorderColor(props.errorState);

  return _react2.default.createElement(BaseDateInput, _extends({ borderColor: borderColor }, rest));
};

// Documentation: https://github.com/arqex/react-datetime
DateInput.propTypes = {
  value: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object]),
  defaultValue: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object]),
  dateFormat: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.bool]),
  timeFormat: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.bool]),
  input: _propTypes2.default.bool,
  open: _propTypes2.default.bool,
  locale: _propTypes2.default.string,
  utc: _propTypes2.default.bool,
  onChange: _propTypes2.default.func,
  onFocus: _propTypes2.default.func,
  onBlur: _propTypes2.default.func,
  viewMode: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.bool]),
  className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array]),
  inputProps: _propTypes2.default.object,
  isValidDate: _propTypes2.default.func,
  renderDay: _propTypes2.default.func,
  renderMonth: _propTypes2.default.func,
  renderYear: _propTypes2.default.func,
  strictParsing: _propTypes2.default.bool,
  closeOnSelect: _propTypes2.default.bool,
  closeOnTab: _propTypes2.default.bool,
  timeConstraints: _propTypes2.default.object,
  disableOnClickOutside: _propTypes2.default.bool,
  fullwidth: _propTypes2.default.bool
};

DateInput.defaultProps = {
  dateFormat: true,
  timeFormat: false,
  input: true,
  utc: false,
  viewMode: 'days',
  className: '',
  strictParsing: false,
  closeOnSelect: true,
  closeOnTab: true,
  fullwidth: false
};

exports.default = DateInput;