'use client' import { SearchBar } from '@/components/SearchBar' import { SongCard } from '@/components/SongCard' import { AlbumCard } from '@/components/AlbumCard' import { ArtistCard } from '@/components/ArtistCard' import { SectionHeader } from '@/components/SectionHeader' import { useState, useEffect, Suspense } from 'react' import { useSearchParams } from 'next/navigation' function SearchContent() { const searchParams = useSearchParams() const [results, setResults] = useState(null) const [loading, setLoading] = useState(false) const [searchedQuery, setSearchedQuery] = useState('') useEffect(() => { const q = searchParams.get('q') if (q) { performSearch(q) } }, [searchParams]) const performSearch = async (searchQuery: string) => { if (!searchQuery.trim()) { setResults(null) return } setSearchedQuery(searchQuery) setLoading(true) try { const res = await fetch(`/api/search?q=${encodeURIComponent(searchQuery)}`) if (res.ok) { const data = await res.json() setResults(data) } } catch (error) { console.error('Search failed:', error) } finally { setLoading(false) } } const handleSearch = (query: string) => { if (query.trim()) { const url = new URL(window.location.href) url.searchParams.set('q', query) window.history.pushState({}, '', url) performSearch(query) } else { setResults(null) setSearchedQuery('') } } const hasResults = results && ( (results.songs && results.songs.length > 0) || (results.albums && results.albums.length > 0) || (results.artists && results.artists.length > 0) ) return (
{/* Header */}

Search

Find songs, artists, albums, and playlists

{/* Results */} {loading ? (

Searching...

) : hasResults ? (
{/* Songs Section */} {results.songs && results.songs.length > 0 && (
{results.songs.map((song: any) => ( ))}
)} {/* Artists Section */} {results.artists && results.artists.length > 0 && (
{results.artists.map((artist: any) => ( ))}
)} {/* Albums Section */} {results.albums && results.albums.length > 0 && (
{results.albums.map((album: any) => ( ))}
)}
) : searchedQuery ? (

No results found for "{searchedQuery}"

Try different keywords or browse by genre

) : (

Start typing to search

Find your favorite music

)} {/* Popular Searches */} {!searchedQuery && (

Popular Searches

{['Hip Hop', 'Rock', 'Electronic', 'Jazz', 'Pop', 'Classical'].map((genre) => ( ))}
)}
) } export default function SearchPage() { return (

Loading search...

}> ) }