"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "AccountTotal", {
    enumerable: true,
    get: function() {
        return AccountTotal;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _sheet = require("../../../sheet");
const _divider = require("../../../divider");
const _assetAndMargin = require("./assetAndMargin");
const _text = require("../../../text");
const _types = require("@orderly.network/types");
const _hooks = require("@orderly.network/hooks");
const _logo = require("../../../logo");
const _assetsProvider = require("../../../provider/assetsProvider");
const _icon = require("../../../icon");
const _provider = require("../../../provider");
const AccountTotal = (props)=>{
    const { currency = "USDC", accountInfo } = props;
    // @ts-ignore
    const { errors } = (0, _react.useContext)(_provider.OrderlyAppContext);
    const { onDeposit, onWithdraw, onSettle, visible, toggleVisible } = (0, _react.useContext)(_assetsProvider.AssetsContext);
    const { currentLeverage } = (0, _hooks.useMarginRatio)();
    //
    const balance = (0, _react.useMemo)(()=>{
        if (props.status < _types.AccountStatusEnum.EnableTrading) {
            return "--";
        }
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Numeral, {
            rule: "price",
            visible: visible,
            children: props.totalValue ?? 0
        });
    }, [
        props.status,
        props.totalValue,
        visible
    ]);
    const maxLerverage = (0, _react.useMemo)(()=>{
        return accountInfo?.max_leverage ?? "-";
    }, [
        accountInfo
    ]);
    if (props.status < _types.AccountStatusEnum.EnableTrading) {
        return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
            className: "orderly-flex orderly-items-center orderly-text-base-contrast-54 orderly-text-4xs",
            children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                className: "orderly-flex orderly-flex-col",
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        className: "orderly-flex orderly-items-center orderly-gap-2",
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                                children: "Total value"
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                                children: "≈"
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        className: "orderly-flex orderly-gap-2",
                        children: [
                            "--",
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                                className: "orderly-text-base-contrast-20",
                                children: currency
                            })
                        ]
                    })
                ]
            })
        });
    }
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_sheet.Sheet, {
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsx)(_sheet.SheetTrigger, {
                asChild: true,
                children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                    className: "orderly-flex orderly-items-center orderly-cursor-pointer orderly-text-base-contrast-54",
                    children: [
                        /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                            className: "orderly-flex orderly-flex-col orderly-text-4xs",
                            children: [
                                /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                                    className: "orderly-flex orderly-items-center",
                                    children: [
                                        /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                                            children: "Total value"
                                        }),
                                        /*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
                                            className: "orderly-text-primary-light orderly-px-2",
                                            onClick: (event)=>{
                                                event.stopPropagation();
                                                toggleVisible();
                                            },
                                            children: visible ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_icon.EyeOffIcon, {
                                                className: "orderly-text-primary",
                                                size: 12
                                            }) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_icon.EyeIcon, {
                                                className: "orderly-text-primary",
                                                size: 12
                                            })
                                        }),
                                        /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                                            className: "orderly-text-base",
                                            children: "≈"
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                                    className: "orderly-flex orderly-gap-2 orderly-text-base-contrast",
                                    children: [
                                        balance,
                                        /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                                            className: "orderly-text-base-contrast-20",
                                            children: currency
                                        })
                                    ]
                                })
                            ]
                        }),
                        /*#__PURE__*/ (0, _jsxruntime.jsx)(_divider.Divider, {
                            vertical: true,
                            className: "orderly-px-3"
                        }),
                        /*#__PURE__*/ (0, _jsxruntime.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__*/ (0, _jsxruntime.jsx)(_text.Numeral, {
                                precision: 2,
                                surfix: "x",
                                children: currentLeverage
                            })
                        })
                    ]
                })
            }),
            /*#__PURE__*/ (0, _jsxruntime.jsxs)(_sheet.SheetContent, {
                id: "orderly-asset-and-margin-sheet",
                onOpenAutoFocus: (event)=>event.preventDefault(),
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_sheet.SheetHeader, {
                        id: "orderly-asset-and-margin-sheet-title",
                        leading: /*#__PURE__*/ (0, _jsxruntime.jsx)(_logo.Logo.secondary, {
                            size: 30
                        }),
                        children: "Assets & Margin"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_assetAndMargin.AssetAndMarginSheet, {
                        onDeposit: onDeposit,
                        onWithdraw: onWithdraw,
                        onSettle: onSettle,
                        maxLeverage: maxLerverage
                    })
                ]
            })
        ]
    });
};

//# sourceMappingURL=accountTotal.js.map