'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.Components = undefined;

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

exports.getTimeProps = getTimeProps;

var _PickerButton = require('../PickerButton');

var _PickerButton2 = _interopRequireDefault(_PickerButton);

var _PickerTag = require('../PickerTag');

var _PickerTag2 = _interopRequireDefault(_PickerTag);

var _generateSinglePicker2 = require('./generateSinglePicker');

var _generateSinglePicker3 = _interopRequireDefault(_generateSinglePicker2);

var _generateRangePicker = require('./generateRangePicker');

var _generateRangePicker2 = _interopRequireDefault(_generateRangePicker);

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

/**
 * 基于antd v4.5.3 date-picker改造
 */
var Components = exports.Components = { button: _PickerButton2['default'], rangeItem: _PickerTag2['default'] };
function toArray(list) {
    if (!list) {
        return [];
    }
    return Array.isArray(list) ? list : [list];
}
function getTimeProps(props) {
    var format = props.format,
        picker = props.picker,
        showHour = props.showHour,
        showMinute = props.showMinute,
        showSecond = props.showSecond,
        use12Hours = props.use12Hours;

    var firstFormat = toArray(format)[0];
    var showTimeObj = (0, _extends3['default'])({}, props);
    if (firstFormat) {
        if (!firstFormat.includes('s') && showSecond === undefined) {
            showTimeObj.showSecond = false;
        }
        if (!firstFormat.includes('m') && showMinute === undefined) {
            showTimeObj.showMinute = false;
        }
        if (!firstFormat.includes('H') && !firstFormat.includes('h') && showHour === undefined) {
            showTimeObj.showHour = false;
        }
        if ((firstFormat.includes('a') || firstFormat.includes('A')) && use12Hours === undefined) {
            showTimeObj.use12Hours = true;
        }
    }
    if (picker === 'time') {
        return showTimeObj;
    }
    return {
        showTime: showTimeObj
    };
}
function generatePicker(generateConfig) {
    // =========================== Picker ===========================
    var _generateSinglePicker = (0, _generateSinglePicker3['default'])(generateConfig),
        DatePicker = _generateSinglePicker.DatePicker,
        WeekPicker = _generateSinglePicker.WeekPicker,
        MonthPicker = _generateSinglePicker.MonthPicker,
        YearPicker = _generateSinglePicker.YearPicker,
        TimePicker = _generateSinglePicker.TimePicker,
        QuarterPicker = _generateSinglePicker.QuarterPicker;
    // ======================== Range Picker ========================


    var RangePicker = (0, _generateRangePicker2['default'])(generateConfig);
    var MergedDatePicker = DatePicker;
    MergedDatePicker.WeekPicker = WeekPicker;
    MergedDatePicker.MonthPicker = MonthPicker;
    MergedDatePicker.YearPicker = YearPicker;
    MergedDatePicker.RangePicker = RangePicker;
    MergedDatePicker.TimePicker = TimePicker;
    MergedDatePicker.QuarterPicker = QuarterPicker;
    return MergedDatePicker;
}
exports['default'] = generatePicker;