"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.entityIdAttr = void 0;
exports.generateEntityId = generateEntityId;
exports.isInvalidEntityId = isInvalidEntityId;
const uuid_1 = require("uuid");
const descedants_1 = require("./descedants.js");
exports.entityIdAttr = 'data-entity-id';
function generateEntityId(name = 'entity') {
    return name + '-' + (0, uuid_1.v4)();
}
/**
 * Returns true when entityId is not set, is set to default value, or is duplicated (other node already has this entityId)
 */
function isInvalidEntityId({ doc, node, defaultId, }) {
    const entityId = node.attrs[exports.entityIdAttr];
    if (!entityId || entityId === defaultId)
        return true;
    return Boolean((0, descedants_1.findFirstDescedantNode)(doc, (dNode) => node !== dNode && dNode.attrs[exports.entityIdAttr] === entityId));
}
//# sourceMappingURL=entity-id.js.map
