import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { ConfirmAction, } from '../../../../ConfirmAction';
import { Tooltip } from '../../../../Tooltip';
import { cva } from '../../../../utils/cva';
import { mainIconButtonClassnames } from './constants';
import { StyledIconButton } from './styles';
import { useLogic } from './useLogic';
const iconButtonCva = cva(mainIconButtonClassnames.root, {
    variants: {
        isMobilePrimary: {
            true: mainIconButtonClassnames.primaryButton,
        },
    },
});
export const MainIconButton = (props) => {
    const { tooltipProps } = useLogic(props);
    const { action, onActionClick, isDisabled, tooltipPlacement } = props;
    const { name, icon, needConfirm, confirmText, confirmButtonProps, disabledReason, disabled, loading, isBlockingOperation, loadingNote, onClick, isMobilePrimary, ...actions } = action;
    const renderButton = (renderProps) => (_jsx(Tooltip, { withoutContainer: !disabled, placement: tooltipPlacement, ...tooltipProps, children: _jsx(StyledIconButton, { disabled: isDisabled || disabled, loading: loading, ...actions, variant: "text", ...renderProps, className: iconButtonCva({ isMobilePrimary }), children: icon }) }, name));
    return (_jsx(_Fragment, { children: needConfirm ? (_jsx(ConfirmAction, { text: confirmText, confirmButtonProps: confirmButtonProps, actionComponent: (renderProps) => renderButton(renderProps), onConfirm: onActionClick(onClick) })) : (renderButton({
            onClick: onActionClick(onClick),
        })) }));
};
