import './style.scss'
import DatePicker from '../../../datePicker';
import BaseFormControl from '../../baseFormControl';
import { JDDateTimeTpl } from './tpl';
class JDDateTime extends BaseFormControl {
    constructor(config) {
        super(config);
        this.config = this.getConfig(config);
        this.render();
    }
    
    getConfig(config) {
        return $.extend(true, {}, {
            domData: {},
            value: ''
        }, config);
    }
    
     render() {
        const { dataType, range, format, value, min, max, limitRange, trigger, show, showBottom, btns, isClosePicker } = this.config.domData
        this.setValue();
        let dom = template.render(JDDateTimeTpl, {
            value: this.value
        });
        this.appendFormControl(dom);
        new DatePicker({
            elem: this.element.find('input'),
            done: (time) => {
                this.setValue(time);
            },
            
            type: dataType || 'datetime',
            
            range: !!range,
            
            format: format || 'yyyy-MM-dd HH:mm:ss',
            
            min: '1900-01-01 00:00:00',
            
            max: '2099-12-31 00:00:00',
            
            limitRange: limitRange || 1000000,
            value: this.value,
        })
    }
    
    setValue(value) {
        if (value) {
            this.value = value;
        } else {
            if (this.config.defaultDate) {
                this.value = this.config.defaultDate;
            }
        }
    }
    
    getData() {
        let result = {};
        if (this.value) {
            result[this.config.domData.name] = this.value;
        } else {
            return null;
        }
        return result;
    }
}
export default JDDateTime;