import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { LeverageView } from "../../../../block/leverage";
import { modal } from "../../../../modal";
import { useFundingRate, useAccountInfo, useQuery } from "@orderly.network/hooks";
import React, { memo, useCallback, useMemo } from "react";
export const MyLeverageView = (props)=>{
    const data = useFundingRate(props.symbol);
    const { data: info } = useAccountInfo();
    const res = useQuery(`/v1/public/info/${props.symbol}`, {
        focusThrottleInterval: 1000 * 60 * 60 * 24,
        dedupingInterval: 1000 * 60 * 60 * 24,
        revalidateOnFocus: false
    });
    const maxAccountLeverage = info?.max_leverage;
    const maxSymbolLeverage = useMemo(()=>{
        const base = res?.data?.base_imr;
        if (base) return 1 / base;
    }, [
        res
    ]);
    const showLeverageInfo = useCallback(()=>{
        modal.alert({
            title: "Max leverage",
            message: /*#__PURE__*/ _jsxs("span", {
                className: "orderly-text-3xs orderly-text-base-contrast-54",
                children: [
                    "This instrument supports up to ",
                    maxSymbolLeverage,
                    "x leverage. The actual amount cannot exceed the max account leverage."
                ]
            })
        });
    }, [
        maxSymbolLeverage
    ]);
    const maxLeverage = useMemo(()=>{
        if (!maxAccountLeverage || !maxSymbolLeverage) {
            return "-";
        }
        return Math.min(maxAccountLeverage, maxSymbolLeverage);
    }, [
        maxAccountLeverage,
        maxSymbolLeverage
    ]);
    return /*#__PURE__*/ _jsx("div", {
        className: "orderly-px-3 orderly-py-2",
        children: /*#__PURE__*/ _jsx(LeverageView, {
            maxLeverage: maxLeverage,
            // @ts-ignore
            predFundingRate: data.est_funding_rate,
            countdown: data.countDown,
            onShowLeverageInfo: showLeverageInfo
        })
    });
};
export const MemoizedCompnent = /*#__PURE__*/ memo(MyLeverageView);

//# sourceMappingURL=leverage.js.map