import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Fragment, useMemo } from "react";
import { Statistic } from "../../statistic/statistic";
import { AlgoOrderRootType, AlgoOrderType } from "@orderly.network/types";
import { Popover, PopoverContent, PopoverTrigger } from "../../popover";
import { TriggerPriceItem } from "../positions/shared/triggerPrice";
import { useSymbolsInfo } from "@orderly.network/hooks";
import { useTPSLOrderRowContext } from "../tp_sl/tpslOrderRowContext";
export 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 } = useTPSLOrderRowContext();
    const symbolInfo = useSymbolsInfo()[order?.symbol ?? ""]();
    const childOrders = useMemo(()=>{
        const orders = order.child_orders.filter((child)=>!!child.trigger_price && child.is_activated).map((child)=>{
            const type = child.algo_type === 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__*/ _jsxs(Fragment, {
                children: [
                    /*#__PURE__*/ _jsx("div", {
                        className: "orderly-inline-flex",
                        children: /*#__PURE__*/ _jsxs(Popover, {
                            children: [
                                /*#__PURE__*/ _jsx(PopoverTrigger, {
                                    children: /*#__PURE__*/ _jsx(Statistic, {
                                        label: /*#__PURE__*/ _jsx(_Fragment, {
                                            children: /*#__PURE__*/ _jsx("span", {
                                                className: "orderly-text-base-contrast-36",
                                                children: `${type} trigger`
                                            })
                                        }),
                                        labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
                                        valueClassName: child.algo_type === 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__*/ _jsx(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__*/ _jsx(TriggerPriceItem, {
                                        qty: quantity,
                                        price: child.trigger_price,
                                        entryPrice: position?.average_open_price ?? 0,
                                        orderSide: child.side,
                                        orderType: child.algo_type,
                                        symbolInfo: symbolInfo
                                    })
                                })
                            ]
                        })
                    }),
                    /*#__PURE__*/ _jsx(Statistic, {
                        label: `${type} price`,
                        labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
                        value: /*#__PURE__*/ _jsx("span", {
                            children: "Market"
                        }),
                        rule: "price",
                        valueClassName: "orderly-text-3xs orderly-text-base-contrast-80"
                    })
                ]
            }, child.algo_order_id);
        });
        orders.splice(1, 0, /*#__PURE__*/ _jsx(Statistic, {
            label: "Quantity",
            labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
            value: /*#__PURE__*/ _jsx("span", {
                children: order.algo_type === 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__*/ _jsx(_Fragment, {
        children: childOrders
    });
};

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