"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TPSLTriggerPrice", {
    enumerable: true,
    get: function() {
        return TPSLTriggerPrice;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _text = require("../../../text");
const _utils = require("../../../utils");
const _tooltip = require("../../../tooltip");
const _hooks = require("@orderly.network/hooks");
const _types = require("@orderly.network/types");
const _triggerPrice = require("../shared/triggerPrice");
const TPSLTriggerPrice = (props)=>{
    const { direction = "row", order, position } = props;
    const symbolInfo = (0, _hooks.useSymbolsInfo)()[position?.symbol ?? ""]();
    const pnl = (0, _react.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__*/ (0, _jsxruntime.jsx)(_triggerPrice.TriggerPriceItem, {
                qty: quantity,
                price: props.takeProfitPrice,
                entryPrice: position.average_open_price,
                orderSide: order.side,
                orderType: _types.AlgoOrderType.TAKE_PROFIT,
                symbolInfo: symbolInfo
            }, "tp"));
        }
        if (!!props.stopLossPrice) {
            msgs.push(/*#__PURE__*/ (0, _jsxruntime.jsx)(_triggerPrice.TriggerPriceItem, {
                qty: quantity,
                price: props.stopLossPrice,
                entryPrice: position.average_open_price,
                orderSide: order.side,
                orderType: _types.AlgoOrderType.STOP_LOSS,
                symbolInfo: symbolInfo
            }, "sl"));
        }
        return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
            children: msgs
        });
    }, [
        props.takeProfitPrice,
        props.stopLossPrice,
        position?.average_open_price,
        order?.side,
        order?.quantity,
        order?.algo_type
    ]);
    const child = (0, _react.useMemo)(()=>{
        const children = [];
        if (props.takeProfitPrice) {
            children.push(/*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Numeral, {
                className: (0, _utils.cn)("orderly-text-trade-profit orderly-gap-0  orderly-decoration-white/20"),
                rule: "price",
                children: props.takeProfitPrice,
                prefix: !props.stopLossPrice || direction === "column" ? /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                    className: "orderly-text-base-contrast-54",
                    children: "TP - "
                }) : ""
            }, "tp"));
        }
        if (props.stopLossPrice) {
            children.push(/*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Numeral, {
                className: (0, _utils.cn)("orderly-text-trade-loss orderly-gap-0 orderly-decoration-white/20 "),
                rule: "price",
                children: props.stopLossPrice,
                prefix: !props.takeProfitPrice || direction === "column" ? /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                    className: "orderly-text-base-contrast-54",
                    children: "SL - "
                }) : ""
            }, "sl"));
        }
        if (children.length === 0) return /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
            children: "-"
        });
        if (children.length === 2 && direction === "row") {
            children.splice(1, 0, /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                children: "/"
            }, "split"));
        }
        return children;
    }, [
        props.takeProfitPrice,
        props.stopLossPrice
    ]);
    const content = /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
        className: (0, _utils.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__*/ (0, _jsxruntime.jsx)(_tooltip.Tooltip, {
            content: pnl,
            children: content
        });
    }
    return content;
};

//# sourceMappingURL=tpslTriggerPrice.js.map