"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "RecentTabPane", {
    enumerable: true,
    get: function() {
        return RecentTabPane;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _listview = require("./listview");
const _hooks = require("@orderly.network/hooks");
const _useDataSource = require("../useDataSource");
const _favoriteButton = require("./favoriteButton");
const RecentTabPane = (props)=>{
    const { activeIndex, setActiveIndex, onItemClick, fitlerKey } = props;
    const [data, { recent, addToHistory, favoriteTabs, updateFavoriteTabs, updateSymbolFavoriteState }] = (0, _hooks.useMarkets)(_hooks.MarketsType.RECENT);
    const filterData = (0, _react.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 }] = (0, _useDataSource.useDataSource)(// @ts-ignore
    filterData);
    (0, _react.useEffect)(()=>{
        onSearch(fitlerKey);
    }, [
        fitlerKey
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_listview.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__*/ (0, _jsxruntime.jsx)(_favoriteButton.FavoriteButton, {
                symbol: item,
                tabs: favoriteTabs,
                updateFavoriteTabs: updateFavoriteTabs,
                updateSymbolFavoriteState: updateSymbolFavoriteState
            });
        }
    });
};

//# sourceMappingURL=recentTabPane.js.map