"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 _orderbook = require("../../../../../block/orderbook");
const _provider = require("../../../../../provider");
const _css = require("../../../../../utils/css");
const _hooks = require("@orderly.network/hooks");
const _utils = require("@orderly.network/utils");
const _react = require("react");
const MyOrderBook = (props)=>{
    const { symbol } = props;
    const [cellHeight, setCellHeight] = (0, _react.useState)(20);
    const [data, { onDepthChange, isLoading, onItemClick, depth, allDepths }] = (0, _hooks.useOrderbookStream)(symbol, undefined, {
        level: 7
    });
    const config = (0, _hooks.useSymbolsInfo)();
    const symbolInfo = config?.[symbol];
    const quote_dp = symbolInfo("quote_dp");
    const ee = (0, _hooks.useEventEmitter)();
    (0, _react.useEffect)(()=>{
        const resizeHandler = ({ height })=>{
            let innerHeight = height - 116;
            let cellHeight = innerHeight / 14;
            setCellHeight(()=>cellHeight);
        };
        ee.on("dom:orderEntry:resize", resizeHandler);
        return ()=>{
            ee.off("dom:orderEntry:resize", resizeHandler);
        };
    }, []);
    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)("div", {
        id: "orderly-order-book",
        className: (0, _css.cn)("orderly-pr-1", props.className),
        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_provider.SymbolProvider, {
            symbol: symbol,
            children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_orderbook.OrderBook, {
                level: 7,
                asks: data.asks,
                bids: data.bids,
                markPrice: data.markPrice,
                lastPrice: data.middlePrice,
                depth: depths,
                activeDepth: selDepth,
                base: symbolInfo("base"),
                quote: symbolInfo("quote"),
                isLoading: isLoading,
                onItemClick: onItemClick,
                cellHeight: cellHeight,
                onDepthChange: onDepthChange,
                // @ts-ignore
                pendingOrders: []
            })
        })
    });
};
const MemorizedOrderBook = /*#__PURE__*/ (0, _react.memo)(MyOrderBook);

//# sourceMappingURL=index.js.map