import { defineCellType } from '../../types';
import { DateTimeView } from './View';
import { DateTimeEdit } from './Edit';
import { DateTimeEditWrapper } from './DateTimeEditWrapper';
import { toValidDate } from './helpers';
export { DateTimeView, DateTimeEdit };
/**
 * DateTime — 2-in-1 cell type. Single `Date | null` rendered as two halves
 * (date | time) with a vertical divider. Each half has its own focus + edit
 * lifecycle, but only one sub-cell is in edit mode at a time.
 *
 * Serialized via ISO 8601 (`toISOString`) — round-trips both date and time
 * components without timezone surprises in storage. The cell is never in a
 * "date set, time null" state; an empty time-of-day after a date pick
 * defaults to 00:00:00.
 */
export const dateTimeCellType = defineCellType({
    type: 'datetime',
    ViewComponent: DateTimeView,
    EditComponent: DateTimeEdit,
    EditWrapper: DateTimeEditWrapper,
    serialize: (value) => {
        const date = toValidDate(value);
        return date ? date.toISOString() : '';
    },
    deserialize: (raw) => {
        if (!raw) {
            return null;
        }
        const date = toValidDate(raw);
        if (!date) {
            throw new Error(`Invalid datetime value: "${raw}"`);
        }
        return date;
    },
    validate: (value) => {
        if (value == null) {
            return null;
        }
        return toValidDate(value) ? null : 'Invalid date/time';
    },
    editable: true,
    clearable: true,
    // Forward typed character into the date half (entry default is 'date').
    // The Edit component opens the calendar and forwards the key.
    onTypeToEdit: () => ({}),
});
//# sourceMappingURL=index.js.map