import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { TabPane, Tabs } from "../../../../../tab";
import { memo, useCallback, useState } from "react";
import { PositionPane } from "./positions";
import { MyOrders } from "./orders";
import { OrderStatus } from "@orderly.network/types";
import { MemoizedOrdersTabTitle } from "../../../../../page/trading/mobile/sections/dataList/orders/tabTitle";
import { TabBarExtraNode } from "../../../../../page/trading/desktop/sections/datalist/tabbarExtraNode";
import { HistoryView } from "./history";
import { usePositionStream, useSessionStorage } from "@orderly.network/hooks";
import { DecimalPrecisionType } from "./decimalPrecisionCheckBox";
import { UnPnlPriceBasisType } from "./unPnlPriceBasisCheckBox";
export const DataListView = ()=>{
    const [activeTab, setActiveTab] = useState("positions");
    const [data] = usePositionStream();
    const hasPositions = (data.rows?.length || 0) > 0;
    const [decimalPrecision, setDecimalPrecision] = useSessionStorage("orderly_dicimal_precision_key", DecimalPrecisionType.TWO);
    const [unPnlPriceBasis, setUnPnlPriceBasic] = useSessionStorage("orderly_unrealized_pnl_price_basis_key", UnPnlPriceBasisType.MARKET_PRICE);
    // const [orderStatus, setOrderStatus] = useSessionStorage(
    //   "orderly_order_status",
    //   "positions"
    // );
    const onTabChange = useCallback((value)=>{
        setActiveTab(value);
    // setOrderStatus(
    //   {
    //     positions: "positions",
    //     orders: OrderStatus.INCOMPLETE,
    //     filled: OrderStatus.FILLED,
    //     cancelled: OrderStatus.CANCELLED,
    //     rejected: OrderStatus.REJECTED,
    //     history: "history",
    //   }[value]
    // );
    }, []);
    return /*#__PURE__*/ _jsxs(Tabs, {
        autoFit: true,
        value: activeTab,
        onTabChange: onTabChange,
        tabBarClassName: "orderly-h-[48px] orderly-text-sm desktop:orderly-font-semibold",
        tabBarExtra: /*#__PURE__*/ _jsx(TabBarExtraNode, {
            decimalPrecision: decimalPrecision,
            setDecimalPrecision: setDecimalPrecision,
            unPnlPriceBasis: unPnlPriceBasis,
            setUnPnlPriceBasic: setUnPnlPriceBasic
        }),
        extraData: {
            showAllSymbol: false,
            // value is 0 1 2
            pnlNotionalDecimalPrecision: decimalPrecision,
            // 0: mark price 1: last price
            unPnlPriceBasis: unPnlPriceBasis
        },
        children: [
            /*#__PURE__*/ _jsx(TabPane, {
                title: hasPositions ? `Positions(${data.rows?.length})` : "Positions",
                value: "positions",
                className: "orderly-px-3",
                children: /*#__PURE__*/ _jsx(PositionPane, {
                    unPnlPriceBasis: unPnlPriceBasis,
                    setUnPnlPriceBasic: setUnPnlPriceBasic
                })
            }),
            /*#__PURE__*/ _jsx(TabPane, {
                title: /*#__PURE__*/ _jsx(MemoizedOrdersTabTitle, {}),
                value: "orders",
                className: "orderly-px-3",
                children: /*#__PURE__*/ _jsx(MyOrders, {
                    status: OrderStatus.INCOMPLETE
                })
            }),
            /*#__PURE__*/ _jsx(TabPane, {
                title: "Filled",
                value: "filled",
                className: "orderly-px-3",
                children: /*#__PURE__*/ _jsx(MyOrders, {
                    status: OrderStatus.FILLED
                })
            }),
            /*#__PURE__*/ _jsx(TabPane, {
                title: "Cancelled",
                value: "cancelled",
                className: "orderly-px-3",
                children: /*#__PURE__*/ _jsx(MyOrders, {
                    status: OrderStatus.CANCELLED
                })
            }),
            /*#__PURE__*/ _jsx(TabPane, {
                title: "Rejected",
                value: "rejected",
                className: "orderly-px-3",
                children: /*#__PURE__*/ _jsx(MyOrders, {
                    status: OrderStatus.REJECTED
                })
            }),
            /*#__PURE__*/ _jsx(TabPane, {
                title: "Order history",
                value: "history",
                className: "orderly-px-3",
                children: /*#__PURE__*/ _jsx(HistoryView, {})
            })
        ]
    });
};
export const MemoizedDataListView = /*#__PURE__*/ memo(DataListView);

//# sourceMappingURL=index.js.map