/**
 * 时间选择
 * @author xiufu.wang
 */

import ElTimeSelect from 'mars-pro/packages/time-select';
import ElTimePicker from 'mars-pro/packages/time-picker';
import BaseMixin from 'mars-pro/packages/pro-input/src/mixins/base';
export default {
    name: 'ProInputTime',
    componentName: 'ProInputTime',
    mixins: [BaseMixin],
    props: {
        type: String
    },
    components: {
        ElTimeSelect,
        ElTimePicker
    },
    computed: {
        mergerPickerOptions() {
            const usepickerOptions = this.$attrs.pickerOptions || {}
            const min = this.$attrs.min
            const max = this.$attrs.max
            if (this.isTimePicker) {
                return {
                    selectableRange:`${min || '01:00:00'} - ${max || '24:59:59'}`,
                    ...usepickerOptions
                }
            }
            return {
                ...(!!min ? { start: min } : {}),
                ...(!!max ? { end: max } : {}),
                sep: this.$attrs.sep,
                ...usepickerOptions
            }
        },
        isTimePicker() {
            return this.type === 'timePicker'
        }
    },
    render() {
        const _datas = {
            props: {
                value: this.value,
                lazy: true,
                clearable: true,
                valueFormat: 'HH:mm:ss',
                ...this.$attrs,
                pickerOptions: this.mergerPickerOptions,
                popperClass: 'pro-input-time-picker-panel',
                'is-range': false
            },
            attrs: this.$attrs,
            on: {
                ...this.$listeners
            },
            ref: 'elinput',
            'class': {
                'pro-input-time': true
            }
        }

        if (this.isTimePicker) {
            return (
                <ElTimePicker {..._datas}> {this.renderSlots()}</ElTimePicker>
            )
        }

        return (
            <ElTimeSelect  {..._datas}>
                {this.renderSlots()}
            </ElTimeSelect>
        )
    }
}