"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createProseMirrorMetadata = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _model = require("@atlaskit/editor-prosemirror/model");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // Disable no-re-export rule for entry point files
/* eslint-disable @atlaskit/editor/no-re-export */
var isPMNode = function isPMNode(nodeOrMark) {
  return nodeOrMark instanceof _model.Node || Array.isArray(nodeOrMark.marks);
};

/**
 * 🧱 Internal Helper Function: Editor FE Platform
 *
 * Creates a set of generic metadata attributes for a ProseMirror node or mark.
 * These attributes are used to annotate the DOM representation with information
 * about the node or mark type.
 *
 * @param {PMNode | PMMark} nodeOrMark - The ProseMirror node or mark to create metadata for.
 * @returns {Record<string, string>} An object containing metadata attributes.
 *  - `data-prosemirror-content-type`: Specifies if the content is a node or mark.
 *  - `data-prosemirror-node-name` (if applicable): The name of the node.
 *  - `data-prosemirror-node-block` (if applicable): Indicates if the node is a block.
 *  - `data-prosemirror-node-inline` (if applicable): Indicates if the node is inline.
 *  - `data-prosemirror-mark-name` (if applicable): The name of the mark.
 */
var createProseMirrorMetadata = exports.createProseMirrorMetadata = function createProseMirrorMetadata(nodeOrMark, options) {
  var name = nodeOrMark.type.name;
  var isNode = isPMNode(nodeOrMark);
  var commonAttributes = {
    'data-prosemirror-content-type': isNode ? 'node' : 'mark'
  };
  if (!isNode) {
    return _objectSpread(_objectSpread({}, commonAttributes), {}, (0, _defineProperty2.default)({}, 'data-prosemirror-mark-name', name));
  }
  commonAttributes['data-prosemirror-node-name'] = name;
  if (nodeOrMark.type.isBlock) {
    commonAttributes['data-prosemirror-node-block'] = 'true';
  }
  if (nodeOrMark.type.isInline) {
    commonAttributes['data-prosemirror-node-inline'] = 'true';
  }
  if ((options === null || options === void 0 ? void 0 : options.anchrorId) !== undefined && (0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) {
    commonAttributes['data-node-anchor'] = options.anchrorId;
  }
  return commonAttributes;
};