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 { KeyboardTimePicker, MuiPickersUtilsProvider } from '@material-ui/pickers';
import DateFnsUtils from '@date-io/date-fns';
// import { useIntl } from '../../../intl';
/**
 * TextField for time input
 */
export const TimeField = props => {
    const { onChange: onChangeProp, value: valueProp } = props, other = __rest(props, ["onChange", "value"]);
    // TODO: implement intl, use CPS as reference
    // const { timeFormatString, is12hTime } = useIntl();
    const timeFormatString = 'HH:mm';
    const is12hTime = true;
    // @note @material-ui/picker's built-in mask generation does not work with formats like French (Canada)'s "HH 'h' mm"
    //       so for now compute the mask ourself. This may need revisiting when they release their next major version.
    const maskChar = '_';
    const mask = timeFormatString
        .split(/'([^']*)'/)
        .map((m, i) => (i % 2 === 0 ? m.replace(/[a-z]/gi, maskChar) : m))
        .join('') + 'M';
    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(KeyboardTimePicker
    // format={timeFormatString}
    , Object.assign({ 
        // format={timeFormatString}
        ampm: is12hTime, mask: "__:__ _M", 
        // maskChar={maskChar}
        variant: "inline", autoOk: true, onChange: onChange, value: value }, other))));
};
//# sourceMappingURL=TimeField.js.map