"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "OrderBookCell", {
    enumerable: true,
    get: function() {
        return OrderBookCell;
    }
});
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 _numeral = require("../../text/numeral");
const _provider = require("../../provider");
const _utils1 = require("../../utils");
const _types = require("./types");
const OrderBookCell = (props)=>{
    const width = props.accumulated / props.count * 100;
    const { cellHeight, onItemClick, depth, showTotal } = (0, _react.useContext)(_orderContext.OrderBookContext);
    const { base_dp, quote_dp } = (0, _react.useContext)(_provider.SymbolContext);
    let qty = Number.isNaN(props.quantity) ? "-" : props.mode === "amount" ? new _utils.Decimal(props.quantity).mul(props.price).toString() : props.quantity;
    if (showTotal) {
        qty = props.quantity;
    }
    const dp = (0, _react.useMemo)(()=>{
        return (0, _utils.getPrecisionByNumber)(depth || `${quote_dp}`);
    }, [
        depth,
        quote_dp
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
        className: (0, _utils1.cn)("orderly-order-book-list-item orderly-overflow-hidden orderly-relative orderly-cursor-pointer orderly-tabular-nums", showTotal && "orderly-flex-1"),
        style: {
            height: `${cellHeight}px`
        },
        onClick: (e)=>{
            if (Number.isNaN(props.price) || Number.isNaN(props.quantity)) return;
            onItemClick?.([
                props.price,
                props.quantity
            ]);
        },
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                className: "orderly-flex orderly-flex-row orderly-justify-between orderly-items-center orderly-z-10 orderly-relative orderly-px-1 orderly-text-4xs desktop:orderly-text-2xs orderly-h-full",
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                        className: 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-text-base-contrast-80",
                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_numeral.Numeral, {
                            precision: props.mode === "amount" ? 2 : base_dp,
                            children: qty
                        })
                    })
                ]
            }),
            Number.isNaN(width) || showTotal ? null : /*#__PURE__*/ (0, _jsxruntime.jsx)(_cellBar.CellBar, {
                width: width,
                className: props.type === _types.OrderBookCellType.ASK ? "orderly-bg-trade-loss/20" : "orderly-bg-trade-profit/20"
            })
        ]
    });
};

//# sourceMappingURL=cell.js.map