"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Listview", {
    enumerable: true,
    get: function() {
        return Listview;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _table = require("../../../table");
const _text = require("../../../text");
const _types = require("@orderly.network/types");
const _classvarianceauthority = require("class-variance-authority");
const _string = require("../../../utils/string");
const _provider = require("../../../provider");
const _cancelButton = require("./cancelButton");
const _quantity = require("./quantity");
const _price = require("./price");
const _css = require("../../../utils/css");
const _columnsUtil = require("../columnsUtil");
const _orderTrades = require("../../../block/orderHistory/orderTrades");
const _triggerPrice = require("./triggerPrice");
const _ordersEmptyView = require("./ordersEmptyView");
const Listview = (props)=>{
    const columns = (0, _react.useMemo)(()=>{
        // const columns = columnsBasis();
        // if status is incomplete then return this columns, else return columnsBasis
        if (props.status === _types.OrderStatus.INCOMPLETE) {
            const columns = [
                {
                    title: "Instrument",
                    dataIndex: "symbol",
                    className: "orderly-h-[48px]",
                    width: 120,
                    onSort: props.status === _types.OrderStatus.INCOMPLETE ? (r1, r2, sortOrder)=>{
                        if (sortOrder === "asc") {
                            return r1.symbol.localeCompare(r2.symbol);
                        }
                        return r2.symbol.localeCompare(r1.symbol);
                    } : undefined,
                    render: (value)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Text, {
                            rule: "symbol",
                            className: "orderly-font-semibold",
                            onClick: (e)=>{
                                props.onSymbolChange?.({
                                    symbol: value
                                });
                                e.stopPropagation();
                                e.preventDefault();
                            },
                            children: value
                        })
                },
                {
                    title: "Type",
                    width: 100,
                    className: "orderly-h-[48px] orderly-font-semibold",
                    dataIndex: "type",
                    formatter: (value, record)=>{
                        const type = typeof record.type === "string" ? record.type.replace("_ORDER", "").toLowerCase() : record.type;
                        if (record.algo_order_id) {
                            return `Stop ${type}`;
                        }
                        return (0, _string.upperCaseFirstLetter)(value);
                    }
                },
                {
                    title: "Side",
                    width: 100,
                    className: "orderly-h-[48px]",
                    dataIndex: "side",
                    onSort: props.status === _types.OrderStatus.INCOMPLETE ? (r1, r2, sortOrder)=>{
                        if (sortOrder === "asc") {
                            return r2.side.localeCompare(r1.side);
                        }
                        return r1.side.localeCompare(r2.side);
                    } : undefined,
                    render: (value)=>/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                            className: (0, _classvarianceauthority.cx)("orderly-font-semibold", value === _types.OrderSide.BUY ? "orderly-text-trade-profit" : "orderly-text-trade-loss"),
                            children: (0, _string.upperCaseFirstLetter)(value)
                        })
                },
                {
                    title: "Filled / Quantity",
                    className: "orderly-h-[48px] orderly-ui-pending-list-input-container orderly-ui-pending-list-quantity-input-container",
                    dataIndex: "quantity",
                    width: 120,
                    onSort: props.status === _types.OrderStatus.INCOMPLETE,
                    render: (value, record)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_quantity.OrderQuantity, {
                            order: record
                        })
                },
                {
                    title: "Price",
                    className: "orderly-h-[48px] orderly-ui-pending-list-input-container rderly-ui-pending-list-price-input-container",
                    dataIndex: "price",
                    width: 120,
                    onSort: props.status === _types.OrderStatus.INCOMPLETE,
                    render: (value, record)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_price.Price, {
                            order: record
                        })
                },
                {
                    title: "Trigger",
                    className: "orderly-h-[48px] orderly-ui-pending-list-input-container orderly-ui-pending-list-trigger-input-container",
                    dataIndex: "trigger_price",
                    width: 120,
                    // onSort: props.status === OrderStatus.INCOMPLETE,
                    render: (value, record)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_triggerPrice.TriggerPrice, {
                            order: record
                        })
                },
                {
                    title: "Est. total",
                    width: 100,
                    className: "orderly-h-[48px] orderly-font-semibold",
                    dataIndex: "executed",
                    render: (value, record)=>{
                        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Numeral, {
                            className: "orderly-font-semibold orderly-text-2xs orderly-text-base-contrast-80",
                            precision: 2,
                            children: record.quantity === 0 || Number.isNaN(record.price) || record.price === null ? "--" : `${record.quantity * record.price}`
                        });
                    }
                },
                {
                    title: "Reduce",
                    dataIndex: "reduce_only",
                    width: 100,
                    className: "orderly-h-[48px] orderly-font-semibold",
                    render: (value)=>{
                        return /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                            children: value ? "Yes" : "No"
                        });
                    }
                },
                {
                    title: "Hidden",
                    dataIndex: "visible",
                    width: 100,
                    className: "orderly-h-[48px] orderly-font-semibold",
                    render: (value, record)=>{
                        // @ts-ignore
                        return /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                            children: record.visible_quantity !== 0 ? "No" : "Yes"
                        });
                    }
                },
                {
                    title: "Order time",
                    dataIndex: "created_time",
                    width: 150,
                    onSort: props.status === _types.OrderStatus.INCOMPLETE,
                    className: "orderly-h-[48px]",
                    render: (value)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Text, {
                            rule: "date",
                            className: "orderly-break-normal orderly-whitespace-nowrap orderly-font-semibold",
                            children: value
                        })
                },
                {
                    title: "",
                    dataIndex: "action",
                    className: "orderly-h-[48px]",
                    align: "right",
                    fixed: "right",
                    width: 100,
                    render: (_, record)=>{
                        if (props.status === _types.OrderStatus.INCOMPLETE) {
                            return /*#__PURE__*/ (0, _jsxruntime.jsx)(_cancelButton.CancelButton, {
                                order: record
                            });
                        }
                        return null;
                    }
                }
            ];
            // columns.push();
            return columns;
        } else {
            return (0, _columnsUtil.columnsBasis)({
                status: props.status,
                onSymbolChange: props.onSymbolChange
            });
        }
    }, [
        props.status
    ]);
    const divRef = (0, _react.useRef)(null);
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
        ref: divRef,
        className: "orderly-h-full orderly-overflow-y-auto",
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsx)(_table.Table, {
                bordered: true,
                justified: true,
                showMaskElement: false,
                columns: columns,
                dataSource: props.dataSource,
                loadMore: props.loadMore,
                headerClassName: "orderly-text-2xs orderly-text-base-contrast-54 orderly-py-3 orderly-bg-base-900",
                className: (0, _css.cn)("orderly-text-2xs orderly-text-base-contrast-80", props.className),
                generatedRowKey: (record, index)=>`${index}${record.order_id || record.algo_order_id}`,
                renderRowContainer: (record, index, children)=>{
                    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_provider.SymbolProvider, {
                        symbol: record.symbol,
                        children: children
                    }, index);
                },
                expandRowRender: props.status === "FILLED" ? (record, index)=>{
                    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_orderTrades.OrderTrades, {
                        record: record,
                        index: index
                    });
                } : undefined
            }),
            (!props.dataSource || props.dataSource.length <= 0) && /*#__PURE__*/ (0, _jsxruntime.jsx)(_ordersEmptyView.OrdersEmptyView, {
                watchRef: divRef,
                left: 0,
                right: props.status === _types.OrderStatus.INCOMPLETE ? 100 : 120
            })
        ]
    });
};

//# sourceMappingURL=listview.js.map