import { Dropdown } from "antd";
import classNames from "clsx";
import React from "react";
import { ToolBarItem } from "./ToolBarItem";
var HeadingLocaleKeyMap = {
    1: 'largeTitle',
    2: 'paragraphTitle',
    3: 'smallTitle',
    4: 'bodyText',
    Text: 'bodyText'
};
var getHeadingText = function getHeadingText(i18n, level) {
    var _i18n_locale;
    var localeKey = HeadingLocaleKeyMap[level];
    return (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale = i18n.locale) === null || _i18n_locale === void 0 ? void 0 : _i18n_locale[localeKey]) || localeKey;
};
export var HeadingDropdown = /*#__PURE__*/ React.memo(function(param) {
    var baseClassName = param.baseClassName, hashId = param.hashId, i18n = param.i18n, node = param.node, hideTools = param.hideTools, onHeadingChange = param.onHeadingChange;
    var _i18n_locale;
    var headingItems = React.useMemo(function() {
        return [
            'H1',
            'H2',
            'H3',
            'Text'
        ].map(function(item, index) {
            if (hideTools === null || hideTools === void 0 ? void 0 : hideTools.includes(item)) {
                return null;
            }
            var level = item === 'Text' ? 'Text' : Number(item.slice(1));
            return {
                label: getHeadingText(i18n, level),
                key: "head-".concat(item),
                onClick: function onClick() {
                    return onHeadingChange(index + 1);
                }
            };
        }).filter(Boolean);
    }, [
        hideTools,
        i18n,
        onHeadingChange
    ]);
    var currentText = React.useMemo(function() {
        var _node_;
        if (node === null || node === void 0 ? void 0 : (_node_ = node[0]) === null || _node_ === void 0 ? void 0 : _node_.level) {
            return getHeadingText(i18n, node[0].level);
        }
        return getHeadingText(i18n, 'Text');
    }, [
        i18n,
        node
    ]);
    return /*#__PURE__*/ React.createElement(Dropdown, {
        menu: {
            items: headingItems
        }
    }, /*#__PURE__*/ React.createElement(ToolBarItem, {
        title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale = i18n.locale) === null || _i18n_locale === void 0 ? void 0 : _i18n_locale.heading) || '标题',
        icon: null,
        className: classNames("".concat(baseClassName, "-item"), hashId),
        style: {
            minWidth: 36,
            textAlign: 'center',
            fontSize: 12,
            justifyContent: 'center',
            lineHeight: 1
        }
    }, currentText));
});
HeadingDropdown.displayName = 'HeadingDropdown';
