var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from "react";
import { Tooltip } from "../tooltip";
import { ADPIcon } from "../adpIcon";
import { cn } from "@utils";
import { buttonVariants } from "./buttonVariants";
export const colors = ["primary", "secondary", "success", "warning", "error"];
export const variants = ["filled", "outline", "shade", "text"];
export var ESizes;
(function (ESizes) {
    ESizes["XS"] = "xs";
    ESizes["SM"] = "sm";
    ESizes["MD"] = "md";
    ESizes["LG"] = "lg";
    ESizes["XL"] = "xl";
})(ESizes || (ESizes = {}));
// Map of button size to spinner size
export const ButtonSizeToSpinnerMap = {
    xs: "xs",
    sm: "xs",
    md: "sm",
    lg: "sm",
    xl: "md"
};
/**
 * Button component with multiple variants, colors, and sizes.
 *
 * @example
 * ```tsx
 * <Button variant="filled" color="primary" size="md">
 *   Click me
 * </Button>
 * ```
 */
export const Button = React.forwardRef((_a, ref) => {
    var { className, variant = "filled", color = "primary", size = "md", children, disabled, loading = false, type = "button", prefixIcon, suffixIcon, tooltip, tooltipPlacement } = _a, props = __rest(_a, ["className", "variant", "color", "size", "children", "disabled", "loading", "type", "prefixIcon", "suffixIcon", "tooltip", "tooltipPlacement"]);
    // Determine if we should show padded styles based on whether children exist
    const hasChildren = Boolean(children);
    // Create the button element
    const buttonElement = (_jsxs("button", Object.assign({ type: type, className: cn(buttonVariants({
            variant,
            color,
            size,
            hasChildren: hasChildren ? true : undefined
        }), className), disabled: disabled || loading, ref: ref }, props, { children: [loading ? (_jsx(ADPIcon, { icon: "spinner", spin: true, size: ButtonSizeToSpinnerMap[size] })) : (prefixIcon && (typeof prefixIcon === "string"
                ? _jsx(ADPIcon, { icon: prefixIcon, fixedWidth: true, size: ButtonSizeToSpinnerMap[size] })
                : prefixIcon)), children, suffixIcon && (typeof suffixIcon === "string"
                ? _jsx(ADPIcon, { icon: suffixIcon, fixedWidth: true, size: ButtonSizeToSpinnerMap[size] })
                : suffixIcon)] })));
    // If tooltip is present and not null or empty, wrap the button with Tooltip.
    if (tooltip !== null && tooltip !== undefined && tooltip !== false && tooltip !== "") {
        return (_jsx(Tooltip, { clickable: false, trigger: buttonElement, triggerAriaLabel: typeof tooltip === "string" ? tooltip : undefined, disabled: disabled, placement: tooltipPlacement, children: tooltip }));
    }
    // Otherwise, return just the button
    return buttonElement;
});
Button.displayName = "Button";
//# sourceMappingURL=button.js.map