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/monthPanel.jsx';
/**
 * monthPanel.jsx
 *
 * @Author: apple
 * @Date: 2017/10/25 19:28
 */

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

/**
 * @ignore
 * */

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

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

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

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

            var _props = this.props,
                prefixCls = _props.prefixCls,
                months = _props.months,
                disabledBtn = _props.disabledBtn,
                local = _props.local,
                selectType = _props.selectType,
                onChangePanel = _props.onChangePanel,
                beginTime = _props.beginTime,
                currentDate = _props.currentDate,
                onSelectMonth = _props.onSelectMonth,
                type = _props.type,
                endTime = _props.endTime,
                currentYear = _props.currentYear,
                onChangeSelectType = _props.onChangeSelectType,
                disableTime = _props.disableTime;

            var monthPrefixCls = prefixCls + '-month';
            var typeSelectPanelParams = {
                onChangePanel: onChangePanel,
                onChangeSelectType: onChangeSelectType,
                actionArray: {
                    prev: 'months-prev',
                    outPanel: 'select-year',
                    next: 'months-next'
                },
                title: currentYear,
                componentType: type,
                disabledBtn: disabledBtn,
                local: local,
                prefixCls: monthPrefixCls
            };
            return React.createElement(
                'div',
                { className: classNames(monthPrefixCls, { disable: selectType !== 'select-month' }), __source: {
                        fileName: _jsxFileName,
                        lineNumber: 75
                    },
                    __self: this
                },
                React.createElement(
                    'div',
                    { className: monthPrefixCls + '-condensed', __source: {
                            fileName: _jsxFileName,
                            lineNumber: 76
                        },
                        __self: this
                    },
                    React.createElement(TypeSelectPanel, Object.assign({}, typeSelectPanelParams, {
                        __source: {
                            fileName: _jsxFileName,
                            lineNumber: 77
                        },
                        __self: this
                    })),
                    React.createElement(
                        'div',
                        { className: monthPrefixCls + '-body', __source: {
                                fileName: _jsxFileName,
                                lineNumber: 78
                            },
                            __self: this
                        },
                        months.map(function (item, index) {
                            var displayYear = currentYear;
                            var disabled = false;
                            var renderTimeMoment = moment(displayYear + '-' + item.value);
                            if (type === 'date-range-end') {
                                // 时间禁用
                                var beginTimeMoment = moment(beginTime);
                                if (beginTimeMoment.year() > renderTimeMoment.year() || beginTimeMoment.year() === renderTimeMoment.year() && beginTimeMoment.month() > renderTimeMoment.month()) {
                                    disabled = true;
                                }
                            }
                            if (type === 'date-range-begin') {
                                var endTimeMoment = moment(endTime);
                                if (endTimeMoment.year() < renderTimeMoment.year() || endTimeMoment.year() === renderTimeMoment.year() && endTimeMoment.month() < renderTimeMoment.month()) {
                                    disabled = true;
                                }
                            }
                            if (disableTime && disableTime(new Date(renderTimeMoment))) {
                                disabled = true;
                            }
                            var classes = monthPrefixCls + '-body-td';
                            if (moment(currentDate).isSame(currentYear + '-' + item.value, 'month')) {
                                classes += ' ' + monthPrefixCls + '-body-td-checked';
                            }
                            return React.createElement(
                                'span',
                                {
                                    className: classes,
                                    key: index,
                                    onClick: !disabled ? function () {
                                        return onSelectMonth(index);
                                    } : function () {},
                                    disabled: disabled, __source: {
                                        fileName: _jsxFileName,
                                        lineNumber: 112
                                    },
                                    __self: _this2
                                },
                                item.label
                            );
                        })
                    )
                )
            );
        }
    }]);

    return MonthPanel;
}(React.PureComponent);

MonthPanel.propTypes = {
    selectType: PropTypes.string,
    onChangePanel: PropTypes.func,
    month: 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]),
    onSelectMonth: PropTypes.func,
    disableTime: PropTypes.func,
    type: PropTypes.string,
    endTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)]),
    format: PropTypes.string,
    currentYear: PropTypes.number,
    onChangeSelectType: PropTypes.func
};
MonthPanel.defaultProps = {
    beginTime: moment().format('YYYY-MM'),
    endTime: moment().format('YYYY-MM')
};


export default MonthPanel;