import { jsx } from "react/jsx-runtime";
import { getLighterColor } from "../../../utils/index.js";
import { memo } from "react";
import { CanvasIcon } from "../../../utils/icon-registry.js";
import { CanvasTooltip } from "../../CanvasTooltip.js";
import { ToolbarIconButton } from "./ToolbarIconButton.js";
const ToolbarButton = /*#__PURE__*/ memo(({ action, layoutId })=>{
    const isEnabled = !action.disabled;
    const hoverBg = action.color ? getLighterColor(action.color) : void 0;
    const handleClick = (e)=>{
        e.stopPropagation();
        e.preventDefault();
        if (isEnabled) action.onClick();
    };
    return /*#__PURE__*/ jsx(CanvasTooltip, {
        content: action.label,
        placement: "top",
        children: /*#__PURE__*/ jsx(ToolbarIconButton, {
            layout: layoutId ? true : void 0,
            layoutId: layoutId,
            transition: {
                type: 'tween',
                duration: 0.2,
                ease: 'easeOut'
            },
            type: "button",
            className: "nodrag nopan",
            onClick: handleClick,
            "aria-label": action.label,
            "aria-disabled": !isEnabled,
            "aria-pressed": action.isToggled,
            disabled: !isEnabled,
            isToggled: action.isToggled,
            color: action.color,
            hoverBg: hoverBg,
            children: action.icon && 'string' == typeof action.icon ? /*#__PURE__*/ jsx(CanvasIcon, {
                icon: action.icon,
                size: 16,
                color: action.color
            }) : action.icon
        })
    });
});
ToolbarButton.displayName = 'ToolbarButton';
export { ToolbarButton };
