"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StartInsurableTransactionButton = exports.StartTransactionButton = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const DefaultTransactionButton_1 = require("../../components/DefaultTransactionButton");
const hooks_1 = require("../../hooks");
const providers_1 = require("../../providers");
const stores_1 = require("../../stores");
const StartTransactionButton = ({ onClick, route, text, loading, }) => {
    const { sdkConfig } = (0, providers_1.useWidgetConfig)();
    const isMultisigSigner = sdkConfig?.multisigConfig?.isMultisigSigner;
    const { insufficientGas, isInitialLoading: isGasSufficiencyLoading } = (0, hooks_1.useGasSufficiency)(route);
    const { insufficientFunds, isInitialLoading: isFundsSufficiencyLoading } = (0, hooks_1.useFundsSufficiency)(route);
    const shouldDisableButton = !isMultisigSigner && (insufficientFunds || !!insufficientGas?.length);
    return ((0, jsx_runtime_1.jsx)(DefaultTransactionButton_1.DefaultTransactionButton, { onClick: onClick, text: text, disabled: shouldDisableButton, loading: isFundsSufficiencyLoading || isGasSufficiencyLoading || loading }));
};
exports.StartTransactionButton = StartTransactionButton;
const StartInsurableTransactionButton = ({ onClick, text, route, loading, disabled, insurableRouteId }) => {
    const routeExecution = (0, stores_1.useRouteExecutionStore)((state) => state.routes[insurableRouteId]);
    const { isFetching } = (0, hooks_1.useRoutes)({
        insurableRoute: routeExecution?.route,
    });
    return ((0, jsx_runtime_1.jsx)(exports.StartTransactionButton, { onClick: onClick, text: text, route: route, disabled: disabled, loading: loading || isFetching, insurableRouteId: insurableRouteId }));
};
exports.StartInsurableTransactionButton = StartInsurableTransactionButton;
