/**
 * DevExtreme (cjs/__internal/ui/html_editor/formats/m_mention.js)
 * Version: 23.2.9 (build 24294-0112)
 * Build date: Sun Oct 20 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.default = void 0;
var _renderer = _interopRequireDefault(require("../../../../core/renderer"));
var _devextremeQuill = _interopRequireDefault(require("devextreme-quill"));
var _m_templates_storage = _interopRequireDefault(require("../utils/m_templates_storage"));

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}

function _inheritsLoose(subClass, superClass) {
    subClass.prototype = Object.create(superClass.prototype);
    subClass.prototype.constructor = subClass;
    _setPrototypeOf(subClass, superClass)
}

function _setPrototypeOf(o, p) {
    _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
        o.__proto__ = p;
        return o
    };
    return _setPrototypeOf(o, p)
}
let Mention = {};
if (_devextremeQuill.default) {
    const Embed = _devextremeQuill.default.import("blots/embed");
    const MENTION_CLASS = "dx-mention";
    Mention = function(_Embed) {
        _inheritsLoose(Mention, _Embed);

        function Mention(scroll, node) {
            var _this;
            _this = _Embed.call(this, scroll, node) || this;
            _this.renderContent(_this.contentNode, Mention.value(node));
            return _this
        }
        Mention.create = function(data) {
            const node = _Embed.create.call(this);
            node.setAttribute("spellcheck", false);
            node.dataset.marker = data.marker;
            node.dataset.mentionValue = data.value;
            node.dataset.id = data.id;
            return node
        };
        Mention.value = function(node) {
            return {
                marker: node.dataset.marker,
                id: node.dataset.id,
                value: node.dataset.mentionValue
            }
        };
        var _proto = Mention.prototype;
        _proto.renderContent = function(node, data) {
            const template = Mention._templatesStorage.get({
                editorKey: data.keyInTemplateStorage,
                marker: data.marker
            });
            if (template) {
                template.render({
                    model: data,
                    container: node
                })
            } else {
                this.baseContentRender(node, data)
            }
        };
        _proto.baseContentRender = function(node, data) {
            const $marker = (0, _renderer.default)("<span>").text(data.marker);
            (0, _renderer.default)(node).append($marker).append(data.value)
        };
        Mention.addTemplate = function(data, template) {
            this._templatesStorage.set(data, template)
        };
        Mention.removeTemplate = function(data) {
            this._templatesStorage.delete(data)
        };
        return Mention
    }(Embed);
    Mention.blotName = "mention";
    Mention.tagName = "span";
    Mention.className = MENTION_CLASS;
    Mention._templatesStorage = new _m_templates_storage.default
}
var _default = Mention;
exports.default = _default;
