"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.yfmNoteTooltipPlugin = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const icons_1 = require("@gravity-ui/icons");
const prosemirror_state_1 = require("prosemirror-state");
const yfm_note_1 = require("../../../../../i18n/yfm-note/index.js");
const BaseTooltip_1 = require("../../../../../plugins/BaseTooltip/index.js");
const toolbar_1 = require("../../../../../toolbar/index.js");
const remove_node_1 = require("../../../../../utils/remove-node.js");
const index_1 = require("../../../index.js");
require("./index.css");
var YfmNoteType;
(function (YfmNoteType) {
    YfmNoteType["tip"] = "tip";
    YfmNoteType["info"] = "info";
    YfmNoteType["warning"] = "warning";
    YfmNoteType["alert"] = "alert";
})(YfmNoteType || (YfmNoteType = {}));
const isEnable = () => true;
const isActive = () => false;
const changeType = (type) => ({ node, pos, dispatch, tr }) => {
    dispatch(tr.setNodeMarkup(pos, null, {
        ...node.attrs,
        class: `yfm-note yfm-accent-${type}`,
        'note-type': type,
    }));
};
const yfmNoteTooltipPlugin = ({ actions, schema }) => new prosemirror_state_1.Plugin({
    view(view) {
        return new BaseTooltip_1.BaseTooltipPluginView(view, {
            idPrefix: 'yfm-note-tooltip',
            nodeType: (0, index_1.noteType)(view.state.schema),
            popupPlacement: ['bottom', 'top'],
            content: (view, { node, pos }) => ((0, jsx_runtime_1.jsx)(toolbar_1.Toolbar, { editor: actions, focus: () => view.focus(), 
                // the yfm class allows to access css variables
                // https://github.com/diplodoc-platform/transform/blob/master/src/scss/_common.scss#L17
                className: "yfm g-md-yfm-note-toolbar", qa: "g-md-toolbar-yfm-note", data: [
                    [
                        YfmNoteType.info,
                        YfmNoteType.tip,
                        YfmNoteType.warning,
                        YfmNoteType.alert,
                    ].map((type) => ({
                        id: `note-type-${type}`,
                        icon: { data: icons_1.CircleInfo },
                        title: (0, yfm_note_1.i18n)(type),
                        type: toolbar_1.ToolbarDataType.SingleButton,
                        isActive,
                        isEnable,
                        exec: () => changeType(type)({
                            schema,
                            pos: pos,
                            node: node,
                            tr: view.state.tr,
                            dispatch: view.dispatch.bind(view),
                        }),
                    })),
                    [
                        {
                            id: 'note-remove',
                            icon: { data: icons_1.TrashBin },
                            title: (0, yfm_note_1.i18n)('remove'),
                            type: toolbar_1.ToolbarDataType.SingleButton,
                            isActive,
                            isEnable,
                            exec: () => (0, remove_node_1.removeNode)({
                                pos: pos,
                                node: node,
                                tr: view.state.tr,
                                dispatch: view.dispatch.bind(view),
                            }),
                        },
                    ],
                ] })),
        });
    },
});
exports.yfmNoteTooltipPlugin = yfmNoteTooltipPlugin;
//# sourceMappingURL=index.js.map
