"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "OrderTrades", {
    enumerable: true,
    get: function() {
        return OrderTrades;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _spinner = require("../../spinner");
const _text = require("../../text");
const _hooks = require("@orderly.network/hooks");
const _utils = require("@orderly.network/utils");
const _react = require("react");
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 } = (0, _hooks.usePrivateQuery)(path);
    const base = record?.symbol?.split("_")?.[1] || "";
    const config = (0, _hooks.useSymbolsInfo)();
    if (config.isNil) return null;
    // const symbolInfo = config ? config?.[record.symbol] : {};
    // const baseDp = symbolInfo?.("quote_dp") || 2;
    const symbolInfo = config[record.symbol];
    const baseDp = symbolInfo("quote_dp", 2);
    const body = (0, _react.useMemo)(()=>{
        if (data === undefined) {
            return /*#__PURE__*/ (0, _jsxruntime.jsx)("tr", {
                children: /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                    colSpan: 5,
                    children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        className: "orderly-flex orderly-h-[27.5px]",
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                className: "orderly-flex-1"
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_spinner.Spinner, {
                                size: "small",
                                className: "orderly-block"
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                className: "orderly-flex-1"
                            })
                        ]
                    })
                })
            });
        }
        if (data.length === 0) {
            return /*#__PURE__*/ (0, _jsxruntime.jsxs)("tr", {
                className: "orderly-text-base-contrast-54",
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                        className: "orderly-py-1",
                        children: "-"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                        className: "orderly-py-1",
                        children: "-"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                        className: "orderly-py-1",
                        children: "-"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                        className: "orderly-py-1",
                        children: "-"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                        className: "orderly-py-1",
                        children: "-"
                    })
                ]
            });
        }
        return data.map((item)=>{
            const data = (0, _utils.timestampToString)(item.executed_timestamp);
            const price = item.executed_price;
            const qty = item.executed_quantity;
            const total = new _utils.Decimal(price).mul(qty).toNumber();
            return /*#__PURE__*/ (0, _jsxruntime.jsxs)("tr", {
                className: "orderly-text-base-contrast-54",
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                        className: "orderly-py-1",
                        children: item.id
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                        className: "orderly-py-1",
                        children: data
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                        className: "orderly-py-1",
                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Numeral, {
                            precision: baseDp,
                            children: price
                        })
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                        className: "orderly-py-1",
                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Numeral, {
                            precision: baseDp,
                            children: qty
                        })
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
                        className: "orderly-py-1",
                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Numeral, {
                            precision: baseDp,
                            children: total
                        })
                    })
                ]
            });
        });
    }, [
        data
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
        className: "orderly-flex orderly-min-h-[50px] orderly-pb-1 orderly-max-h-[266px] orderly-overflow-auto",
        children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("table", {
            className: "orderly-w-full orderly-mx-6 orderly-text-2xs",
            children: [
                /*#__PURE__*/ (0, _jsxruntime.jsx)("thead", {
                    className: "orderly-py-2 orderly-text-left orderly-text-base-contrast-36 orderly-sticky",
                    children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("tr", {
                        className: "orderly-bg-base-700",
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("th", {
                                className: "orderly-w-1/5 orderly-pt-2 orderly-bg-base-700 orderly-sticky orderly-top-0",
                                children: "Transaction ID"
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("th", {
                                className: "orderly-w-1/5 orderly-pt-2 orderly-bg-base-700 orderly-sticky orderly-top-0",
                                children: "Date"
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("th", {
                                className: "orderly-w-1/5 orderly-pt-2 orderly-bg-base-700 orderly-sticky orderly-top-0",
                                children: "Price (USDC)"
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("th", {
                                className: "orderly-w-1/5 orderly-pt-2 orderly-bg-base-700 orderly-sticky orderly-top-0",
                                children: `Qty (${base})`
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("th", {
                                className: "orderly-w-1/5 orderly-pt-2 orderly-bg-base-700 orderly-sticky orderly-top-0",
                                children: "Total (USDC)"
                            })
                        ]
                    })
                }),
                /*#__PURE__*/ (0, _jsxruntime.jsx)("tbody", {
                    children: body
                })
            ]
        })
    });
};

//# sourceMappingURL=orderTrades.js.map