"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, {
    MemorizedOrderBook: function() {
        return MemorizedOrderBook;
    },
    MyOrderBook: function() {
        return MyOrderBook;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _indexdesktop = require("../../../../../block/orderbook/desktop/index.desktop");
const _symbolProvider = require("../../../../../provider/symbolProvider");
const _tabContext = require("../../../../../tab/tabContext");
const _hooks = require("@orderly.network/hooks");
const _react = require("react");
const _usePendingOrderStream = require("./usePendingOrderStream");
const _utils = require("@orderly.network/utils");
const CELL_MAX = 30;
const DEFAULT_CELL_HEIGHT = 20;
const SPACE = 104;
const MyOrderBook = (props)=>{
    const { symbol } = props;
    const [cellHeight, setCellHeight] = (0, _react.useState)(DEFAULT_CELL_HEIGHT);
    const [level, setLevel] = (0, _react.useState)(10);
    const { base, quote, quote_dp } = (0, _symbolProvider.useSymbolContext)();
    const [data, { onDepthChange, isLoading, onItemClick, depth, allDepths }] = (0, _hooks.useOrderbookStream)(symbol, undefined, {
        level
    });
    const pendingOrders = (0, _usePendingOrderStream.usePendingOrderStream)(symbol);
    const { height } = (0, _tabContext.useTabContext)();
    (0, _react.useEffect)(()=>{
        if (height?.content) {
            //   setCellHeight(height.content / level);
            const level = Math.floor((height.content - SPACE) / ((DEFAULT_CELL_HEIGHT + 1) * 2));
            const cellsHeight = (DEFAULT_CELL_HEIGHT + 1) * 2 * level;
            const restSpace = height.content - SPACE - cellsHeight;
            // console.log(
            //   "restSpace",
            //   level,
            //   height.content,
            //   SPACE,
            //   cellsHeight,
            //   restSpace
            // );
            if (restSpace > 10) {
                setCellHeight(DEFAULT_CELL_HEIGHT + restSpace / level / 2);
            } else {
                setCellHeight(DEFAULT_CELL_HEIGHT);
            }
            setLevel(level);
        }
    }, [
        height?.content
    ]);
    const selDepth = (0, _react.useMemo)(()=>{
        if (typeof depth === 'undefined' || typeof quote_dp === 'undefined') {
            return undefined;
        }
        let formattedNumber = (0, _utils.removeTrailingZeros)(depth);
        return formattedNumber;
    }, [
        depth,
        quote_dp
    ]);
    const depths = (0, _react.useMemo)(()=>{
        return allDepths?.map((e)=>(0, _utils.removeTrailingZeros)(e)) || [];
    }, [
        allDepths,
        quote_dp
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_indexdesktop.DesktopOrderBook, {
        level: level,
        asks: data.asks,
        bids: data.bids,
        markPrice: data.markPrice,
        lastPrice: data.middlePrice,
        depth: depths,
        activeDepth: selDepth,
        base: base,
        quote: quote,
        isLoading: isLoading,
        onItemClick: onItemClick,
        cellHeight: cellHeight,
        onDepthChange: onDepthChange,
        className: props.className,
        pendingOrders: pendingOrders
    });
};
const MemorizedOrderBook = /*#__PURE__*/ (0, _react.memo)(MyOrderBook);

//# sourceMappingURL=orderbook.js.map