/**
 * DevExtreme (cjs/ui/html_editor/formats/mention.js)
 * Version: 23.1.6 (build 23316-0110)
 * Build date: Sun Nov 12 2023
 *
 * Copyright (c) 2012 - 2023 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.default = void 0;
var _devextremeQuill = _interopRequireDefault(require("devextreme-quill"));
var _renderer = _interopRequireDefault(require("../../../core/renderer"));
var _templates_storage = _interopRequireDefault(require("../utils/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)
}
var Mention = {};
if (_devextremeQuill.default) {
    var Embed = _devextremeQuill.default.import("blots/embed");
    var 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) {
            var 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) {
            var 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) {
            var $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 _templates_storage.default
}
var _default = Mention;
exports.default = _default;
module.exports = exports.default;
module.exports.default = exports.default;
