import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useContext, useMemo } from "react";
import { Sheet, SheetContent, SheetHeader, SheetTrigger } from "../../../sheet";
import { Divider } from "../../../divider";
import { AssetAndMarginSheet } from "./assetAndMargin";
import { Numeral } from "../../../text";
import { AccountStatusEnum } from "@orderly.network/types";
import { useMarginRatio } from "@orderly.network/hooks";
import { Logo } from "../../../logo";
import { AssetsContext } from "../../../provider/assetsProvider";
import { EyeIcon, EyeOffIcon } from "../../../icon";
import { OrderlyAppContext } from "../../../provider";
export const AccountTotal = (props)=>{
    const { currency = "USDC", accountInfo } = props;
    // @ts-ignore
    const { errors } = useContext(OrderlyAppContext);
    const { onDeposit, onWithdraw, onSettle, visible, toggleVisible } = useContext(AssetsContext);
    const { currentLeverage } = useMarginRatio();
    //
    const balance = useMemo(()=>{
        if (props.status < AccountStatusEnum.EnableTrading) {
            return "--";
        }
        return /*#__PURE__*/ _jsx(Numeral, {
            rule: "price",
            visible: visible,
            children: props.totalValue ?? 0
        });
    }, [
        props.status,
        props.totalValue,
        visible
    ]);
    const maxLerverage = useMemo(()=>{
        return accountInfo?.max_leverage ?? "-";
    }, [
        accountInfo
    ]);
    if (props.status < AccountStatusEnum.EnableTrading) {
        return /*#__PURE__*/ _jsx("div", {
            className: "orderly-flex orderly-items-center orderly-text-base-contrast-54 orderly-text-4xs",
            children: /*#__PURE__*/ _jsxs("div", {
                className: "orderly-flex orderly-flex-col",
                children: [
                    /*#__PURE__*/ _jsxs("div", {
                        className: "orderly-flex orderly-items-center orderly-gap-2",
                        children: [
                            /*#__PURE__*/ _jsx("span", {
                                children: "Total value"
                            }),
                            /*#__PURE__*/ _jsx("span", {
                                children: "≈"
                            })
                        ]
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: "orderly-flex orderly-gap-2",
                        children: [
                            "--",
                            /*#__PURE__*/ _jsx("span", {
                                className: "orderly-text-base-contrast-20",
                                children: currency
                            })
                        ]
                    })
                ]
            })
        });
    }
    return /*#__PURE__*/ _jsxs(Sheet, {
        children: [
            /*#__PURE__*/ _jsx(SheetTrigger, {
                asChild: true,
                children: /*#__PURE__*/ _jsxs("div", {
                    className: "orderly-flex orderly-items-center orderly-cursor-pointer orderly-text-base-contrast-54",
                    children: [
                        /*#__PURE__*/ _jsxs("div", {
                            className: "orderly-flex orderly-flex-col orderly-text-4xs",
                            children: [
                                /*#__PURE__*/ _jsxs("div", {
                                    className: "orderly-flex orderly-items-center",
                                    children: [
                                        /*#__PURE__*/ _jsx("span", {
                                            children: "Total value"
                                        }),
                                        /*#__PURE__*/ _jsx("button", {
                                            className: "orderly-text-primary-light orderly-px-2",
                                            onClick: (event)=>{
                                                event.stopPropagation();
                                                toggleVisible();
                                            },
                                            children: visible ? /*#__PURE__*/ _jsx(EyeOffIcon, {
                                                className: "orderly-text-primary",
                                                size: 12
                                            }) : /*#__PURE__*/ _jsx(EyeIcon, {
                                                className: "orderly-text-primary",
                                                size: 12
                                            })
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: "orderly-text-base",
                                            children: "≈"
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: "orderly-flex orderly-gap-2 orderly-text-base-contrast",
                                    children: [
                                        balance,
                                        /*#__PURE__*/ _jsx("span", {
                                            className: "orderly-text-base-contrast-20",
                                            children: currency
                                        })
                                    ]
                                })
                            ]
                        }),
                        /*#__PURE__*/ _jsx(Divider, {
                            vertical: true,
                            className: "orderly-px-3"
                        }),
                        /*#__PURE__*/ _jsx("div", {
                            className: "orderly-border orderly-border-solid orderly-px-2 orderly-rounded orderly-border-primary-light orderly-text-primary-light orderly-text-4xs orderly-h-[30px] orderly-leading-[30px] orderly-flex orderly-items-center",
                            children: /*#__PURE__*/ _jsx(Numeral, {
                                precision: 2,
                                surfix: "x",
                                children: currentLeverage
                            })
                        })
                    ]
                })
            }),
            /*#__PURE__*/ _jsxs(SheetContent, {
                id: "orderly-asset-and-margin-sheet",
                onOpenAutoFocus: (event)=>event.preventDefault(),
                children: [
                    /*#__PURE__*/ _jsx(SheetHeader, {
                        id: "orderly-asset-and-margin-sheet-title",
                        leading: /*#__PURE__*/ _jsx(Logo.secondary, {
                            size: 30
                        }),
                        children: "Assets & Margin"
                    }),
                    /*#__PURE__*/ _jsx(AssetAndMarginSheet, {
                        onDeposit: onDeposit,
                        onWithdraw: onWithdraw,
                        onSettle: onSettle,
                        maxLeverage: maxLerverage
                    })
                ]
            })
        ]
    });
};

//# sourceMappingURL=accountTotal.js.map