import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo } from "react";
import { useMarginRatio, useLeverage } from "@orderly.network/hooks";
import { Numeral } from "../../../text";
import { Pencil } from "lucide-react";
import { LeverageDialog } from "./leverageDialog";
import { Tooltip } from "../../../tooltip";
import { Divider } from "../../../divider";
import { cn } from "../../../utils";
import { getMarginRatioColor } from "../utils";
const LeverageAndMarginRatio = (props)=>{
    const { isConnected } = props;
    const { marginRatio, currentLeverage, mmr } = useMarginRatio();
    const [maxLeverage, { update, config: leverageLevers }] = useLeverage();
    const marginRatioVal = marginRatio === 0 ? 10 : Math.min(marginRatio, 10);
    const { isRed, isYellow, isGreen } = getMarginRatioColor(marginRatioVal, mmr);
    return /*#__PURE__*/ _jsxs("div", {
        className: "orderly-flex orderly-justify-between orderly-text-xs",
        children: [
            /*#__PURE__*/ _jsxs("div", {
                className: "orderly-flex orderly-flex-col orderly-tabular-nums orderly-items-start",
                children: [
                    /*#__PURE__*/ _jsx(Tooltip, {
                        // @ts-ignore
                        content: /*#__PURE__*/ _jsxs("div", {
                            children: [
                                /*#__PURE__*/ _jsx("span", {
                                    children: "Your actual Leverage of the whole account / Your max Leverage of the whole account"
                                }),
                                /*#__PURE__*/ _jsx(Divider, {
                                    className: "orderly-py-2 orderly-border-white/10"
                                }),
                                /*#__PURE__*/ _jsx("span", {
                                    children: "Margin ratio = Total collateral / Total position notional"
                                })
                            ]
                        }),
                        className: "orderly-max-w-[270px]",
                        children: /*#__PURE__*/ _jsx("div", {
                            className: "orderly-text-base-contrast-54 orderly-text-3xs orderly-cursor-pointer",
                            children: "Margin ratio"
                        })
                    }),
                    /*#__PURE__*/ _jsx(Numeral, {
                        className: cn("orderly-text-base-contrast", isConnected && cn({
                            "orderly-text-[#FF67C2]": isRed,
                            "orderly-text-[#FFCF73]": isYellow,
                            "orderly-text-[#1EF6B4]": isGreen
                        })),
                        rule: "percentages",
                        coloring: true,
                        children: isConnected ? marginRatioVal : "-"
                    })
                ]
            }),
            /*#__PURE__*/ _jsxs("div", {
                id: "orderly-desktop-max-leverage",
                className: "orderly-flex orderly-flex-col orderly-items-end",
                children: [
                    /*#__PURE__*/ _jsx(Tooltip, {
                        content: "Your actual Leverage of the whole account / Your max Leverage of the whole account",
                        className: "orderly-max-w-[270px]",
                        children: /*#__PURE__*/ _jsx("div", {
                            className: "orderly-text-base-contrast-54 orderly-text-3xs orderly-cursor-pointer",
                            children: "Account leverage"
                        })
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: "orderly-flex orderly-items-center orderly-gap-1 orderly-text-2xs",
                        children: [
                            isConnected ? /*#__PURE__*/ _jsx(Numeral, {
                                surfix: "x",
                                children: currentLeverage
                            }) : "-",
                            /*#__PURE__*/ _jsx("span", {
                                className: "orderly-text-base-contrast-54",
                                children: "/"
                            }),
                            isConnected ? /*#__PURE__*/ _jsx(LeverageDialog, {
                                children: /*#__PURE__*/ _jsxs("button", {
                                    id: "orderly-desktop-leverage-button",
                                    className: "orderly-flex orderly-items-center orderly-gap-1",
                                    children: [
                                        /*#__PURE__*/ _jsx("span", {
                                            children: `${maxLeverage ?? "-"}x`
                                        }),
                                        typeof maxLeverage !== "undefined" && // @ts-ignore
                                        /*#__PURE__*/ _jsx(Pencil, {
                                            size: 14,
                                            className: "orderly-text-base-contrast-54"
                                        })
                                    ]
                                })
                            }) : "-"
                        ]
                    })
                ]
            })
        ]
    });
};
export const MemorizedLeverage = /*#__PURE__*/ memo(LeverageAndMarginRatio);

//# sourceMappingURL=leverage.js.map