import React, { useState, useMemo } from 'react' import { useChannels } from '../contexts/ChannelContext' import { useKeyboard } from '../hooks/useKeyboard' import { Search, Heart, Tv, RefreshCw } from 'lucide-react' import { Channel } from '../types/channel' interface ChannelListProps { onChannelSelect?: () => void } export default function ChannelList({ onChannelSelect }: ChannelListProps) { const { channels, categories, currentChannel, favorites, searchTerm, selectedCategory, setCurrentChannel, setSearchTerm, setSelectedCategory, toggleFavorite, refreshChannels, isLoading } = useChannels() const [selectedIndex, setSelectedIndex] = useState(0) const filteredChannels = useMemo(() => { let filtered = channels // Filtrar por categoría if (selectedCategory === 'favorites') { filtered = filtered.filter(channel => favorites.includes(channel.id)) } else if (selectedCategory !== 'all') { filtered = filtered.filter(channel => channel.category === selectedCategory) } // Filtrar por búsqueda if (searchTerm) { filtered = filtered.filter(channel => channel.name.toLowerCase().includes(searchTerm.toLowerCase()) ) } return filtered }, [channels, selectedCategory, favorites, searchTerm]) useKeyboard({ onArrowUp: () => setSelectedIndex(prev => Math.max(0, prev - 1)), onArrowDown: () => setSelectedIndex(prev => Math.min(filteredChannels.length - 1, prev + 1)), onEnter: () => { if (filteredChannels[selectedIndex]) { handleChannelSelect(filteredChannels[selectedIndex]) } } }) const handleChannelSelect = (channel: Channel) => { setCurrentChannel(channel) onChannelSelect?.() } const handleCategoryChange = (category: string) => { setSelectedCategory(category) setSelectedIndex(0) } return (
No se encontraron canales
{channel.name}
{channel.category}