'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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _day = require('./day');

var _day2 = _interopRequireDefault(_day);

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

//import MonthPicker from './month'
//import YearPicker from './year'

var DatePicker = function (_Component) {
    _inherits(DatePicker, _Component);

    function DatePicker(props) {
        _classCallCheck(this, DatePicker);

        var _this = _possibleConstructorReturn(this, (DatePicker.__proto__ || Object.getPrototypeOf(DatePicker)).call(this, props));

        _this.state = {
            mode: 'day',
            shadowValue: props.value || props.defaultValue
        };
        _this.handleChangeMode = _this.handleChangeMode.bind(_this);
        _this.handleShadowChange = _this.handleShadowChange.bind(_this);
        return _this;
    }

    _createClass(DatePicker, [{
        key: 'render',
        value: function render() {
            var _props = this.props,
                value = _props.value,
                defaultValue = _props.defaultValue,
                day = _props.style.day,
                rest = _objectWithoutProperties(_props, ['value', 'defaultValue', 'style']);

            var props = _extends({}, rest, {
                value: value || defaultValue,
                shadowValue: this.state.shadowValue,
                onChangeMode: this.handleChangeMode,
                onShadowChange: this.handleShadowChange
            });

            switch (this.state.mode) {

                case 'day':
                    return _react2.default.createElement(_day2.default, _extends({}, props, { style: day }));

                //case 'month':
                //    return <MonthPicker {...{...props, style: day}} />

                //case 'year':
                //    return <YearPicker {...{...props, style: day}} />

                default:
                    return _react2.default.createElement(_day2.default, _extends({}, props, { style: day }));
            }
        }
    }, {
        key: 'handleChange',
        value: function handleChange(value) {
            if (this.isAllowedDate(value)) {
                this.props.onChange(value);
            }
        }
    }, {
        key: 'handleChangeMode',
        value: function handleChangeMode(mode) {
            this.setState({ mode: mode });
        }
    }, {
        key: 'handleShadowChange',
        value: function handleShadowChange(nextValue) {
            this.setState({ shadowValue: nextValue });
        }
    }, {
        key: 'componentWillReceiveProps',
        value: function componentWillReceiveProps(nextProps) {
            if (nextProps.value && !nextProps.value.isSame(this.props.value)) {
                this.setState({
                    shadowValue: nextProps.value
                });
            }
        }
    }, {
        key: 'isAllowedDate',
        value: function isAllowedDate(value) {
            var _props2 = this.props,
                minDate = _props2.minDate,
                maxDate = _props2.maxDate;

            var isAfter = !value || !minDate ? true : value.isAfter(minDate);
            var isBefore = !value || !maxDate ? true : value.isBefore(maxDate);
            return isBefore && isAfter;
        }
    }]);

    return DatePicker;
}(_react.Component);

exports.default = DatePicker;
//# sourceMappingURL=index.js.map