import classNames from '../../../../../../_virtual/index.mjs';
import React__default from 'react';
import modules_b0070f27 from './Button.module.css.mjs';
import { CircularProgress } from './CircularProgress.mjs';

function buttonClassNames({ variant, block = true }) {
    return classNames(modules_b0070f27.button, modules_b0070f27[variant], {
        [modules_b0070f27.block]: block
    });
}
// Base renderer for both <a> and <button> based <Button>s
const baseButton = (props)=>{
    const { as, children, icon, onClick, loading, disabled = loading, block, variant, ...otherProps } = props;
    const Element = as;
    let buttonContent = /*#__PURE__*/ React__default.createElement(React__default.Fragment, null, icon, /*#__PURE__*/ React__default.createElement("span", null, children));
    if (loading) {
        buttonContent = /*#__PURE__*/ React__default.createElement(CircularProgress, {
            size: 20
        });
    }
    return /*#__PURE__*/ React__default.createElement(Element, {
        className: buttonClassNames(props),
        onClick: onClick,
        disabled: disabled,
        ...otherProps
    }, buttonContent);
};
const Button = (props)=>baseButton({
        type: 'button',
        as: 'button',
        ...props
    });
const ButtonAnchor = (props)=>baseButton({
        ...props,
        // Links don't fire click event on space while buttons do, so we implement that ourselves for these
        // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/button_role#accessibility_concerns
        onKeyDown: (evt)=>{
            props.onKeyDown?.(evt);
            if (evt.defaultPrevented) return;
            if (evt.key === ' ') evt.currentTarget.click();
        },
        as: 'a'
    });

export { ButtonAnchor, buttonClassNames, Button as default };
//# sourceMappingURL=Button.mjs.map
