"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "DesktopOrderBookCell", {
    enumerable: true,
    get: function() {
        return DesktopOrderBookCell;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _cellBar = require("../cellBar");
const _orderContext = require("../../../block/orderbook/orderContext");
const _utils = require("@orderly.network/utils");
const _num = require("../../../utils/num");
const _numeral = require("../../../text/numeral");
const _provider = require("../../../provider");
const _utils1 = require("../../../utils");
const _types = require("../types");
const DesktopOrderBookCell = (props)=>{
    const { cellHeight, showTotal, onItemClick, depth, pendingOrders } = (0, _react.useContext)(_orderContext.OrderBookContext);
    const { base_dp, quote_dp } = (0, _react.useContext)(_provider.SymbolContext);
    const width = Number.isNaN(props.price) ? 0 : props.accumulated / props.count * 100;
    const dp = (0, _react.useMemo)(()=>{
        return (0, _utils.getPrecisionByNumber)(depth || `${quote_dp}`);
    }, [
        depth,
        quote_dp
    ]);
    const totalAmount = Number.isNaN(props.accumulated) ? "-" : props.accumulatedAmount?.toString();
    const isPendingOrder = (0, _react.useMemo)(()=>{
        const priceStr = (0, _num.parseNumber)(props.price, {
            precision: dp,
            padding: true
        });
        const index = pendingOrders.findIndex((item)=>priceStr === (0, _num.parseNumber)(item, {
                precision: dp,
                padding: true
            }));
        return index !== -1;
    }, [
        pendingOrders,
        props.price,
        depth
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
        className: "orderly-flex orderly-flex-row orderly-tabular-nums orderly-justify-between orderly-text-base-contrast-80 orderly-text-3xs orderly-relative orderly-cursor-pointer",
        style: {
            height: `${cellHeight}px`
        },
        onClick: ()=>{
            if (Number.isNaN(props.price) || Number.isNaN(props.quantity)) return;
            onItemClick?.([
                props.price,
                props.quantity
            ]);
        },
        onMouseEnter: props.onMouseEnter,
        onMouseLeave: props.onMouseLeave,
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                className: (0, _utils1.cn)("orderly-basis-7/12 orderly-flex orderly-felx-row orderly-items-center orderly-mr-2", showTotal && "orderly-basis-5/12"),
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                        className: (0, _utils1.cn)("orderly-flex-1 orderly-text-left", props.type === _types.OrderBookCellType.ASK ? "orderly-text-trade-loss" : "orderly-text-trade-profit"),
                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_numeral.Numeral, {
                            precision: dp,
                            children: props.price
                        })
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                        className: "orderly-flex-1 orderly-text-right orderly-text-base-contrast-80",
                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_numeral.Numeral, {
                            precision: base_dp,
                            children: props.quantity
                        })
                    })
                ]
            }),
            /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                className: (0, _utils1.cn)("orderly-basis-5/12 orderly-flex orderly-items-center orderly-fex-row orderly-overflow-hidden orderly-relative", showTotal && "orderly-basis-7/12"),
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                        className: (0, _utils1.cn)("orderly-flex-1 orderly-pr-6 orderly-text-right", showTotal && "orderly-pr-3"),
                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_numeral.Numeral, {
                            precision: base_dp,
                            className: "orderly-z-10",
                            children: props.accumulated
                        })
                    }),
                    showTotal && /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                        className: "orderly-flex-1 orderly-text-right orderly-pr-3",
                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_numeral.Numeral, {
                            precision: 2,
                            className: "orderly-z-10",
                            children: totalAmount
                        })
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_cellBar.CellBar, {
                        width: width,
                        direction: _cellBar.CellBarDirection.LEFT_TO_RIGHT,
                        className: props.type === _types.OrderBookCellType.ASK ? "orderly-bg-trade-loss/10" : "orderly-bg-trade-profit/10"
                    })
                ]
            }),
            isPendingOrder && /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                className: (0, _utils1.cn)("orderly-absolute orderly-rounded-full orderly-left-[-8px] orderly-h-[4px] orderly-w-[4px] orderly-pointer-events-none", props.type === _types.OrderBookCellType.ASK && "orderly-bg-trade-loss", props.type === _types.OrderBookCellType.BID && "orderly-bg-trade-profit"),
                style: {
                    top: `${cellHeight / 2 - 2}px`
                }
            }),
            props.isHover && /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                className: "orderly-absolute orderly-bg-white orderly-left-0 orderly-right-0 orderly-top-0 orderly-bottom-0 orderly-opacity-10"
            })
        ]
    });
};

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