'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 _Header = require('./Header');

var _Header2 = _interopRequireDefault(_Header);

var _Body = require('./Body');

var _Body2 = _interopRequireDefault(_Body);

var _utils = require('../../../common/utils');

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

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

var layoutStyle = {
    position: 'relative',
    outline: 'none',
    width: '100%',
    minWidth: 200,
    listStyle: 'none',
    textAlign: 'left',
    lineHeight: '1.5'
};

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

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

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

        _this.setShadowValue = _this.setShadowValue.bind(_this);
        // this.handleKeyDown = this.handleKeyDown.bind(this)
        // this.handleChange = this.handleChange.bind(this)
        _this.handleChangeToNextDecade = _this.changeYear.bind(_this, 10);
        _this.handleChangeToPreviousDecade = _this.changeYear.bind(_this, -10);
        return _this;
    }

    _createClass(Panel, [{
        key: 'render',
        value: function render() {
            var _props = this.props,
                style = _props.style,
                shadowValue = _props.shadowValue;


            var startYear = parseInt(shadowValue.year() / 10, 10) * 10;
            var props = {
                autoFocus: true,
                tabIndex: "0",
                className: 'picker-day',
                style: (0, _utils.deepAssign)(layoutStyle, (0, _utils.omit)(style, 'body', 'header')),
                onKeyDown: this.handleKeyDown
            };

            var childProps = _extends({}, this.props, {
                shadowValue: shadowValue,
                // value,
                onShadowValueChange: this.setShadowValue,
                onChange: this.handleChange,
                startYear: startYear,
                endYear: startYear + 9,
                onChangeToPreviousDecade: this.handleChangeToPreviousDecade,
                onChangeToNextDecade: this.handleChangeToNextDecade
            });
            return _react2.default.createElement(
                'div',
                props,
                _react2.default.createElement(_Header2.default, _extends({}, childProps, {
                    style: style.header
                })),
                _react2.default.createElement(_Body2.default, _extends({}, childProps, {
                    style: style.body
                }))
            );
        }
    }, {
        key: 'changeYear',
        value: function changeYear(amount) {
            var shadowValue = this.props.shadowValue;

            this.setShadowValue(shadowValue.add(amount, 'year'));
        }
    }, {
        key: 'setShadowValue',
        value: function setShadowValue(newValue) {
            this.props.onShadowValueChange(newValue);
            // this.setState({ shadowValue: newValue })
        }
    }, {
        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 Panel;
}(_react.Component);

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