import { jsx as _jsx } from "react/jsx-runtime";
import { LoadingButton } from '@mui/lab';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { useWallet, useWidgetConfig } from '../../providers';
import { navigationRoutes } from '../../utils';
export const DefaultTransactionButton = ({ onClick, text, disabled, loading }) => {
    const { t } = useTranslation();
    const navigate = useNavigate();
    const { walletManagement } = useWidgetConfig();
    const { account, connect } = useWallet();
    const handleClick = async () => {
        if (account.isActive) {
            onClick?.();
        }
        else if (walletManagement) {
            await connect();
        }
        else {
            navigate(navigationRoutes.selectWallet);
        }
    };
    const getButtonText = () => {
        if (account.isActive) {
            if (text) {
                return text;
            }
        }
        return t(`button.connectWallet`);
    };
    if (account.isActive) {
        return (_jsx(LoadingButton, { variant: "contained", color: "primary", onClick: handleClick, disabled: disabled, loading: loading, loadingPosition: "center", fullWidth: true, style: {
                fontSize: '18px',
                fontWeight: 'bold',
                textTransform: 'uppercase',
                borderRadius: '20px',
                padding: '1rem 1.25rem'
            }, children: getButtonText() }));
    }
    return (_jsx(LoadingButton, { variant: "contained", color: "info", onClick: handleClick, disabled: disabled, loading: loading, loadingPosition: "center", fullWidth: true, style: {
            fontSize: '18px',
            fontWeight: 'bold',
            textTransform: 'uppercase',
            borderRadius: '20px',
            padding: '1rem 1.25rem'
        }, children: getButtonText() }));
};
