"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "SharePoisitionView", {
    enumerable: true,
    get: function() {
        return SharePoisitionView;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _modal = require("../../modal");
const _modalHelper = require("../../modal/modalHelper");
const _sheet = require("../../sheet/sheet");
const _dialog = require("../../dialog/dialog");
const _hooks = require("@orderly.network/hooks");
const _types = require("@orderly.network/types");
const _react = require("react");
const _desktopSharePnl = require("./desktopSharePnl");
const _mobileSharePnl = require("./mobileSharePnl");
const _provider = require("../../provider");
const SharePoisitionView = (0, _modalHelper.create)((props)=>{
    const isTablet = (0, _hooks.useMediaQuery)(_types.MEDIA_TABLET);
    const { position } = props;
    // const [leverage] = useLeverage();
    const symbolInfo = (0, _hooks.useSymbolsInfo)();
    // const { data: info } = useAccountInfo();
    // const maxAccountLeverage = info?.max_leverage;
    // const res = useQuery<any>(`/v1/public/info/${position.symbol}`, {
    //   focusThrottleInterval: 1000 * 60 * 60 * 24,
    //   dedupingInterval: 1000 * 60 * 60 * 24,
    //   revalidateOnFocus: false,
    // });
    // const maxSymbolLeverage = useMemo(() => {
    //   const base = res?.data?.base_imr;
    //   if (base) return 1 / base;
    // }, [res]);
    // const maxLeverage = useMemo(() => {
    //   if (!maxAccountLeverage || !maxSymbolLeverage) {
    //     return "-";
    //   }
    //   return Math.min(maxAccountLeverage, maxSymbolLeverage);
    // }, [maxAccountLeverage, maxSymbolLeverage]);
    const { getFirstRefCode } = (0, _hooks.useReferralInfo)();
    if (symbolInfo.isNil) return null;
    const base_dp = symbolInfo[position.symbol]("base_dp");
    const quote_dp = symbolInfo[position.symbol]("quote_dp");
    const { referral } = (0, _react.useContext)(_provider.OrderlyAppContext);
    const referralInfo = (0, _react.useMemo)(()=>{
        const code = getFirstRefCode()?.code;
        const info = {
            code,
            slogan: referral?.slogan,
            link: referral?.refLink
        };
        return info;
    }, [
        getFirstRefCode,
        referral
    ]);
    return isTablet ? /*#__PURE__*/ (0, _jsxruntime.jsx)(MobileSharePnL, {
        position: position,
        leverage: props.leverage,
        baseDp: base_dp,
        quoteDp: quote_dp,
        referral: referralInfo
    }) : /*#__PURE__*/ (0, _jsxruntime.jsx)(DesktopSharePnL, {
        position: position,
        leverage: props.leverage,
        baseDp: base_dp,
        quoteDp: quote_dp,
        referral: referralInfo
    });
});
const MobileSharePnL = (props)=>{
    const { leverage, position, baseDp, quoteDp, referral } = props;
    const { visible, hide, resolve, reject, onOpenChange } = (0, _modal.useModal)();
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_sheet.Sheet, {
        open: visible,
        onOpenChange: onOpenChange,
        children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_sheet.SheetContent, {
            id: "orderly-referral-mweb-bg",
            className: "orderly-px-4",
            onOpenAutoFocus: (e)=>e.preventDefault(),
            onCloseAutoFocus: (e)=>e.preventDefault(),
            children: [
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_sheet.SheetHeader, {
                    id: "orderly-asset-and-margin-sheet-title",
                    children: "PnL Sharing"
                }),
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_mobileSharePnl.MobileSharePnLContent, {
                    position: position,
                    leverage: leverage,
                    hide: hide,
                    baseDp: baseDp,
                    quoteDp: quoteDp,
                    referral: referral
                })
            ]
        })
    });
};
const DesktopSharePnL = (props)=>{
    const { leverage, position, baseDp, quoteDp, referral } = props;
    const { visible, hide, resolve, reject, onOpenChange } = (0, _modal.useModal)();
    const [viewportHeight, setViewportHeight] = (0, _react.useState)(window.innerHeight < 900 ? 660 : 807);
    (0, _react.useEffect)(()=>{
        const handleResize = ()=>{
            setViewportHeight(window.innerHeight < 900 ? 660 : 807);
        };
        window.addEventListener("resize", handleResize);
        return ()=>{
            window.removeEventListener("resize", handleResize);
        };
    }, []);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_dialog.Dialog, {
        open: visible,
        onOpenChange: onOpenChange,
        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_dialog.DialogContent, {
            className: "orderly-shadow-lg orderly-w-[640px] orderly-bg-base-800 desktop:orderly-max-w-[640px] orderly-py-0",
            style: {
                height: `${viewportHeight}px`
            },
            autoFocus: false,
            onOpenAutoFocus: (e)=>e.preventDefault(),
            onCloseAutoFocus: (e)=>e.preventDefault(),
            children: /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                id: "orderly-referral-desktop-bg",
                style: {
                    height: `${viewportHeight}px`
                },
                children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_desktopSharePnl.DesktopSharePnLContent, {
                    position: position,
                    leverage: leverage,
                    hide: hide,
                    baseDp: baseDp,
                    quoteDp: quoteDp,
                    referral: referral
                })
            })
        })
    });
};

//# sourceMappingURL=sharePosition.js.map