import { IReactComponent } from '@wowpic/xform-types';
import { DatePicker as AntdDatePicker } from 'antd';
import React, { FunctionComponent, useCallback } from 'react';
import { getMomentTime } from '../utils';

const DateTimePicker: FunctionComponent<IReactComponent> = ({
    value: originValue,
    onChange,
    ...props
}) => {
    const value: any = getMomentTime(originValue);
    const onValueChange = useCallback(
        (v) => onChange(+v),
        [onChange]
    );
    return (
        <AntdDatePicker
            showTime
            value={value}
            onChange={onValueChange}
            {...props} />
    );
};

export default DateTimePicker;
