import { __rest } from '../../_virtual/_tslib.js';
import React__default, { useRef } from 'react';
import { IconButtonContainer } from './styles.js';
import { Spinner } from '../Spinner/index.js';
import { getSpinnerSize, getSpinnerType } from './utils.js';
import Placeholder from '../../icons/Placeholder.js';
import { useHasFocus } from '../../hooks/useHasFocus.js';

function IconButton(_a) {
    var { variant = 'primary', icon = React__default.createElement(Placeholder, null), size = 'large', className, disabled = false, isLoading = false, type = 'button', onClick } = _a, props = __rest(_a, ["variant", "icon", "size", "className", "disabled", "isLoading", "type", "onClick"]);
    const loadingSize = getSpinnerSize(size) || 'L';
    const spinnerVariant = getSpinnerType(variant) || 'brand';
    const ref = useRef(null);
    const { hasFocus, setHasFocus } = useHasFocus(ref);
    return (React__default.createElement(IconButtonContainer, { hasFocus: hasFocus, ref: ref, variant: variant, size: size, className: className, isLoading: isLoading, disabled: disabled, type: type, onClick: onClick, "data-testid": props['data-testid'], "data-trackid": props['data-trackid'], "aria-label": props['aria-label'], onBlur: () => setHasFocus(false) }, isLoading ? (React__default.createElement(Spinner, { variant: spinnerVariant, size: loadingSize })) : (icon)));
}

export { IconButton };
