import React, { Component } from 'react';
import hocImmutable, { imShallowEqual } from '../../utils/HOC/hocImmutable';
import { DatePicker } from 'antd';
import moment from 'moment';

const Picker = hocImmutable(({ format = 'YYYY-MM-DD', onChange, ...props }) => {
    if (props.defaultValue !== undefined) {
        props.defaultValue = props.defaultValue.map(value => {
            return moment(value, format);
        })
    }
    if (props.value !== undefined) {
        props.value = props.value.map(value => {
            return moment(value, format);
        })
    }
    if (props.defaultPickerValue !== undefined) {
        props.defaultPickerValue = props.defaultPickerValue.map(value => {
            return moment(value, format);
        })
    }
    return <DatePicker.RangePicker {...props}
        format={format}
        onChange={(dates, dateStrs) => onChange && onChange(dateStrs, dates)}
    />
})

export default Picker;

export const DateRangePickerWithTime = ({ format = 'YYYY-MM-DD HH:mm:ss', showTime = true, ...props }) => {
    return <Picker {...props}
        showTime={showTime}
        format={format}
    />
}