import { jsx as _jsx } from "react/jsx-runtime";
import { CircleInfo, TrashBin } from '@gravity-ui/icons';
import { Plugin } from 'prosemirror-state';
import { i18n } from "../../../../../i18n/yfm-note/index.js";
import { BaseTooltipPluginView } from "../../../../../plugins/BaseTooltip/index.js";
import { Toolbar, ToolbarDataType } from "../../../../../toolbar/index.js";
import { removeNode } from "../../../../../utils/remove-node.js";
import { noteType } from "../../../index.js";
import "./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,
    }));
};
export const yfmNoteTooltipPlugin = ({ actions, schema }) => new Plugin({
    view(view) {
        return new BaseTooltipPluginView(view, {
            idPrefix: 'yfm-note-tooltip',
            nodeType: noteType(view.state.schema),
            popupPlacement: ['bottom', 'top'],
            content: (view, { node, pos }) => (_jsx(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: CircleInfo },
                        title: i18n(type),
                        type: 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: TrashBin },
                            title: i18n('remove'),
                            type: ToolbarDataType.SingleButton,
                            isActive,
                            isEnable,
                            exec: () => removeNode({
                                pos: pos,
                                node: node,
                                tr: view.state.tr,
                                dispatch: view.dispatch.bind(view),
                            }),
                        },
                    ],
                ] })),
        });
    },
});
//# sourceMappingURL=index.js.map
