"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TPSLCell", {
    enumerable: true,
    get: function() {
        return TPSLCell;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _statistic = require("../../statistic/statistic");
const _types = require("@orderly.network/types");
const _popover = require("../../popover");
const _triggerPrice = require("../positions/shared/triggerPrice");
const _hooks = require("@orderly.network/hooks");
const _tpslOrderRowContext = require("../tp_sl/tpslOrderRowContext");
const TPSLCell = (props)=>{
    const { order, base_dp, quote_dp } = props;
    const isAlgoOrder = order?.algo_order_id !== undefined;
    // console.log("price node", order);
    const { sl_trigger_price, tp_trigger_price, position } = (0, _tpslOrderRowContext.useTPSLOrderRowContext)();
    const symbolInfo = (0, _hooks.useSymbolsInfo)()[order?.symbol ?? ""]();
    const childOrders = (0, _react.useMemo)(()=>{
        const orders = order.child_orders.filter((child)=>!!child.trigger_price && child.is_activated).map((child)=>{
            const type = child.algo_type === _types.AlgoOrderType.TAKE_PROFIT ? "TP" : "SL";
            let quantity = order.quantity;
            if (quantity === 0) {
                if (order.child_orders[0].type === "CLOSE_POSITION") {
                    quantity = position?.position_qty ?? 0;
                }
            }
            return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_react.Fragment, {
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                        className: "orderly-inline-flex",
                        children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_popover.Popover, {
                            children: [
                                /*#__PURE__*/ (0, _jsxruntime.jsx)(_popover.PopoverTrigger, {
                                    children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_statistic.Statistic, {
                                        label: /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
                                            children: /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                                                className: "orderly-text-base-contrast-36",
                                                children: `${type} trigger`
                                            })
                                        }),
                                        labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
                                        valueClassName: child.algo_type === _types.AlgoOrderType.TAKE_PROFIT ? "orderly-text-trade-profit orderly-text-3xs orderly-font-bold orderly-underline orderly-underline-offset-2 orderly-decoration-dashed orderly-decoration-base-contrast-36" : "orderly-text-trade-loss orderly-text-3xs orderly-font-bold orderly-underline orderly-underline-offset-2 orderly-decoration-dashed orderly-decoration-base-contrast-36",
                                        rule: "price",
                                        precision: quote_dp,
                                        value: child.trigger_price
                                    })
                                }),
                                /*#__PURE__*/ (0, _jsxruntime.jsx)(_popover.PopoverContent, {
                                    side: "top",
                                    align: "start",
                                    className: "orderly-p-1 orderly-bg-base-400 orderly-fill-base-400 orderly-text-3xs orderly-max-w-max",
                                    arrow: true,
                                    children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_triggerPrice.TriggerPriceItem, {
                                        qty: quantity,
                                        price: child.trigger_price,
                                        entryPrice: position?.average_open_price ?? 0,
                                        orderSide: child.side,
                                        orderType: child.algo_type,
                                        symbolInfo: symbolInfo
                                    })
                                })
                            ]
                        })
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_statistic.Statistic, {
                        label: `${type} price`,
                        labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
                        value: /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                            children: "Market"
                        }),
                        rule: "price",
                        valueClassName: "orderly-text-3xs orderly-text-base-contrast-80"
                    })
                ]
            }, child.algo_order_id);
        });
        orders.splice(1, 0, /*#__PURE__*/ (0, _jsxruntime.jsx)(_statistic.Statistic, {
            label: "Quantity",
            labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
            value: /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                children: order.algo_type === _types.AlgoOrderRootType.POSITIONAL_TP_SL ? "Entire position" : order.quantity ?? "-"
            }),
            precision: base_dp,
            rule: "price",
            align: "right",
            valueClassName: "orderly-text-3xs orderly-text-base-contrast-80"
        }));
        return orders;
    }, [
        order
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
        children: childOrders
    });
};

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