import { defineCellType } from '../../types';
import { TimeView } from './View';
import { TimeEdit } from './Edit';
export { TimeView, TimeEdit };
// Accepts `hh:mm`, `hh:mm:ss`, or `hh:mm:ss.SSS`. The Time type round-trips
// through `timeToDate`/`dateToTime` (which always emits the full form), so
// stored values are typically `hh:mm:ss.SSS` after the first edit.
const TIME_REGEXP = /^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\.[0-9]{1,3})?)?$/;
export const timeCellType = defineCellType({
    type: 'time',
    ViewComponent: TimeView,
    EditComponent: TimeEdit,
    // Time strings are timezone-neutral — pass through as-is for clipboard TSV.
    serialize: (value) => value ?? '',
    deserialize: (raw) => {
        if (!raw) {
            return null;
        }
        if (!TIME_REGEXP.test(raw)) {
            throw new Error(`Invalid time value: "${raw}" (expected hh:mm[:ss[.SSS]])`);
        }
        return raw;
    },
    validate: (value) => {
        if (!value) {
            return null;
        }
        return TIME_REGEXP.test(value) ? null : 'Invalid time';
    },
    editable: true,
    clearable: true,
    // Clear the committed value when entering edit mode via typing. With
    // `nativeTypeToEdit`, cairo focuses the WDS input synchronously inside the
    // keydown handler and lets the browser deliver the typed character to the
    // now-focused input naturally — no programmatic seeding required.
    nativeTypeToEdit: true,
    onTypeToEdit: () => ({ value: null }),
});
//# sourceMappingURL=index.js.map