"use strict";

exports.__esModule = true;
exports.dateTimeCellType = void 0;
var _types = require("../../types");
var _View = require("./View");
exports.DateTimeView = _View.DateTimeView;
var _Edit = require("./Edit");
exports.DateTimeEdit = _Edit.DateTimeEdit;
var _DateTimeEditWrapper = require("./DateTimeEditWrapper");
var _helpers = require("./helpers");
/**
 * 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.
 */
const dateTimeCellType = exports.dateTimeCellType = (0, _types.defineCellType)({
  type: 'datetime',
  ViewComponent: _View.DateTimeView,
  EditComponent: _Edit.DateTimeEdit,
  EditWrapper: _DateTimeEditWrapper.DateTimeEditWrapper,
  serialize: value => {
    const date = (0, _helpers.toValidDate)(value);
    return date ? date.toISOString() : '';
  },
  deserialize: raw => {
    if (!raw) {
      return null;
    }
    const date = (0, _helpers.toValidDate)(raw);
    if (!date) {
      throw new Error(`Invalid datetime value: "${raw}"`);
    }
    return date;
  },
  validate: value => {
    if (value == null) {
      return null;
    }
    return (0, _helpers.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