"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Cell", {
    enumerable: true,
    get: function() {
        return Cell;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _provider = require("../../provider");
const _statistic = require("../../statistic");
const _tag = require("../../tag");
const _text = require("../../text");
const _string = require("../../utils/string");
const _types = require("@orderly.network/types");
const _react = require("react");
const _typeTag = require("./typeTag");
const Cell = (props)=>{
    const { item } = props;
    const { quote, quote_dp, base, base_dp } = (0, _react.useContext)(_provider.SymbolContext);
    const typeTag = (0, _react.useMemo)(()=>{
        if (item.side === _types.OrderSide.SELL) {
            return /*#__PURE__*/ (0, _jsxruntime.jsx)(_tag.Tag, {
                color: "sell",
                size: "small",
                children: "Sell"
            });
        }
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_tag.Tag, {
            color: "buy",
            size: "small",
            children: "Buy"
        });
    }, [
        item
    ]);
    const onSymbol = ()=>{
        props.onSymbolChange?.({
            symbol: item.symbol
        });
        // go to the top of page
        window.scrollTo(0, 0);
    };
    const state = (0, _react.useMemo)(()=>{
        const status = item.status || item.algo_status;
        if (status === "NEW") {
            return (0, _string.upperCaseFirstLetter)("pending");
        }
        return (0, _string.upperCaseFirstLetter)(status);
    }, [
        item.status,
        item.algo_status
    ]);
    const qty = (0, _react.useMemo)(()=>{
        if (item.parent_algo_type === _types.AlgoOrderRootType.POSITIONAL_TP_SL) {
            return /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                children: "Entire position"
            });
        }
        return item.quantity ?? "-";
    }, [
        item
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
        className: "orderly-px-4 orderly-py-2",
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                className: "orderly-mb-1 orderly-flex orderly-items-start orderly-justify-between",
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        className: "orderly-flex-col",
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                                className: "orderly-flex orderly-items-center orderly-gap-2 ",
                                children: [
                                    typeTag,
                                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                        className: "orderly-flex-1 orderly-text-2xs",
                                        onClick: onSymbol,
                                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Text, {
                                            rule: "symbol",
                                            children: item.symbol
                                        })
                                    })
                                ]
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_typeTag.OrderTypeTag, {
                                order: item
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        className: "orderly-text-4xs orderly-text-base-contrast-36 orderly-flex orderly-flex-col orderly-gap-1",
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                className: "orderly-text-3xs orderly-text-base-contrast-80 orderly-text-right",
                                children: state
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Text, {
                                rule: "date",
                                children: item.created_time
                            })
                        ]
                    })
                ]
            }),
            /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                className: "orderly-grid orderly-grid-cols-3 orderly-gap-2",
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_statistic.Statistic, {
                        label: "Qty.",
                        labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
                        valueClassName: "orderly-text-3xs",
                        value: qty,
                        rule: "price",
                        precision: base_dp,
                        className: item.parent_algo_type === _types.AlgoOrderRootType.POSITIONAL_TP_SL ? "" : item.side === _types.OrderSide.BUY ? "orderly-text-trade-profit" : "orderly-text-trade-loss"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_statistic.Statistic, {
                        label: "Filled",
                        labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
                        valueClassName: "orderly-text-3xs orderly-text-base-contrast-80",
                        // @ts-ignore
                        value: item.total_executed_quantity ?? "-",
                        rule: "price",
                        precision: base_dp
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_statistic.Statistic, {
                        labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
                        valueClassName: "orderly-text-3xs orderly-text-base-contrast-80",
                        rule: "price",
                        precision: quote_dp,
                        label: /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
                            children: /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                                className: "orderly-text-base-contrast-36",
                                children: "Trigger price"
                            })
                        }),
                        value: item.type === _types.OrderType.MARKET || item.type === _types.OrderType.STOP_MARKET ? "Market" : item.trigger_price,
                        align: "right"
                    }),
                    /*#__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: "Avg. price"
                            })
                        }),
                        labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
                        valueClassName: "orderly-text-3xs orderly-text-base-contrast-80",
                        rule: "price",
                        precision: quote_dp,
                        value: item.average_executed_price ?? "-"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_statistic.Statistic, {
                        labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
                        valueClassName: "orderly-text-3xs orderly-text-base-contrast-80",
                        rule: "price",
                        precision: quote_dp,
                        label: /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
                            children: /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                                className: "orderly-text-base-contrast-36",
                                children: "Order price"
                            })
                        }),
                        value: item.type === _types.OrderType.MARKET ? "Market" : item.price
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_statistic.Statistic, {
                        labelClassName: "orderly-text-4xs orderly-text-base-contrast-36",
                        valueClassName: "orderly-text-3xs",
                        rule: "price",
                        precision: 2,
                        prefix: item.realized_pnl > 0 ? '+' : '',
                        label: /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
                            children: /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                                className: "orderly-text-base-contrast-36",
                                children: "Realized PnL(USDC)"
                            })
                        }),
                        className: item.realized_pnl === 0 ? "" : item.realized_pnl > 0 ? "orderly-text-trade-profit" : "orderly-text-trade-loss",
                        value: item.realized_pnl === 0 ? '-' : item.realized_pnl,
                        align: "right"
                    })
                ]
            })
        ]
    });
};

//# sourceMappingURL=cell.js.map