import { NextRequest, NextResponse } from 'next/server' import { getSearchSuggestions } from '@/lib/search' export async function GET(request: NextRequest) { try { const { searchParams } = new URL(request.url) const query = searchParams.get('q') const limit = parseInt(searchParams.get('limit') || '10') if (!query || query.trim().length === 0) { return NextResponse.json( { error: 'Search query is required' }, { status: 400 } ) } // Validate limit if (limit < 1 || limit > 50) { return NextResponse.json( { error: 'Limit must be between 1 and 50' }, { status: 400 } ) } const suggestions = await getSearchSuggestions(query.trim(), limit) return NextResponse.json( { query, suggestions, }, { status: 200 } ) } catch (error) { console.error('Search suggestions error:', error) return NextResponse.json( { error: 'Failed to get search suggestions' }, { status: 500 } ) } }