import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useCallback, useContext, useMemo } from "react";
import { AccountStatusBar } from "../../../../../block/accountStatus";
import { WsStatus } from "../../../../../block/accountStatus/sections/WsStatus";
import { ChainIdSwtich } from "../../../../../block/accountStatus/sections/chainIdSwitch";
import { GetTestUSDC } from "../../../../../block/operation/getTestUSDC";
import { WalletConnectSheet } from "../../../../../block/walletConnect";
import { modal } from "../../../../../modal";
import { OrderlyAppContext } from "../../../../../provider";
import { useAccount, useCollateral, useAccountInfo, useWalletConnector, StatusContext, WsNetworkStatus } from "@orderly.network/hooks";
import { AccountStatusEnum } from "@orderly.network/types";
import { isTestnet } from "@orderly.network/utils";
export const BottomNavBar = (props)=>{
    const { state } = useAccount();
    const { data } = useAccountInfo();
    const { totalValue } = useCollateral();
    const { errors } = useContext(OrderlyAppContext);
    const { ws: wsStatus } = useContext(StatusContext);
    const { onWalletConnect, onSetChain, onWalletDisconnect } = useContext(OrderlyAppContext);
    const { connectedChain } = useWalletConnector();
    const onConnect = useCallback(()=>{
        onWalletConnect().then((result)=>{
            if (result && result.status < AccountStatusEnum.EnableTrading) {
                modal.show(WalletConnectSheet, {
                    status: result.status
                });
            }
        });
    }, []);
    const showGetTestUSDC = useMemo(()=>{
        const chainId = connectedChain?.id;
        if (chainId === undefined) {
            return false;
        }
        return state.status === AccountStatusEnum.EnableTrading && // @ts-ignore
        isTestnet(parseInt(chainId));
    }, [
        state.status,
        connectedChain
    ]);
    return /*#__PURE__*/ _jsxs(_Fragment, {
        children: [
            wsStatus === WsNetworkStatus.Unstable ? /*#__PURE__*/ _jsx(WsStatus, {}) : errors?.ChainNetworkNotSupport && /*#__PURE__*/ _jsx(ChainIdSwtich, {
                onSetChain: onSetChain
            }),
            showGetTestUSDC && /*#__PURE__*/ _jsx(GetTestUSDC, {}),
            /*#__PURE__*/ _jsx("div", {
                id: "orderly-botom-bar-container",
                className: "orderly-fixed orderly-left-0 orderly-bottom-0 orderly-w-screen orderly-bg-base-800 orderly-p-[14px] orderly-pb-[20px] orderly-border-t orderly-border-base-contrast/10 orderly-z-30 orderly-h-[64px] orderly-flex orderly-justify-between orderly-items-center",
                children: /*#__PURE__*/ _jsx(AccountStatusBar, {
                    chains: [],
                    status: state.status,
                    address: state.address,
                    accountInfo: data,
                    totalValue: totalValue,
                    onConnect: onConnect,
                    onDisconnect: onWalletDisconnect,
                    showGetTestUSDC: showGetTestUSDC
                })
            })
        ]
    });
};

//# sourceMappingURL=index.js.map