"use strict";

exports.__esModule = true;
exports.dateCellType = void 0;
var _types = require("../../types");
var _View = require("./View");
exports.DateView = _View.DateView;
var _Edit = require("./Edit");
exports.DateEdit = _Edit.DateEdit;
const dateCellType = exports.dateCellType = (0, _types.defineCellType)({
  type: 'date',
  ViewComponent: _View.DateView,
  EditComponent: _Edit.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