import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2024-2025 GoodData Corporation
import { forwardRef } from "react";
import { stringUtils } from "@gooddata/util";
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 ? `${stringUtils.simplifyText(ariaLabel)}` : `${stringUtils.simplifyText(label)}`;
};
/**
 * @internal
 */
export const UiButton = forwardRef(({ id, size = "medium", variant = "secondary", tabIndex = 0, label, isDisabled, isLoading, iconBefore, iconAfter, onClick, onKeyDown, dataId, dataTestId, accessibilityConfig, maxWidth, }, ref) => {
    const iconSize = 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, hasIconBefore, hasIconAfter }), disabled: isDisabled, tabIndex: tabIndex, onClick: onClick, onKeyDown: onKeyDown, "data-id": dataId, "data-testid": testId, "aria-label": accessibilityConfig?.ariaLabel, "aria-labelledby": accessibilityConfig?.ariaLabelledBy, "aria-describedby": accessibilityConfig?.ariaDescribedBy, "aria-expanded": accessibilityConfig?.ariaExpanded, role: accessibilityConfig?.role, children: [iconBefore ? (_jsx(UiIcon, { type: iconBefore, size: iconSize, ariaHidden: accessibilityConfig?.iconAriaHidden })) : null, _jsx("span", { className: e("text"), style: { maxWidth }, children: label }), iconAfter ? (_jsx(UiIcon, { type: iconAfter, size: iconSize, ariaHidden: accessibilityConfig?.iconAriaHidden })) : null] }));
});
UiButton.displayName = "UiButton";
//# sourceMappingURL=UiButton.js.map