"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MainIconButton = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const ConfirmAction_1 = require("../../../../ConfirmAction");
const Tooltip_1 = require("../../../../Tooltip");
const cva_1 = require("../../../../utils/cva");
const constants_1 = require("./constants");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
const iconButtonCva = (0, cva_1.cva)(constants_1.mainIconButtonClassnames.root, {
    variants: {
        isMobilePrimary: {
            true: constants_1.mainIconButtonClassnames.primaryButton,
        },
    },
});
const MainIconButton = (props) => {
    const { tooltipProps } = (0, useLogic_1.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) => ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { withoutContainer: !disabled, placement: tooltipPlacement, ...tooltipProps, children: (0, jsx_runtime_1.jsx)(styles_1.StyledIconButton, { disabled: isDisabled || disabled, loading: loading, ...actions, variant: "text", ...renderProps, className: iconButtonCva({ isMobilePrimary }), children: icon }) }, name));
    return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: needConfirm ? ((0, jsx_runtime_1.jsx)(ConfirmAction_1.ConfirmAction, { text: confirmText, confirmButtonProps: confirmButtonProps, actionComponent: (renderProps) => renderButton(renderProps), onConfirm: onActionClick(onClick) })) : (renderButton({
            onClick: onActionClick(onClick),
        })) }));
};
exports.MainIconButton = MainIconButton;
