"use client"; import { useState } from "react"; import { useSearchParams } from "next/navigation"; import { SearchFilters } from "@/components/search/filters"; import { SearchResults } from "@/components/search/results"; import { SearchFilters as FilterType } from "@/types/search"; import { useSearch } from "@/hooks/use-search"; export default function SearchPage() { const searchParams = useSearchParams(); // URL Params state const query = searchParams.get("q") || ""; const typeParam = searchParams.get("type"); const statusParam = searchParams.get("status"); // Local Filter State (synced with URL initially, but can be independent before apply) // For simplicity, we'll keep filters in sync with valid search params or local state that pushes to URL const [filters, setFilters] = useState({ types: typeParam ? [typeParam] : [], statuses: statusParam ? [statusParam] : [], }); // Construct search DTO const searchDto = { q: query, // Map internal types to backend expectation if needed, assumes direct mapping for now type: filters.types?.length === 1 ? filters.types[0] : undefined, // Backend might support single type or multiple? // DTO says 'type?: string', 'status?: string'. If multiple, our backend might need adjustment or we only support single filter for now? // Spec says "Advanced filters work (type, status)". Let's assume generic loose mapping for now or comma separated. // Let's assume the hook and backend handle it. If backend expects single value, we pick first or join. // Backend controller uses `SearchQueryDto`. Let's check DTO if I can view it. // Actually, I'll pass them and let the service handle serialization if needed. ...filters }; const { data: results, isLoading, isError } = useSearch(searchDto); const handleFilterChange = (newFilters: FilterType) => { setFilters(newFilters); // Optional: Update URL to reflect filters? }; return (

Search Results

{isLoading ? "Searching..." : `Found ${results?.length || 0} results for "${query}"` }

{isError ? (
Failed to load search results.
) : ( )}
); }