import { jsx as _jsx } from "react/jsx-runtime";
import { OrderSide, OrderStatus } from "@orderly.network/types";
import { Renew } from "../orderHistory/full/renew";
import { CancelButton } from "./full/cancelButton";
import { upperCaseFirstLetter } from "../../utils/string";
import { Text } from "../../text";
import { cx } from "class-variance-authority";
import { NumeralWithCtx } from "../../text/numeralWithCtx";
/// get columns for cancel/fill/reject/history
export const columnsBasis = (props)=>{
    const { status, onSymbolChange } = props || {};
    const columns = [
        {
            title: "Instrument",
            dataIndex: "symbol",
            width: 120,
            className: "orderly-h-[48px] orderly-font-semibold",
            render: (value)=>/*#__PURE__*/ _jsx(Text, {
                    rule: "symbol",
                    onClick: (e)=>{
                        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)=>{
                if (record.algo_order_id) {
                    return `Stop ` + `${record.type}`.toLowerCase();
                }
                return upperCaseFirstLetter(value);
            }
        },
        {
            title: "Side",
            className: "orderly-h-[48px]",
            width: 100,
            dataIndex: "side",
            render: (value, record)=>/*#__PURE__*/ _jsx("span", {
                    className: cx("orderly-font-semibold", value === OrderSide.BUY ? "orderly-text-trade-profit" : "orderly-text-trade-loss"),
                    children: upperCaseFirstLetter(value)
                })
        },
        {
            title: "Filled / Quantity",
            className: "orderly-h-[48px] orderly-font-semibold",
            dataIndex: "quantity",
            width: 200,
            render: (value, record)=>{
                return /*#__PURE__*/ _jsx("span", {
                    className: cx("orderly-font-semibold", record.side === OrderSide.BUY ? "orderly-text-trade-profit" : "orderly-text-trade-loss"),
                    children: `${record.total_executed_quantity} / ${record.quantity}`
                });
            }
        },
        {
            title: "Order Price",
            className: "orderly-h-[48px] orderly-font-semibold",
            dataIndex: "price",
            width: 100,
            render: (value, record)=>{
                if (record.type === "MARKET") {
                    return /*#__PURE__*/ _jsx("span", {
                        children: "Market"
                    });
                }
                return /*#__PURE__*/ _jsx(NumeralWithCtx, {
                    className: "orderly-font-semibold orderly-text-2xs",
                    children: value || "-"
                });
            }
        },
        {
            title: "Avg. price",
            width: 100,
            className: "orderly-h-[48px] orderly-font-semibold",
            dataIndex: "average_executed_price",
            render: (value, record)=>{
                return /*#__PURE__*/ _jsx(NumeralWithCtx, {
                    className: "orderly-font-semibold orderly-text-2xs",
                    children: value || "-"
                });
            }
        },
        {
            title: "Trigger",
            width: 100,
            className: "orderly-h-[48px] orderly-font-semibold",
            dataIndex: "trigger_price",
            render: (value, record)=>{
                return /*#__PURE__*/ _jsx(NumeralWithCtx, {
                    className: "orderly-font-semibold orderly-text-2xs",
                    children: value
                });
            }
        },
        {
            title: "Est. total",
            width: 100,
            className: "orderly-h-[48px] orderly-font-semibold",
            dataIndex: "executed",
            render: (value, record)=>{
                return /*#__PURE__*/ _jsx(NumeralWithCtx, {
                    className: "orderly-font-semibold orderly-text-2xs",
                    children: record.total_executed_quantity === 0 || Number.isNaN(record.average_executed_price) || record.average_executed_price === null ? "-" : `${record.total_executed_quantity * record.average_executed_price}`
                });
            }
        },
        {
            title: "Fee",
            width: 100,
            className: "orderly-h-[48px] orderly-font-semibold",
            dataIndex: "total_fee"
        },
        {
            title: "Status",
            width: 120,
            className: "orderly-h-[48px] orderly-font-semibold",
            dataIndex: "status",
            formatter: (value, record)=>{
                const status = value || record.algo_status;
                if (status === "NEW") {
                    return upperCaseFirstLetter("pending");
                }
                return upperCaseFirstLetter(status);
            }
        },
        {
            title: "Reduce",
            width: 80,
            dataIndex: "reduce_only",
            className: "orderly-h-[48px] orderly-font-semibold",
            render: (value)=>{
                return /*#__PURE__*/ _jsx("span", {
                    children: value ? "Yes" : "No"
                });
            }
        },
        {
            title: "Hidden",
            width: 80,
            dataIndex: "visible",
            className: "orderly-h-[48px] orderly-font-semibold",
            render: (value, record)=>{
                return /*#__PURE__*/ _jsx("span", {
                    children: record.visible_quantity !== 0 ? "No" : "Yes"
                });
            }
        },
        {
            title: "Order time",
            dataIndex: "created_time",
            width: 150,
            // onSort: status === OrderStatus.INCOMPLETE,
            className: "orderly-h-[48px]",
            render: (value)=>/*#__PURE__*/ _jsx(Text, {
                    rule: "date",
                    className: "orderly-break-normal orderly-whitespace-nowrap orderly-font-semibold",
                    children: value
                })
        }
    ];
    if (status !== OrderStatus.REJECTED && status !== OrderStatus.FILLED) {
        columns.push({
            title: "",
            dataIndex: "action",
            width: 120,
            className: "orderly-h-[48px] orderly-font-semibold !orderly-pr-2",
            align: "right",
            fixed: "right",
            render: (value, record)=>{
                if (record.status === OrderStatus.CANCELLED) {
                    return /*#__PURE__*/ _jsx(Renew, {
                        record: record
                    });
                }
                if (record.status === OrderStatus.NEW) {
                    return /*#__PURE__*/ _jsx(CancelButton, {
                        order: record
                    });
                }
                return null;
            }
        });
    }
    return columns;
};

//# sourceMappingURL=columnsUtil.js.map