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/datePanel.jsx';
/**
 * datePanel.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 { TimeOptions } from '../../timePicker';
import TypeSelectPanel from './typeSelectPanel';
import { isFunction } from '../../util/isType';

/**
 * @ignore
 * */

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

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

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

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

            var _props = this.props,
                datePanel = _props.datePanel,
                selectType = _props.selectType,
                currentMonth = _props.currentMonth,
                currentYear = _props.currentYear,
                monthDaysArray = _props.monthDaysArray,
                currentDate = _props.currentDate,
                beginTime = _props.beginTime,
                dateConfig = _props.dateConfig,
                showTime = _props.showTime,
                onChangeTimeOrDatePanel = _props.onChangeTimeOrDatePanel,
                endTime = _props.endTime,
                selectHour = _props.selectHour,
                selectMinute = _props.selectMinute,
                selectSecond = _props.selectSecond,
                onSelectTime = _props.onSelectTime,
                onChangePanel = _props.onChangePanel,
                onChangeSelectType = _props.onChangeSelectType,
                onSelectDay = _props.onSelectDay,
                prefixCls = _props.prefixCls,
                datePickerType = _props.datePickerType,
                disabledBtn = _props.disabledBtn,
                days = _props.days,
                disableTime = _props.disableTime,
                local = _props.local,
                disableExquisiteTimeRules = _props.disableExquisiteTimeRules;

            var componentType = this.props.type;
            var dayPrefixCls = prefixCls + '-day';
            var typeSelectPanelParams = {
                onChangePanel: onChangePanel,
                onChangeSelectType: onChangeSelectType,
                actionArray: {
                    prev: 'days-prev',
                    outPanel: 'select-month',
                    next: 'days-next'
                },
                title: dateConfig[local].months[currentMonth - 1].label + ' ' + currentYear,
                componentType: componentType,
                selectType: 'day',
                disabledBtn: disabledBtn,
                days: days,
                prefixCls: dayPrefixCls
            };
            var timeDefaultValue = selectHour + ':' + selectMinute + ':' + selectSecond;
            var parseDisabledHours = void 0;
            var parseDisabledMinutes = void 0;
            var parseDisabledSeconds = void 0;
            if (disableExquisiteTimeRules) {
                var disabledHours = disableExquisiteTimeRules.disabledHours,
                    disabledMinutes = disableExquisiteTimeRules.disabledMinutes,
                    disabledSeconds = disableExquisiteTimeRules.disabledSeconds;

                parseDisabledHours = isFunction(disabledHours) ? function (number) {
                    return disabledHours(number, currentDate);
                } : function () {};
                parseDisabledMinutes = isFunction(disabledMinutes) ? function (selectHour, number) {
                    return disabledMinutes(selectHour, number, currentDate);
                } : function () {};
                parseDisabledSeconds = isFunction(disabledSeconds) ? function (selectHour, selectMinute, number) {
                    return disabledSeconds(selectHour, selectMinute, number, currentDate);
                } : function () {};
            }
            return React.createElement(
                'div',
                { className: classNames(dayPrefixCls, { disable: selectType !== 'select-day' }), __source: {
                        fileName: _jsxFileName,
                        lineNumber: 115
                    },
                    __self: this
                },
                datePanel ? React.createElement(
                    'div',
                    {
                        __source: {
                            fileName: _jsxFileName,
                            lineNumber: 117
                        },
                        __self: this
                    },
                    React.createElement(TypeSelectPanel, Object.assign({}, typeSelectPanelParams, {
                        __source: {
                            fileName: _jsxFileName,
                            lineNumber: 118
                        },
                        __self: this
                    })),
                    React.createElement(
                        'div',
                        { className: dayPrefixCls + '-body', __source: {
                                fileName: _jsxFileName,
                                lineNumber: 119
                            },
                            __self: this
                        },
                        monthDaysArray.map(function (day, index) {
                            var _monthDaysArray$index = monthDaysArray[index],
                                title = _monthDaysArray$index.title,
                                type = _monthDaysArray$index.type,
                                dayFormat = _monthDaysArray$index.dayFormat;

                            var dayBodyPrefixCls = dayPrefixCls + '-body';
                            var className = dayBodyPrefixCls + '-td ' + dayBodyPrefixCls + '-' + type + '-day';
                            var checked = false; // 选中状态
                            // 选中状态的判断
                            var daysFormat = 'YYYY-MM-DD';
                            var formatStaticDate = moment(dayFormat).format(daysFormat);
                            if (type === 'current' && (datePickerType === 'date-range-unity' && (_this2.props.type === 'date-range-begin' && moment(endTime).format(daysFormat) === formatStaticDate || _this2.props.type === 'date-range-end' && moment(beginTime).format(daysFormat) === formatStaticDate) || moment(currentDate).format(daysFormat) === formatStaticDate || moment(currentDate).format(daysFormat) === formatStaticDate)) {
                                checked = true;
                                className += ' ' + dayBodyPrefixCls + '-checked';
                            }
                            // 判断是否是当天
                            if (!checked && moment().format(daysFormat) === formatStaticDate) {
                                className += ' ' + dayBodyPrefixCls + '-today';
                            }
                            if (disableTime && disableTime(new Date(moment(dayFormat))) || moment(dayFormat) > moment(endTime) && componentType === 'date-range-begin' || moment(dayFormat) < moment(beginTime) && componentType === 'date-range-end') {
                                return React.createElement(
                                    'span',
                                    { key: day.dayFormat + '-' + index, className: className, disabled: true, __source: {
                                            fileName: _jsxFileName,
                                            lineNumber: 151
                                        },
                                        __self: _this2
                                    },
                                    title
                                );
                            } else {
                                // 判断选中的时间范围
                                if (datePickerType === 'date-range-unity' && type === 'current' && moment(dayFormat) < moment(endTime) && moment(dayFormat) > moment(beginTime)) {
                                    className += checked ? '' : ' ne-datePicker-day-in-range';
                                } else {
                                    className += checked ? '' : ' ne-datePicker-day-hover';
                                }
                                return React.createElement(
                                    'span',
                                    {
                                        key: day.dayFormat + '-' + index,
                                        className: className,
                                        'data-day': day.dayFormat.split(' ')[0],
                                        onClick: function onClick() {
                                            return onSelectDay(index);
                                        }, __source: {
                                            fileName: _jsxFileName,
                                            lineNumber: 168
                                        },
                                        __self: _this2
                                    },
                                    title
                                );
                            }
                        })
                    )
                ) : React.createElement(TimeOptions, {
                    defaultValue: timeDefaultValue,
                    onOpen: true,
                    onChange: function onChange(value, targetOption) {
                        return onSelectTime(targetOption.type, targetOption.time);
                    },
                    disabledHours: parseDisabledHours,
                    disabledMinutes: parseDisabledMinutes,
                    disabledSeconds: parseDisabledSeconds,
                    __source: {
                        fileName: _jsxFileName,
                        lineNumber: 181
                    },
                    __self: this
                }),
                showTime && React.createElement(
                    'div',
                    { className: dayPrefixCls + '-foot', __source: {
                            fileName: _jsxFileName,
                            lineNumber: 191
                        },
                        __self: this
                    },
                    React.createElement(
                        'div',
                        {
                            className: dayPrefixCls + '-foot-choose-time',
                            style: datePanel ? { justifyContent: 'flex-end', marginRight: '20px' } : {}, __source: {
                                fileName: _jsxFileName,
                                lineNumber: 192
                            },
                            __self: this
                        },
                        React.createElement(
                            'span',
                            { onClick: onChangeTimeOrDatePanel, __source: {
                                    fileName: _jsxFileName,
                                    lineNumber: 195
                                },
                                __self: this
                            },
                            datePanel ? dateConfig[local].time : dateConfig[local].date
                        )
                    )
                )
            );
        }
    }]);

    return DatePanel;
}(React.PureComponent);

DatePanel.propTypes = {
    datePanel: PropTypes.bool,
    selectType: PropTypes.string,
    datePickerType: PropTypes.string,
    currentMonth: PropTypes.number,
    currentYear: PropTypes.number,
    days: PropTypes.array,
    monthDaysArray: PropTypes.array,
    currentDate: PropTypes.oneOfType([PropTypes.instanceOf(moment), PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string, PropTypes.number]),
    disabledBeforeDate: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)]),
    beginTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)]),
    disabledAfterDate: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)]),
    dateConfig: PropTypes.object,
    showTime: PropTypes.bool,
    onChangeTimeOrDatePanel: PropTypes.func,
    onHandleSureTime: PropTypes.func,
    format: PropTypes.string,
    endTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)]),
    selectHour: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.number]),
    selectMinute: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    selectSecond: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    onSelectTime: PropTypes.func,
    onChangePanel: PropTypes.func,
    onChangeSelectType: PropTypes.func,
    onSelectDay: PropTypes.func,
    disableTime: PropTypes.func
};


export default DatePanel;