'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _tslib = require('../../_virtual/_tslib.js');
var React = require('react');
var styles = require('./styles.js');
var index = require('../Spinner/index.js');
var utils = require('./utils.js');
var Placeholder = require('../../icons/Placeholder.js');
var useHasFocus = require('../../hooks/useHasFocus.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

function IconButton(_a) {
    var { variant = 'primary', icon = React__default['default'].createElement(Placeholder['default'], null), size = 'large', className, disabled = false, isLoading = false, type = 'button', onClick } = _a, props = _tslib.__rest(_a, ["variant", "icon", "size", "className", "disabled", "isLoading", "type", "onClick"]);
    const loadingSize = utils.getSpinnerSize(size) || 'L';
    const spinnerVariant = utils.getSpinnerType(variant) || 'brand';
    const ref = React.useRef(null);
    const { hasFocus, setHasFocus } = useHasFocus.useHasFocus(ref);
    return (React__default['default'].createElement(styles.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['default'].createElement(index.Spinner, { variant: spinnerVariant, size: loadingSize })) : (icon)));
}

exports.IconButton = IconButton;
