import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2024-2026 GoodData Corporation
import { forwardRef } from "react";
import { simplifyText } from "@gooddata/util";
import { accessibilityConfigToAttributes } from "../../typings/utilities.js";
import { bem } from "../@utils/bem.js";
import { UiIcon } from "../UiIcon/UiIcon.js";
const { b, e } = bem("gd-ui-kit-button");
const getGeneratedTestId = (label, ariaLabel) => {
    return ariaLabel ? `${simplifyText(ariaLabel)}` : `${simplifyText(label)}`;
};
/**
 * @internal
 */
export const UiButton = forwardRef(({ id, size = "medium", variant = "secondary", tabIndex = 0, label, isDisabled, isSelected, isLoading, disableIconAnimation, iconBefore, iconBeforeSize: iconBeforeSizeProp, iconAfter, iconAfterSize: iconAfterSizeProp, badgeAfter, onClick, onKeyDown, dataId, dataTestId, accessibilityConfig, maxWidth, autoFocus, }, ref) => {
    const iconBeforeSize = iconBeforeSizeProp ?? (size === "small" ? 16 : 18);
    const iconAfterSize = iconAfterSizeProp ?? (size === "small" ? 16 : 18);
    const hasIconBefore = !!iconBefore;
    const hasIconAfter = !!iconAfter;
    const testId = dataTestId || getGeneratedTestId(label, accessibilityConfig?.ariaLabel ?? "");
    return (_jsxs("button", { id: id, ref: ref, className: b({
            size,
            variant,
            isLoading: isLoading ?? false,
            hasIconBefore,
            hasIconAfter,
            isSelected: isSelected ?? false,
        }), disabled: isDisabled, tabIndex: tabIndex, autoFocus: autoFocus, onClick: onClick, onKeyDown: onKeyDown, "data-id": dataId, "data-testid": testId, ...accessibilityConfigToAttributes(accessibilityConfig), children: [iconBefore ? (_jsx(UiIcon, { type: iconBefore, size: iconBeforeSize, accessibilityConfig: { ariaHidden: accessibilityConfig?.iconAriaHidden }, disableAnimation: disableIconAnimation })) : null, _jsx("span", { className: e("text"), style: { maxWidth }, children: label }), badgeAfter !== undefined && typeof badgeAfter === "number" ? (_jsxs("span", { className: e("badge"), children: ["(", badgeAfter, ")"] })) : null, badgeAfter !== undefined && typeof badgeAfter === "string" ? (_jsx("span", { className: e("badge"), children: badgeAfter })) : null, iconAfter ? (_jsx(UiIcon, { type: iconAfter, size: iconAfterSize, accessibilityConfig: { ariaHidden: accessibilityConfig?.iconAriaHidden }, disableAnimation: disableIconAnimation })) : null] }));
});
UiButton.displayName = "UiButton";
