"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    MemoizedCompnent: function() {
        return MemoizedCompnent;
    },
    MyLeverageView: function() {
        return MyLeverageView;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _leverage = require("../../../../block/leverage");
const _modal = require("../../../../modal");
const _hooks = require("@orderly.network/hooks");
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const MyLeverageView = (props)=>{
    const data = (0, _hooks.useFundingRate)(props.symbol);
    const { data: info } = (0, _hooks.useAccountInfo)();
    const res = (0, _hooks.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 = (0, _react.useMemo)(()=>{
        const base = res?.data?.base_imr;
        if (base) return 1 / base;
    }, [
        res
    ]);
    const showLeverageInfo = (0, _react.useCallback)(()=>{
        _modal.modal.alert({
            title: "Max leverage",
            message: /*#__PURE__*/ (0, _jsxruntime.jsxs)("span", {
                id: "orderly-max-leverage-content",
                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 = (0, _react.useMemo)(()=>{
        if (!maxAccountLeverage || !maxSymbolLeverage) {
            return "-";
        }
        return Math.min(maxAccountLeverage, maxSymbolLeverage);
    }, [
        maxAccountLeverage,
        maxSymbolLeverage
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
        className: "orderly-px-3 orderly-py-2",
        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_leverage.LeverageView, {
            maxLeverage: maxLeverage,
            // @ts-ignore
            predFundingRate: data.est_funding_rate,
            countdown: data.countDown,
            onShowLeverageInfo: showLeverageInfo
        })
    });
};
const MemoizedCompnent = /*#__PURE__*/ (0, _react.memo)(MyLeverageView);

//# sourceMappingURL=leverage.js.map