import { jsx as _jsx } from "react/jsx-runtime";
import { HistoryListViewFull } from "../../../../../../block/orderHistory";
import { TradingPageContext } from "../../../../../../page/trading/context/tradingPageContext";
import { useTabContext } from "../../../../../../tab/tabContext";
import { useOrderStream, useAccount } from "@orderly.network/hooks";
import { AccountStatusEnum } from "@orderly.network/types";
import { useCallback, useContext, useState } from "react";
import { useFormatOrderHistory } from "../../../../../../page/trading/shared/hooks/useFormatOrderHistory";
export const HistoryView = ()=>{
    const [side, setSide] = useState("");
    const [status, setStauts] = useState("");
    const { state } = useAccount();
    const { symbol, onSymbolChange } = useContext(TradingPageContext);
    const { data: tabExtraData } = useTabContext();
    const [data, { isLoading, loadMore, cancelOrder, refresh, cancelAlgoOrder }] = useOrderStream({
        // @ts-ignore
        side,
        // @ts-ignore
        status,
        symbol: tabExtraData.showAllSymbol ? "" : symbol,
        size: 40
    });
    const onCancelOrder = useCallback((orderId, symbol)=>{
        ;
        // @ts-ignore
        return cancelOrder(orderId, symbol);
    // .then(() => {
    //   // update history list
    //   return refresh();
    // });
    }, [
        refresh
    ]);
    const formattedData = useFormatOrderHistory(state.status < AccountStatusEnum.EnableTrading || !data ? [] : data);
    // console.log("formattedData", formattedData);
    return /*#__PURE__*/ _jsx(HistoryListViewFull, {
        isLoading: isLoading,
        // @ts-ignore
        dataSource: formattedData,
        onSideChange: setSide,
        onStatusChange: setStauts,
        onSymbolChange: onSymbolChange,
        onCancelOrder: onCancelOrder,
        onCancelAlgoOrder: cancelAlgoOrder,
        // cancelTPSLOrder={cancelTPSLOrder}
        side: side,
        status: status,
        loadMore: loadMore
    });
};

//# sourceMappingURL=index.js.map