text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.isDocumentListItem = isDocumentListItem;
  exports.DocumentListItemBuilder = void 0;
  
  var _ListItem = require("./ListItem");
  
  var _SerializeError = require("./SerializeError");
  
  var _Document = require("./Document");
  
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
  
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  var getDefaultChildResolver = spec => documentId => {
    var schemaType = spec.schemaType && (typeof spec.schemaType === 'string' ? spec.schemaType : spec.schemaType.name);
    return schemaType ? (0, _Document.getDefaultDocumentNode)({
      schemaType,
      documentId
    }) : new _Document.DocumentBuilder().id('documentEditor').documentId(documentId);
  };
  
  class DocumentListItemBuilder extends _ListItem.ListItemBuilder {
    constructor(spec) {
      super(spec);
  
      _defineProperty(this, "spec", void 0);
  
      this.spec = spec ? spec : {};
    }
  
    serialize() {
      var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
        path: []
      };
      var spec = super.serialize(_objectSpread(_objectSpread({}, options), {}, {
        titleIsOptional: true
      }));
  
      if (!spec.schemaType) {
        throw new _SerializeError.SerializeError('`schemaType` is required for document list items', options.path, options.index).withHelpUrl(_SerializeError.HELP_URL.SCHEMA_TYPE_REQUIRED);
      }
  
      var child = spec.child || getDefaultChildResolver(spec);
      return _objectSpread(_objectSpread({}, spec), {}, {
        child,
        schemaType: spec.schemaType,
        _id: spec.id
      });
    }
  
    clone(withSpec) {
      var builder = new DocumentListItemBuilder();
      builder.spec = _objectSpread(_objectSpread({}, this.spec), withSpec || {});
      return builder;
    }
  
  }
  
  exports.DocumentListItemBuilder = DocumentListItemBuilder;
  
  function isDocumentListItem(item) {
    var listItem = item;
    return typeof listItem.schemaType !== 'undefined' && typeof listItem._id === 'string';
  }