import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Spinner } from "../../spinner";
import { Numeral } from "../../text";
import { usePrivateQuery, useSymbolsInfo } from "@orderly.network/hooks";
import { Decimal, timestampToString } from "@orderly.network/utils";
import { useMemo } from "react";
export const OrderTrades = (props)=>{
    const { record, index } = props;
    // const algoOrderId =
    //   "root_algo_order_id" in record
    //     ? record.root_algo_order_id
    //     : record.algo_order_id;
    const algoOrderId = record.algo_order_id;
    const path = algoOrderId !== undefined ? `/v1/algo/order/${algoOrderId}/trades` : `/v1/order/${record.order_id}/trades`;
    const { data } = usePrivateQuery(path);
    const base = record?.symbol?.split("_")?.[1] || "";
    const config = useSymbolsInfo();
    if (config.isNil) return null;
    // const symbolInfo = config ? config?.[record.symbol] : {};
    // const baseDp = symbolInfo?.("quote_dp") || 2;
    const symbolInfo = config[record.symbol];
    const quote_dp = symbolInfo("quote_dp", 2);
    // const quoteDp = symbolInfo("base_dp", 2);
    const base_dp = symbolInfo("base_dp", 2);
    const body = useMemo(()=>{
        if (data === undefined) {
            return /*#__PURE__*/ _jsx("tr", {
                children: /*#__PURE__*/ _jsx("td", {
                    colSpan: 5,
                    children: /*#__PURE__*/ _jsxs("div", {
                        className: "orderly-flex orderly-h-[27.5px]",
                        children: [
                            /*#__PURE__*/ _jsx("div", {
                                className: "orderly-flex-1"
                            }),
                            /*#__PURE__*/ _jsx(Spinner, {
                                size: "small",
                                className: "orderly-block"
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                className: "orderly-flex-1"
                            })
                        ]
                    })
                })
            });
        }
        if (data.length === 0) {
            return /*#__PURE__*/ _jsxs("tr", {
                className: "orderly-text-base-contrast-54",
                children: [
                    /*#__PURE__*/ _jsx("td", {
                        className: "orderly-py-1",
                        children: "-"
                    }),
                    /*#__PURE__*/ _jsx("td", {
                        className: "orderly-py-1",
                        children: "-"
                    }),
                    /*#__PURE__*/ _jsx("td", {
                        className: "orderly-py-1",
                        children: "-"
                    }),
                    /*#__PURE__*/ _jsx("td", {
                        className: "orderly-py-1",
                        children: "-"
                    }),
                    /*#__PURE__*/ _jsx("td", {
                        className: "orderly-py-1",
                        children: "-"
                    })
                ]
            });
        }
        return data.map((item)=>{
            const data = timestampToString(item.executed_timestamp);
            const price = item.executed_price;
            const qty = item.executed_quantity;
            const total = new Decimal(price).mul(qty).toNumber();
            return /*#__PURE__*/ _jsxs("tr", {
                className: "orderly-text-base-contrast-54",
                children: [
                    /*#__PURE__*/ _jsx("td", {
                        className: "orderly-py-1",
                        children: item.id
                    }),
                    /*#__PURE__*/ _jsx("td", {
                        className: "orderly-py-1",
                        children: data
                    }),
                    /*#__PURE__*/ _jsx("td", {
                        className: "orderly-py-1",
                        children: /*#__PURE__*/ _jsx(Numeral, {
                            precision: quote_dp,
                            children: price
                        })
                    }),
                    /*#__PURE__*/ _jsx("td", {
                        className: "orderly-py-1",
                        children: /*#__PURE__*/ _jsx(Numeral, {
                            precision: base_dp,
                            children: qty
                        })
                    }),
                    /*#__PURE__*/ _jsx("td", {
                        className: "orderly-py-1",
                        children: /*#__PURE__*/ _jsx(Numeral, {
                            precision: quote_dp,
                            children: total
                        })
                    })
                ]
            });
        });
    }, [
        data
    ]);
    return /*#__PURE__*/ _jsx("div", {
        className: "orderly-flex orderly-min-h-[50px] orderly-pb-1 orderly-max-h-[266px] orderly-overflow-auto",
        children: /*#__PURE__*/ _jsxs("table", {
            className: "orderly-w-full orderly-mx-6 orderly-text-2xs",
            children: [
                /*#__PURE__*/ _jsx("thead", {
                    className: "orderly-py-2 orderly-text-left orderly-text-base-contrast-36 orderly-sticky",
                    children: /*#__PURE__*/ _jsxs("tr", {
                        className: "orderly-bg-base-700",
                        children: [
                            /*#__PURE__*/ _jsx("th", {
                                className: "orderly-w-1/5 orderly-pt-2 orderly-bg-base-700 orderly-sticky orderly-top-0",
                                children: "Transaction ID"
                            }),
                            /*#__PURE__*/ _jsx("th", {
                                className: "orderly-w-1/5 orderly-pt-2 orderly-bg-base-700 orderly-sticky orderly-top-0",
                                children: "Date"
                            }),
                            /*#__PURE__*/ _jsx("th", {
                                className: "orderly-w-1/5 orderly-pt-2 orderly-bg-base-700 orderly-sticky orderly-top-0",
                                children: "Price (USDC)"
                            }),
                            /*#__PURE__*/ _jsx("th", {
                                className: "orderly-w-1/5 orderly-pt-2 orderly-bg-base-700 orderly-sticky orderly-top-0",
                                children: `Qty (${base})`
                            }),
                            /*#__PURE__*/ _jsx("th", {
                                className: "orderly-w-1/5 orderly-pt-2 orderly-bg-base-700 orderly-sticky orderly-top-0",
                                children: "Total (USDC)"
                            })
                        ]
                    })
                }),
                /*#__PURE__*/ _jsx("tbody", {
                    children: body
                })
            ]
        })
    });
};

//# sourceMappingURL=orderTrades.js.map