import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useMemo } from "react";
import { ListViewFull } from "./listview";
import { MarketsType, useMarkets } from "@orderly.network/hooks";
import { useDataSource } from "../useDataSource";
import { FavoriteButton } from "./favoriteButton";
export const RecentTabPane = (props)=>{
    const { activeIndex, setActiveIndex, onItemClick, fitlerKey } = props;
    const [data, { recent, addToHistory, favoriteTabs, updateFavoriteTabs, updateSymbolFavoriteState }] = useMarkets(MarketsType.RECENT);
    const filterData = useMemo(()=>{
        return recent?.map((item)=>{
            const index = data.findIndex((symbol)=>item.name === symbol.symbol);
            if (index === -1) {
                return null;
            }
            return data[index];
        }).map((item)=>item);
    }, [
        data,
        recent
    ]);
    const [dataSource, { onSearch, onSort }] = useDataSource(// @ts-ignore
    filterData);
    useEffect(()=>{
        onSearch(fitlerKey);
    }, [
        fitlerKey
    ]);
    return /*#__PURE__*/ _jsx(ListViewFull, {
        // @ts-ignore
        // ref={listviewRef}
        activeIndex: activeIndex,
        dataSource: dataSource,
        onSort: onSort,
        readLastSortCondition: false,
        maxHeight: props.maxHeight,
        updateActiveIndex: (index)=>setActiveIndex(index),
        onItemClick: (item)=>{
            // @ts-ignore
            onItemClick?.(item);
            addToHistory(item);
        },
        favoriteTabs: favoriteTabs,
        prefixRender: (item, index)=>{
            return /*#__PURE__*/ _jsx(FavoriteButton, {
                symbol: item,
                tabs: favoriteTabs,
                updateFavoriteTabs: updateFavoriteTabs,
                updateSymbolFavoriteState: updateSymbolFavoriteState
            });
        }
    });
};

//# sourceMappingURL=recentTabPane.js.map