import { defineCellType } from '../../types';
import { DateView } from './View';
import { DateEdit } from './Edit';
export { DateView, DateEdit };
export const dateCellType = defineCellType({
    type: 'date',
    ViewComponent: DateView,
    EditComponent: DateEdit,
    serialize: (value) => {
        if (!value) {
            return '';
        }
        const date = value instanceof Date ? value : new Date(value);
        return isNaN(date.getTime()) ? '' : date.toISOString();
    },
    deserialize: (raw) => {
        if (!raw) {
            return null;
        }
        const date = new Date(raw);
        if (isNaN(date.getTime())) {
            throw new Error();
        }
        return date;
    },
    validate: (value) => {
        if (!value) {
            return null;
        }
        const date = value instanceof Date ? value : new Date(value);
        if (isNaN(date.getTime())) {
            return 'Invalid date';
        }
        return null;
    },
    editable: true,
    clearable: true,
    onTypeToEdit: () => ({}),
});
//# sourceMappingURL=index.js.map