"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TPSLListView", {
    enumerable: true,
    get: function() {
        return TPSLListView;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _types = require("@orderly.network/types");
const _react = require("react");
const _table = require("../../table");
const _text = require("../../text");
const _string = require("../../utils/string");
const _classvarianceauthority = require("class-variance-authority");
const _quantity = require("../../block/orders/full/quantity");
const _cancelButton = require("./cancelButton");
const _utils = require("../../utils");
const _algoOrderTypeBadge = require("./algoOrderTypeBadge");
const _provider = require("../../provider");
const _tpslOrderRowContext = require("../../block/tp_sl/tpslOrderRowContext");
const _utils1 = require("@orderly.network/utils");
const _orderPrice = require("./orderPrice");
const _orderTriggerPrice = require("./orderTriggerPrice");
const _editButton = require("./editButton");
const TPSLListView = (props)=>{
    const columns = (0, _react.useMemo)(()=>{
        const columns = [
            {
                title: "Instrument",
                dataIndex: "symbol",
                className: "orderly-h-[48px]",
                width: 120,
                onSort: (r1, r2, sortOrder)=>{
                    if (sortOrder === "asc") {
                        return r1.symbol.localeCompare(r2.symbol);
                    }
                    return r2.symbol.localeCompare(r1.symbol);
                },
                render: (value, record)=>/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        className: "orderly-flex orderly-flex-col orderly-py-1",
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_text.Text, {
                                rule: "symbol",
                                className: "orderly-font-semibold",
                                onClick: (e)=>{
                                    props.onSymbolChange?.({
                                        symbol: value
                                    });
                                    e.stopPropagation();
                                    e.preventDefault();
                                },
                                children: value
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_algoOrderTypeBadge.AlgoOrderBadge, {
                                order: record
                            })
                        ]
                    })
            },
            {
                title: "Side",
                width: 100,
                className: "orderly-h-[48px]",
                dataIndex: "side",
                onSort: (r1, r2, sortOrder)=>{
                    if (sortOrder === "asc") {
                        return r2.side.localeCompare(r1.side);
                    }
                    return r1.side.localeCompare(r2.side);
                },
                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: "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 === OrderStatus.INCOMPLETE,
                render: (value, record)=>{
                    if (record.algo_type === _types.AlgoOrderRootType.POSITIONAL_TP_SL) {
                        return "Entire position";
                    }
                    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_quantity.OrderQuantity, {
                        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)=>{
                    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_orderTriggerPrice.OrderTriggerPrice, {});
                }
            },
            {
                title: "Price",
                className: "orderly-h-[48px] orderly-ui-pending-list-input-container rderly-ui-pending-list-price-input-container",
                dataIndex: "price",
                width: 80,
                render: (value)=>{
                    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_orderPrice.OrderPrice, {});
                }
            },
            {
                title: "Notional",
                width: 100,
                className: "orderly-h-[48px] orderly-font-semibold",
                dataIndex: "executed",
                render: (value, record)=>{
                    if (record.algo_type === _types.AlgoOrderRootType.POSITIONAL_TP_SL) {
                        return "Entire position";
                    }
                    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 ? "--" : `${new _utils1.Decimal(record.mark_price).mul(record.quantity).todp(2).toNumber()}`
                    });
                }
            },
            {
                title: "Reduce-only",
                dataIndex: "reduce_only",
                width: 100,
                className: "orderly-h-[48px] orderly-font-semibold",
                render: (value, record)=>{
                    return /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                        children: record.child_orders[0].reduce_only ? "Yes" : "No"
                    });
                }
            },
            // {
            //   title: "Hidden",
            //   dataIndex: "visible",
            //   width: 100,
            //   className: "orderly-h-[48px] orderly-font-semibold",
            //   render: (value: number, record) => {
            //     // @ts-ignore
            //     return <span>{record.visible_quantity !== 0 ? "No" : "Yes"}</span>;
            //   },
            // },
            {
                title: "Order time",
                dataIndex: "created_time",
                width: 150,
                onSort: true,
                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: 160,
                render: (_, record)=>{
                    return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        className: "orderly-flex orderly-space-x-2 orderly-justify-end",
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_editButton.EditButton, {}),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_cancelButton.CancelButton, {})
                        ]
                    });
                }
            }
        ];
        // columns.push();
        return columns;
    }, []);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
        className: "orderly-h-full orderly-overflow-y-auto",
        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_table.Table, {
            bordered: true,
            justified: true,
            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),
            columns: columns,
            dataSource: props.dataSource,
            renderRowContainer: (record, index, children)=>{
                return /*#__PURE__*/ (0, _jsxruntime.jsx)(_provider.SymbolProvider, {
                    symbol: record.symbol,
                    children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_tpslOrderRowContext.TPSLOrderRowProvider, {
                        order: record,
                        children: children
                    })
                });
            }
        })
    });
};

//# sourceMappingURL=tpsl_listview.js.map