import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { SymbolContext } from "../../provider";
import { Statistic } from "../../statistic";
import { Tag } from "../../tag";
import { Text } from "../../text";
import { upperCaseFirstLetter } from "../../utils/string";
import { AlgoOrderRootType } from "@orderly.network/types";
import { OrderSide, OrderType } from "@orderly.network/types";
import { useContext, useMemo } from "react";
import { OrderTypeTag } from "./typeTag";
export const Cell = (props)=>{
    const { item } = props;
    const { quote, quote_dp, base, base_dp } = useContext(SymbolContext);
    const typeTag = useMemo(()=>{
        if (item.side === OrderSide.SELL) {
            return /*#__PURE__*/ _jsx(Tag, {
                color: "sell",
                size: "small",
                children: "Sell"
            });
        }
        return /*#__PURE__*/ _jsx(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 = useMemo(()=>{
        const status = item.status || item.algo_status;
        if (status === "NEW") {
            return upperCaseFirstLetter("pending");
        }
        return upperCaseFirstLetter(status);
    }, [
        item.status,
        item.algo_status
    ]);
    const qty = useMemo(()=>{
        if (item.parent_algo_type === AlgoOrderRootType.POSITIONAL_TP_SL) {
            return /*#__PURE__*/ _jsx("span", {
                children: "Entire position"
            });
        }
        return item.quantity ?? "-";
    }, [
        item
    ]);
    return /*#__PURE__*/ _jsxs("div", {
        className: "orderly-px-4 orderly-py-2",
        children: [
            /*#__PURE__*/ _jsxs("div", {
                className: "orderly-mb-1 orderly-flex orderly-items-start orderly-justify-between",
                children: [
                    /*#__PURE__*/ _jsxs("div", {
                        className: "orderly-flex-col",
                        children: [
                            /*#__PURE__*/ _jsxs("div", {
                                className: "orderly-flex orderly-items-center orderly-gap-2 ",
                                children: [
                                    typeTag,
                                    /*#__PURE__*/ _jsx("div", {
                                        className: "orderly-flex-1 orderly-text-2xs",
                                        onClick: onSymbol,
                                        children: /*#__PURE__*/ _jsx(Text, {
                                            rule: "symbol",
                                            children: item.symbol
                                        })
                                    })
                                ]
                            }),
                            /*#__PURE__*/ _jsx(OrderTypeTag, {
                                order: item
                            })
                        ]
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: "orderly-text-4xs orderly-text-base-contrast-36 orderly-flex orderly-flex-col orderly-gap-1",
                        children: [
                            /*#__PURE__*/ _jsx("div", {
                                className: "orderly-text-3xs orderly-text-base-contrast-80 orderly-text-right",
                                children: state
                            }),
                            /*#__PURE__*/ _jsx(Text, {
                                rule: "date",
                                children: item.created_time
                            })
                        ]
                    })
                ]
            }),
            /*#__PURE__*/ _jsxs("div", {
                className: "orderly-grid orderly-grid-cols-3 orderly-gap-2",
                children: [
                    /*#__PURE__*/ _jsx(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 === AlgoOrderRootType.POSITIONAL_TP_SL ? "" : item.side === OrderSide.BUY ? "orderly-text-trade-profit" : "orderly-text-trade-loss"
                    }),
                    /*#__PURE__*/ _jsx(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__*/ _jsx(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__*/ _jsx(_Fragment, {
                            children: /*#__PURE__*/ _jsx("span", {
                                className: "orderly-text-base-contrast-36",
                                children: "Trigger price"
                            })
                        }),
                        value: item.type === OrderType.MARKET || item.type === OrderType.STOP_MARKET ? "Market" : item.trigger_price,
                        align: "right"
                    }),
                    /*#__PURE__*/ _jsx(Statistic, {
                        label: /*#__PURE__*/ _jsx(_Fragment, {
                            children: /*#__PURE__*/ _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__*/ _jsx(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__*/ _jsx(_Fragment, {
                            children: /*#__PURE__*/ _jsx("span", {
                                className: "orderly-text-base-contrast-36",
                                children: "Order price"
                            })
                        }),
                        value: item.type === OrderType.MARKET ? "Market" : item.price
                    }),
                    /*#__PURE__*/ _jsx(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__*/ _jsx(_Fragment, {
                            children: /*#__PURE__*/ _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