"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "DesktopOrderBook", {
    enumerable: true,
    get: function() {
        return DesktopOrderBook;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _bidsdesktop = require("./bids.desktop");
const _asksdesktop = require("./asks.desktop");
const _markPricedesktop = require("./markPrice.desktop");
const _orderContext = require("../../../block/orderbook/orderContext");
const _spinner = require("../../../spinner");
const _css = require("../../../utils/css");
const _headerdesktop = require("./header.desktop");
const _depthSelectdesktop = require("./depthSelect.desktop");
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 DesktopOrderBook = (props)=>{
    const { lastPrice, markPrice, quote, base, isLoading, onDepthChange } = props;
    // const onModeChange = useCallback((mode: QtyMode) => {}, []);
    //
    const divRef = (0, _react.useRef)(null);
    const [showTotal, setShowTotal] = (0, _react.useState)(false);
    const rangeInfo = [
        {
            left: 370,
            right: 600
        },
        {
            left: 740,
            right: 800
        }
    ];
    (0, _react.useEffect)(()=>{
        const resizeObserver = new ResizeObserver((entries)=>{
            for (let entry of entries){
                const { inlineSize: width } = entry.borderBoxSize[0];
                const count = rangeInfo.reduce((a, b)=>a + (width >= b.left && width < b.right ? 1 : 0), 0);
                setShowTotal(()=>count > 0);
            }
        });
        const targetDiv = divRef.current;
        if (targetDiv) {
            resizeObserver.observe(targetDiv);
        }
        return ()=>{
            if (targetDiv) {
                resizeObserver.unobserve(targetDiv);
            }
        };
    }, []);
    /// 
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_orderContext.OrderBookProvider, {
        cellHeight: props.cellHeight ?? 20,
        onItemClick: props.onItemClick,
        depth: props.activeDepth,
        showTotal: showTotal,
        pendingOrders: props.pendingOrders || [],
        children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
            id: "orderly-orderbook-desktop",
            className: (0, _css.cn)("orderly-h-full orderly-relative", props.className),
            ref: divRef,
            children: [
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_depthSelectdesktop.DesktopDepthSelect, {
                    depth: props.depth,
                    value: props.activeDepth,
                    onChange: onDepthChange
                }),
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_headerdesktop.DesktopHeader, {
                    quote: quote,
                    base: base
                }),
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_asksdesktop.DesktopAsks, {
                    data: [
                        ...props.asks
                    ]
                }),
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_markPricedesktop.DesktopMarkPrice, {
                    lastPrice: lastPrice,
                    markPrice: markPrice,
                    asks: [
                        ...props.asks
                    ],
                    bids: [
                        ...props.bids
                    ]
                }),
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_bidsdesktop.DesktopBids, {
                    data: [
                        ...props.bids
                    ]
                }),
                isLoading && /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                    className: "orderly-absolute orderly-left-0 orderly-top-0 orderly-right-0 orderly-bottom-0 orderly-z-10 orderly-flex orderly-items-center orderly-justify-center orderly-bg-base-800/70 orderly-h-full orderly-min-h-[420px]",
                    children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_spinner.Spinner, {})
                })
            ]
        })
    });
};

//# sourceMappingURL=index.desktop.js.map