"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarkupManager = void 0;
const uuid_1 = require("uuid");
const utils_1 = require("../utils/index.js");
class MarkupManager extends utils_1.SafeEventEmitter {
    _markups = new Map();
    _nodes = new Map();
    _namespace;
    logger;
    constructor(logger) {
        super();
        this.logger = logger;
        this._namespace = (0, uuid_1.v4)();
    }
    /**
     * Set raw markup for a specific id
     */
    setMarkup(id, rawMarkup) {
        if (typeof rawMarkup !== 'string') {
            this.logger.warn('[MarkupManager] rawMarkup must be a string');
            return;
        }
        this._markups.set(id, rawMarkup);
        this.emit('markupChanged', { id, rawMarkup });
        this.logger.log(`[MarkupManager] Raw markup for ID ${id} set successfully`);
    }
    /**
     * Set a node for a specific id
     */
    setNode(id, node) {
        if (!node) {
            this.logger.warn('[MarkupManager] Node must be a valid ProseMirror Node');
            return;
        }
        this._nodes.set(id, node);
        this.emit('nodeChanged', { id, node });
        this.logger.log(`[MarkupManager] Node for ID ${id} set successfully`);
    }
    /**
     * Get raw markup for a specific id
     */
    getMarkup(id) {
        return this._markups.get(id) ?? null;
    }
    /**
     * Get a node for a specific id
     */
    getNode(id) {
        return this._nodes.get(id) ?? null;
    }
    getNamespace() {
        return this._namespace;
    }
    /**
     * Reset the stored markups and nodes
     */
    reset() {
        this._markups.clear();
        this._nodes.clear();
        this.emit('reset', {});
        this.logger.log('[MarkupManager] MarkupManager has been reset');
    }
}
exports.MarkupManager = MarkupManager;
//# sourceMappingURL=MarkupManager.js.map
