import { View, Text, ScrollView, TouchableOpacity, FlatList, ActivityIndicator } from 'react-native' import { useRouter } from 'expo-router' import { BottomNavBar } from '../src/components/BottomNavBar' import { usePlayerStore } from '../src/store/playerStore' import { useState, useEffect } from 'react' export default function SearchScreen() { const router = useRouter() const currentSong = usePlayerStore(s => s.currentSong) const isPlaying = usePlayerStore(s => s.isPlaying) const togglePlay = usePlayerStore(s => s.togglePlay) const [query, setQuery] = useState('') const [results, setResults] = useState([]) const [loading, setLoading] = useState(false) const features = [ { id: 'music', name: 'Music', icon: '🎵', route: '/library' }, { id: 'new', name: 'New Music', icon: '✨', route: '/releases' }, { id: 'events', name: 'Live Events', icon: '🎪', route: '/' }, { id: 'radio', name: 'Internet Radio', icon: '📻', route: '/radio' }, { id: 'mood', name: 'Mood Radio', icon: '😊', route: '/mood' }, { id: 'lofi', name: 'LoFi', icon: '🌙', route: '/lofi' }, { id: 'shareplay', name: 'SharePlay', icon: '📢', route: '/shareplay' }, ] const handleSearch = async (text: string) => { setQuery(text) if (!text) { setResults([]) return } setLoading(true) try { const res = await fetch(`/api/search?q=${encodeURIComponent(text)}`) const data = await res.json() setResults(data.items || []) } catch { setResults([]) } finally { setLoading(false) } } return ( router.push('/account' as any)} className="w-10 h-10 rounded-full bg-music-card items-center justify-center"> 👤 Search 🔍 handleSearch(query)} className="text-sm text-music-text ml-2 flex-1" numberOfLines={1} > {query || 'What music is calling to you?'} {loading && ( )} {!loading && results.length > 0 && ( Search Results {results.map((item: any, i: number) => ( 🎵 {item.title || item.name} {item.artist || 'Unknown'} ))} )} {(!query || results.length === 0) && ( <> Browse {features.map((f) => ( router.push(f.route as any)} className="flex-1 min-w-[30%] p-4 rounded-xl bg-music-card items-center"> {f.icon} {f.name} ))} )} {currentSong && ( {currentSong.title} {currentSong.artist} {isPlaying ? '⏸' : '▶️'} )} ) }