import { jsx as _jsx } from "react/jsx-runtime";
import { useMemo } from "react";
import { Numeral } from "../../../text";
import { cn } from "../../../utils";
import { Tooltip } from "../../../tooltip";
import { useSymbolsInfo } from "@orderly.network/hooks";
import { AlgoOrderType } from "@orderly.network/types";
import { TriggerPriceItem } from "../shared/triggerPrice";
export const TPSLTriggerPrice = (props)=>{
    const { direction = "row", order, position } = props;
    const symbolInfo = useSymbolsInfo()[position?.symbol ?? ""]();
    const pnl = useMemo(()=>{
        const msgs = [];
        if (!props.tooltip || !order || !position) return;
        let quantity = order.quantity;
        if (quantity === 0) {
            if (order.child_orders[0].type === "CLOSE_POSITION") {
                quantity = position.position_qty;
            }
        }
        if (!!props.takeProfitPrice) {
            msgs.push(/*#__PURE__*/ _jsx(TriggerPriceItem, {
                qty: quantity,
                price: props.takeProfitPrice,
                entryPrice: position.average_open_price,
                orderSide: order.side,
                orderType: AlgoOrderType.TAKE_PROFIT,
                symbolInfo: symbolInfo
            }, "tp"));
        }
        if (!!props.stopLossPrice) {
            msgs.push(/*#__PURE__*/ _jsx(TriggerPriceItem, {
                qty: quantity,
                price: props.stopLossPrice,
                entryPrice: position.average_open_price,
                orderSide: order.side,
                orderType: AlgoOrderType.STOP_LOSS,
                symbolInfo: symbolInfo
            }, "sl"));
        }
        return /*#__PURE__*/ _jsx("div", {
            children: msgs
        });
    }, [
        props.takeProfitPrice,
        props.stopLossPrice,
        position?.average_open_price,
        order?.side,
        order?.quantity,
        order?.algo_type
    ]);
    const child = useMemo(()=>{
        const children = [];
        if (props.takeProfitPrice) {
            children.push(/*#__PURE__*/ _jsx(Numeral, {
                className: cn("orderly-text-trade-profit orderly-gap-0  orderly-decoration-white/20"),
                rule: "price",
                children: props.takeProfitPrice,
                prefix: !props.stopLossPrice || direction === "column" ? /*#__PURE__*/ _jsx("span", {
                    className: "orderly-text-base-contrast-54",
                    children: "TP - "
                }) : ""
            }, "tp"));
        }
        if (props.stopLossPrice) {
            children.push(/*#__PURE__*/ _jsx(Numeral, {
                className: cn("orderly-text-trade-loss orderly-gap-0 orderly-decoration-white/20 "),
                rule: "price",
                children: props.stopLossPrice,
                prefix: !props.takeProfitPrice || direction === "column" ? /*#__PURE__*/ _jsx("span", {
                    className: "orderly-text-base-contrast-54",
                    children: "SL - "
                }) : ""
            }, "sl"));
        }
        if (children.length === 0) return /*#__PURE__*/ _jsx("span", {
            children: "-"
        });
        if (children.length === 2 && direction === "row") {
            children.splice(1, 0, /*#__PURE__*/ _jsx("span", {
                children: "/"
            }, "split"));
        }
        return children;
    }, [
        props.takeProfitPrice,
        props.stopLossPrice
    ]);
    const content = /*#__PURE__*/ _jsx("div", {
        className: cn("orderly-inline-flex orderly-text-base-contrast-36", props.direction === "column" ? "orderly-flex-col" : "orderly-flex-row orderly-gap-1", props.className),
        children: child
    });
    if (props.tooltip) {
        // @ts-ignore
        return /*#__PURE__*/ _jsx(Tooltip, {
            content: pnl,
            children: content
        });
    }
    return content;
};

//# sourceMappingURL=tpslTriggerPrice.js.map