import React, {useMemo} from "react";
import {AutoTypeInputProps} from "auto-antd/dist/esm/Components";
import {DatePicker} from "antd";
import moment from "moment";

export const DateInput: React.FC<AutoTypeInputProps> = (
    {
        value, onChange
    }) => {


    const dateValue = useMemo(() => {
        if (!value) return null;
        console.log('v....',value)
        return moment(value * 1000);
    }, [value]);

    const onValueChange = (date: moment.Moment | null) => {
        if (date) {
            const unix = date.unix()
            onChange?.(unix);
        }else {
            onChange?.(undefined);
        }
    }

    return (<DatePicker
        onChange={onValueChange}
        value={dateValue}
        format="YYYY-MM-DD"
    />)
}
