"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolbarColors = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const classname_1 = require("../../../classname.js");
const extensions_1 = require("../../../extensions/index.js");
const menubar_1 = require("../../../i18n/menubar/index.js");
const icons_1 = require("../../config/icons.js");
const ToolbarButtonWithPopupMenu_1 = require("../ToolbarButtonWithPopupMenu.js");
require("./ToolbarColors.css");
const b = (0, classname_1.cn)('toolbar-colors');
const textColorIcon = icons_1.icons.textColor;
const ToolbarColors = (props) => {
    const { exec, onClick, enable, currentColor, withDefault } = props;
    const isDefault = currentColor === undefined;
    const onItemClick = (color) => () => {
        // do not exec when current color is default and clicked to default item
        if (!(isDefault && color === ''))
            exec(color);
        onClick?.('colorify', { color: color === '' ? 'default' : color });
    };
    const items = [
        extensions_1.Colors.Gray,
        extensions_1.Colors.Yellow,
        extensions_1.Colors.Orange,
        extensions_1.Colors.Red,
        extensions_1.Colors.Green,
        extensions_1.Colors.Blue,
        extensions_1.Colors.Violet,
    ].map((color) => ({
        id: color,
        icon: textColorIcon.data,
        iconSize: textColorIcon.size ?? 16,
        text: (0, menubar_1.i18n)(`colorify__color_${color}`),
        iconClassname: b('item-icon', { color }),
        action: {
            run: onItemClick(color),
            isEnable: () => Boolean(enable),
            isActive: () => color === currentColor,
            meta() { },
        },
        group: (0, menubar_1.i18n)(`colorify__group_text`),
    }));
    if (withDefault) {
        items.unshift({
            id: 'default',
            icon: textColorIcon.data,
            iconSize: textColorIcon.size ?? 16,
            text: (0, menubar_1.i18n)(`colorify__color_default`),
            iconClassname: b('item-icon', { color: 'default' }),
            group: (0, menubar_1.i18n)(`colorify__group_text`),
            ignoreActive: true,
            action: {
                run: onItemClick(''),
                isEnable: () => Boolean(enable),
                isActive: () => isDefault,
                meta() { },
            },
        });
    }
    return ((0, jsx_runtime_1.jsx)(ToolbarButtonWithPopupMenu_1.ToolbarButtonWithPopupMenu, { ...props, title: (0, menubar_1.i18n)('colorify'), menuItems: items, icon: textColorIcon, _selectionType: "light", iconClassName: b('menu-icon', { color: currentColor }), chevronIconClassName: b('chevron-icon', { color: currentColor }) }));
};
exports.ToolbarColors = ToolbarColors;
//# sourceMappingURL=ToolbarColors.js.map
