"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 _types = require("@orderly.network/types");
const _classvarianceauthority = require("class-variance-authority");
const _string = require("../../../utils/string");
const _provider = require("../../../provider");
const _utils = require("../../../utils");
const _columnsUtil = require("../../../block/orders/columnsUtil");
const _orderTrades = require("../orderTrades");
const _positionEmptyView = require("../../../block/positions/full/positionEmptyView");
const Listview = (props)=>{
    const columns = (0, _react.useMemo)(()=>{
        const cols = (0, _columnsUtil.columnsBasis)({
            onSymbolChange: props.onSymbolChange
        });
        //
        cols[2] = {
            title: "Side",
            className: "orderly-h-[48px]",
            width: 100,
            dataIndex: "side",
            render: (value, record)=>/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                    className: (0, _classvarianceauthority.cx)("orderly-font-semibold", {
                        "orderly-text-trade-profit": record.status !== _types.OrderStatus.CANCELLED && record.status !== _types.OrderStatus.REJECTED && value === _types.OrderSide.BUY,
                        "orderly-text-trade-loss": record.status !== _types.OrderStatus.CANCELLED && record.status !== _types.OrderStatus.REJECTED && value === _types.OrderSide.SELL
                    }),
                    children: (0, _string.upperCaseFirstLetter)(value)
                })
        };
        cols[3] = {
            title: "Filled / Quantity",
            className: "orderly-h-[48px] orderly-font-semibold",
            dataIndex: "quantity",
            width: 200,
            render: (value, record)=>{
                return /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                    className: (0, _classvarianceauthority.cx)("orderly-font-semibold", {
                        "orderly-text-trade-profit": record.status !== _types.OrderStatus.CANCELLED && record.status !== _types.OrderStatus.REJECTED && record.side === _types.OrderSide.BUY,
                        "orderly-text-trade-loss": record.status !== _types.OrderStatus.CANCELLED && record.status !== _types.OrderStatus.REJECTED && record.side === _types.OrderSide.SELL
                    }),
                    children: `${record.total_executed_quantity} / ${record.quantity}`
                });
            }
        };
        return cols;
    }, []);
    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,
                loading: props.loading,
                dataSource: props.dataSource,
                headerClassName: "orderly-text-2xs orderly-text-base-contrast-54 orderly-py-3 orderly-bg-base-900",
                className: (0, _utils.cn)("orderly-text-2xs orderly-text-base-contrast-80", props.className),
                generatedRowKey: (record, index)=>`${index}${record.order_id || record.algo_order_id}`,
                onRow: (record)=>{
                    // console.log(record);
                    if (record.status === _types.OrderStatus.CANCELLED) {
                        return {
                            className: "orderly-text-base-contrast-20",
                            "data-cancelled": "true"
                        };
                    }
                    return {};
                },
                renderRowContainer: (record, index, children)=>{
                    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_provider.SymbolProvider, {
                        symbol: record.symbol,
                        children: children
                    }, index);
                },
                expandRowRender: (record, index)=>{
                    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_orderTrades.OrderTrades, {
                        record: record,
                        index: index
                    });
                },
                scrollToEnd: ()=>{
                    if (!props.loading) {
                        props.loadMore?.();
                    }
                }
            }),
            (!props.dataSource || props.dataSource.length <= 0) && /*#__PURE__*/ (0, _jsxruntime.jsx)(_positionEmptyView.PositionEmptyView, {
                watchRef: divRef,
                left: 0,
                right: 120
            })
        ]
    });
};

//# sourceMappingURL=listview.js.map