import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
var _jsxFileName = 'src/datePicker/panel/yearPanel.jsx';
/**
 * yearPanel.jsx
 *
 * @Author: apple
 * @Date: 2017/10/25 19:27
 */

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import moment from 'moment';
import TypeSelectPanel from './typeSelectPanel';

/**
 * @ignore
 * */

var YearPanel = function (_React$PureComponent) {
    _inherits(YearPanel, _React$PureComponent);

    function YearPanel() {
        _classCallCheck(this, YearPanel);

        return _possibleConstructorReturn(this, (YearPanel.__proto__ || Object.getPrototypeOf(YearPanel)).apply(this, arguments));
    }

    _createClass(YearPanel, [{
        key: 'render',
        value: function render() {
            var _this2 = this;

            var _props = this.props,
                prefixCls = _props.prefixCls,
                selectType = _props.selectType,
                onChangePanel = _props.onChangePanel,
                curDecadeyears = _props.curDecadeyears,
                beginTime = _props.beginTime,
                currentDate = _props.currentDate,
                onSelectYear = _props.onSelectYear,
                type = _props.type,
                endTime = _props.endTime,
                onDisplayYears = _props.onDisplayYears,
                disabledBtn = _props.disabledBtn,
                disableTime = _props.disableTime;

            var yearPrefixCls = prefixCls + '-year';
            var typeSelectPanelParams = {
                onChangePanel: onChangePanel,
                onChangeSelectType: function onChangeSelectType() {},
                actionArray: {
                    prev: 'years-prev',
                    outPanel: 'select-year',
                    next: 'years-next'
                },
                title: onDisplayYears(),
                componentType: type,
                disabledBtn: disabledBtn,
                prefixCls: yearPrefixCls
            };
            return React.createElement(
                'div',
                { className: classNames(yearPrefixCls, { disable: selectType !== 'select-year' }), __source: {
                        fileName: _jsxFileName,
                        lineNumber: 74
                    },
                    __self: this
                },
                React.createElement(
                    'div',
                    { className: yearPrefixCls + '-condensed', __source: {
                            fileName: _jsxFileName,
                            lineNumber: 75
                        },
                        __self: this
                    },
                    React.createElement(TypeSelectPanel, Object.assign({}, typeSelectPanelParams, {
                        __source: {
                            fileName: _jsxFileName,
                            lineNumber: 76
                        },
                        __self: this
                    })),
                    React.createElement(
                        'div',
                        { className: yearPrefixCls + '-body', __source: {
                                fileName: _jsxFileName,
                                lineNumber: 77
                            },
                            __self: this
                        },
                        curDecadeyears.map(function (item, index) {
                            var type = _this2.props.type;
                            var disabled = false;
                            if (type === 'date-range-begin') {
                                var endTimeMoment = moment(endTime);
                                if (endTimeMoment.year() < +curDecadeyears[index]) {
                                    disabled = true;
                                }
                            }
                            if (type === 'date-range-end') {
                                var beginTimeMoment = moment(beginTime);
                                if (beginTimeMoment.year() > +curDecadeyears[index]) {
                                    disabled = true;
                                }
                            }
                            if (disableTime && disableTime(new Date(moment(item + '-01-01')))) {
                                disabled = true;
                            }
                            var classes = yearPrefixCls + '-body-td';
                            if (moment(currentDate).isSame(curDecadeyears[index] + '-01-01', 'year')) {
                                classes += ' ' + yearPrefixCls + '-body-td-checked';
                            }
                            return React.createElement(
                                'span',
                                {
                                    className: classes,
                                    key: index,
                                    onClick: !disabled ? function () {
                                        return onSelectYear(index);
                                    } : function () {},
                                    disabled: disabled, __source: {
                                        fileName: _jsxFileName,
                                        lineNumber: 101
                                    },
                                    __self: _this2
                                },
                                item
                            );
                        })
                    )
                )
            );
        }
    }]);

    return YearPanel;
}(React.PureComponent);

YearPanel.propTypes = {
    selectType: PropTypes.string,
    onChangePanel: PropTypes.func,
    curDecadeyears: PropTypes.array,
    beginTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)]),
    currentDate: PropTypes.oneOfType([PropTypes.instanceOf(moment), PropTypes.instanceOf(Date), PropTypes.string, PropTypes.number]),
    onSelectYear: PropTypes.func,
    disableTime: PropTypes.func,
    type: PropTypes.string,
    endTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)]),
    format: PropTypes.string,
    onDisplayYears: PropTypes.func,
    disabledAfterDate: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)]),
    disabledBeforeDate: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)])
};
YearPanel.defaultProps = {
    beginTime: moment().format('YYYY'),
    endTime: moment().format('YYYY')
};


export default YearPanel;