var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { DateTime } from 'luxon';
import React, { useCallback, useMemo } from 'react';
import { KeyboardDateTimePicker, MuiPickersUtilsProvider } from '@material-ui/pickers';
// import { useIntl } from '../../../intl';
// import { useDateFormat } from '../../utils/CompanyPreferencesProvider';
import DateFnsUtils from '@date-io/date-fns';
/**
 * TextField for date input
 */
export const DateTimeField = (props) => {
    const { onChange: onChangeProp, value: valueProp } = props, other = __rest(props, ["onChange", "value"]);
    // TODO: implement intl, use CPS as reference
    // const { shortDateFormatString } = useIntl();
    const dateFormat = 'yyyy-MM-dd HH:mm';
    const isValidDate = (date) => {
        return date instanceof Date && !isNaN(date);
    };
    const onChange = useCallback((value) => onChangeProp && onChangeProp(isValidDate(value) ? value : undefined), [onChangeProp]);
    const value = useMemo(() => {
        console.log(valueProp);
        return isValidDate(valueProp)
            ? DateTime.fromISO(valueProp.toISOString())
            : null;
    }, [valueProp]);
    return (React.createElement(MuiPickersUtilsProvider, { utils: DateFnsUtils }, React.createElement(KeyboardDateTimePicker, Object.assign({ format: dateFormat, variant: "inline", onChange: onChange, value: value }, other))));
};
//# sourceMappingURL=DateTimeField.js.map