import React from 'react'; import { View, Text, ScrollView, TouchableOpacity, ActivityIndicator, FlatList, } from 'react-native'; import { useTranslation } from 'react-i18next'; import { MaterialIcons } from '@expo/vector-icons'; import { StreamingContent } from '../../services/catalogService'; import { DiscoverCatalog, isTablet, isLargeTablet, isTV } from './searchUtils'; import { DiscoverResultItem } from './DiscoverResultItem'; import { searchStyles as styles } from './searchStyles'; import { BottomSheetModal } from '@gorhom/bottom-sheet'; interface DiscoverSectionProps { discoverLoading: boolean; discoverInitialized: boolean; discoverResults: StreamingContent[]; pendingDiscoverResults: StreamingContent[]; loadingMore: boolean; selectedCatalog: DiscoverCatalog | null; selectedDiscoverType: string; selectedDiscoverGenre: string | null; availableGenres: string[]; typeSheetRef: React.RefObject; catalogSheetRef: React.RefObject; genreSheetRef: React.RefObject; handleShowMore: () => void; navigation: any; setSelectedItem: (item: StreamingContent) => void; setMenuVisible: (visible: boolean) => void; currentTheme: any; } export const DiscoverSection = ({ discoverLoading, discoverInitialized, discoverResults, pendingDiscoverResults, loadingMore, selectedCatalog, selectedDiscoverType, selectedDiscoverGenre, availableGenres, typeSheetRef, catalogSheetRef, genreSheetRef, handleShowMore, navigation, setSelectedItem, setMenuVisible, currentTheme, }: DiscoverSectionProps) => { const { t } = useTranslation(); return ( {/* Section Header */} {t('search.discover')} {/* Filter Chips Row */} {/* Type Selector Chip (Movie/TV Show) */} typeSheetRef.current?.present()} > {selectedDiscoverType === 'movie' ? t('search.movies') : selectedDiscoverType === 'series' ? t('search.tv_shows') : selectedDiscoverType === 'anime.movie' ? t('search.anime_movies') : selectedDiscoverType === 'anime.series' ? t('search.anime_series') : selectedDiscoverType.replace(/[._]/g, ' ').replace(/\b\w/g, c => c.toUpperCase())} {/* Catalog Selector Chip */} catalogSheetRef.current?.present()} > {selectedCatalog ? selectedCatalog.catalogName : t('search.select_catalog')} {/* Genre Selector Chip - only show if catalog has genres */} {availableGenres.length > 0 && ( genreSheetRef.current?.present()} > {selectedDiscoverGenre || t('search.all_genres')} )} {/* Selected filters summary */} {selectedCatalog && ( {selectedCatalog.addonName} • { selectedCatalog.type === 'movie' ? t('search.movies') : selectedCatalog.type === 'series' ? t('search.tv_shows') : selectedCatalog.type === 'anime.movie' ? t('search.anime_movies') : selectedCatalog.type === 'anime.series' ? t('search.anime_series') : selectedCatalog.type.replace(/[._]/g, ' ').replace(/\b\w/g, c => c.toUpperCase()) }{selectedDiscoverGenre ? ` • ${selectedDiscoverGenre}` : ''} )} {/* Discover Results */} {discoverLoading ? ( {t('search.discovering')} ) : discoverResults.length > 0 ? ( `discover-${item.id}-${index}`} numColumns={isTV ? 6 : isLargeTablet ? 5 : isTablet ? 4 : 3} key={isTV ? 'tv-6' : isLargeTablet ? 'ltab-5' : isTablet ? 'tab-4' : 'phone-3'} columnWrapperStyle={styles.discoverGridRow} contentContainerStyle={styles.discoverGridContent} renderItem={({ item, index }) => ( )} initialNumToRender={9} maxToRenderPerBatch={6} windowSize={5} removeClippedSubviews={true} scrollEnabled={false} ListFooterComponent={ pendingDiscoverResults.length > 0 ? ( {t('search.show_more', { count: pendingDiscoverResults.length })} ) : loadingMore ? ( ) : null } /> ) : discoverInitialized && !discoverLoading && selectedCatalog ? ( {t('search.no_content_found')} {t('search.try_different')} ) : !selectedCatalog && discoverInitialized ? ( {t('search.select_catalog_desc')} {t('search.tap_catalog_desc')} ) : null} ); }; DiscoverSection.displayName = 'DiscoverSection';