import { jsx as _jsx } from "react/jsx-runtime";
import { useCallback, useContext, useState } from "react";
import { useOrderStream, useAccount } from "@orderly.network/hooks";
import { TradingPageContext } from "../../../../../../page/trading/context/tradingPageContext";
import { AccountStatusEnum, AlgoOrderRootType } from "@orderly.network/types";
import { OrderStatus } from "@orderly.network/types";
import { OrdersViewFull } from "../../../../../../block/orders/full";
import { useTabContext } from "../../../../../../tab/tabContext";
import { useFormatOrderHistory } from "../../../../../../page/trading/shared/hooks/useFormatOrderHistory";
export const MyOrders = (props)=>{
    const context = useContext(TradingPageContext);
    const { data: tabExtraData } = useTabContext();
    // const [symbol, setSymbol] = useState(() =>
    //   tabExtraData.showAllSymbol ? "" : context.symbol
    // );
    const [side, setSide] = useState("");
    const [data, { isLoading, loadMore, cancelOrder, updateOrder, cancelAlgoOrder, updateAlgoOrder }] = useOrderStream({
        status: props.status,
        symbol: tabExtraData.showAllSymbol ? "" : context.symbol,
        // @ts-ignore
        side,
        excludes: props.status === OrderStatus.FILLED ? [] : [
            AlgoOrderRootType.POSITIONAL_TP_SL,
            AlgoOrderRootType.TP_SL
        ]
    });
    // const onShowAllSymbolChange = (isAll: boolean) => {
    //   setSymbol(isAll ? "" : context.symbol);
    //   setShowAllSymbol(isAll);
    // };
    const { state } = useAccount();
    const onCancelOrder = useCallback((orderId, symbol)=>{
        return cancelOrder(orderId, symbol);
    }, []);
    const formattedData = useFormatOrderHistory(state.status < AccountStatusEnum.EnableTrading || !data ? [] : data);
    return /*#__PURE__*/ _jsx(OrdersViewFull, {
        // @ts-ignore
        dataSource: formattedData,
        isLoading: isLoading,
        symbol: context.symbol,
        onSideChange: setSide,
        // @ts-ignore
        side: side,
        showAllSymbol: tabExtraData.showAllSymbol,
        cancelOrder: onCancelOrder,
        editOrder: updateOrder,
        cancelAlgoOrder: cancelAlgoOrder,
        editAlgoOrder: updateAlgoOrder,
        onSymbolChange: context.onSymbolChange,
        loadMore: loadMore,
        status: props.status
    });
};

//# sourceMappingURL=index.js.map