"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "ActionButton", {
    enumerable: true,
    get: function() {
        return ActionButton;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _button = /*#__PURE__*/ _interop_require_default(require("../../../button"));
const _react = require("react");
const _approveButton = require("./approveButton");
const _notice = require("./notice");
const _modal = require("../../../modal");
const _hooks = require("@orderly.network/hooks");
const _chainDialog = require("../../../block/pickers/chainPicker/chainDialog");
const _accountStatus = require("../../../block/accountStatus");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const ActionButton = (props)=>{
    const { chain, token, chains, onDeposit, switchChain, disabled, quantity, loading, allowance, onApprove, submitting, maxQuantity, warningMessage, chainNotSupport } = props;
    const [_, { findByChainId }] = (0, _hooks.useChains)(undefined, {
        pick: "network_infos",
        filter: (chain)=>chain.network_infos?.bridge_enable || chain.network_infos?.bridgeless
    });
    const onOpenPicker = async ()=>{
        const result = await _modal.modal.show(_chainDialog.ChainDialog, {
            testChains: chains,
            currentChainId: chain?.id
        });
        if (result?.id) {
            const chainInfo = findByChainId(result.id);
            props?.onChainChange?.(chainInfo);
        }
    };
    const chainWarningMessage = (0, _react.useMemo)(()=>{
        if (!chainNotSupport) return "";
        return "Please connect to a supported network.";
    }, [
        chainNotSupport,
        chain?.info?.network_infos?.name
    ]);
    const actionButton = (0, _react.useMemo)(()=>{
        if (!chainNotSupport) {
            return /*#__PURE__*/ (0, _jsxruntime.jsx)(_accountStatus.StatusGuardButton, {
                children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_approveButton.ApproveButton, {
                    onApprove: props.onApprove,
                    onDeposit: onDeposit,
                    allowance: allowance,
                    quantity: quantity,
                    submitting: submitting,
                    maxQuantity: maxQuantity,
                    token: token?.symbol,
                    label: "Deposit",
                    disabled: disabled,
                    buttonId: "orderly-deposit-confirm-button"
                })
            });
        }
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_button.default, {
            fullWidth: true,
            onClick: onOpenPicker,
            id: "orderly-deposit-confirm-button",
            className: "desktop:orderly-text-xs",
            children: "Switch network"
        });
    }, [
        chainNotSupport,
        switchChain,
        disabled,
        chain,
        quantity,
        loading,
        allowance,
        onApprove,
        onDeposit,
        submitting,
        maxQuantity
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                className: "orderly-deposit-warning-message",
                children: chainNotSupport ? /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                    className: "orderly-text-warning orderly-text-4xs orderly-text-center orderly-px-[20px] orderly-pt-4 orderly-pb-3 desktop:orderly-text-2xs ",
                    children: chainWarningMessage
                }) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_notice.Notice, {
                    warningMessage: warningMessage
                })
            }),
            /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                className: "orderly-flex orderly-justify-center",
                children: /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                    className: "orderly-deposit-action-button-container orderly-w-full orderly-text-xs orderly-font-bold",
                    children: actionButton
                })
            })
        ]
    });
};

//# sourceMappingURL=actionButton.js.map