"use strict";

exports.__esModule = true;
exports.objectCellType = void 0;
var _types = require("../../types");
var _View = require("./View");
exports.ObjectView = _View.ObjectView;
var _Edit = require("./Edit");
exports.ObjectEdit = _Edit.ObjectEdit;
var _patternsFields = require("@wix/patterns-fields");
const objectCellType = exports.objectCellType = (0, _types.defineCellType)({
  type: 'object',
  ViewComponent: _View.ObjectView,
  EditComponent: _Edit.ObjectEdit,
  serialize: value => value != null ? (0, _patternsFields.safeStringify)(value) : '',
  deserialize: raw => {
    if (!raw) {
      return {};
    }
    const parsed = (0, _patternsFields.safeParse)(raw);
    return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) ? parsed : {};
  },
  validate: value => {
    if (value == null) {
      return null;
    }
    if (typeof value === 'string') {
      try {
        const parsed = JSON.parse(value);
        if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
          return 'Value must be a valid JSON object';
        }
      } catch {
        return 'Invalid JSON syntax';
      }
    }
    if (typeof value !== 'object' || Array.isArray(value)) {
      return 'Value must be a valid JSON object';
    }
    return null;
  },
  editable: true,
  clearable: true
});
//# sourceMappingURL=index.js.map