'use client'; import { Card } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import Link from 'next/link'; import { FileText, Clipboard, Image, Loader2 } from 'lucide-react'; import { SearchResult } from '@/types/search'; import { format } from 'date-fns'; interface SearchResultsProps { results: SearchResult[]; query: string; loading: boolean; } const TYPE_META: Record = { correspondence: { icon: FileText, label: 'Correspondence', color: 'text-blue-600' }, rfa: { icon: Clipboard, label: 'RFA', color: 'text-purple-600' }, drawing: { icon: Image, label: 'Drawing', color: 'text-green-600' }, }; const STATUS_VARIANT: Record = { DRAFT: 'bg-gray-100 text-gray-700', SUBOWN: 'bg-yellow-100 text-yellow-700', CLBOWN: 'bg-green-100 text-green-700', CCBOWN: 'bg-red-100 text-red-700', CANCELLED: 'bg-slate-100 text-slate-500 line-through', }; const STATUS_LABEL: Record = { DRAFT: 'Draft', SUBOWN: 'Submitted', CLBOWN: 'Approved', CCBOWN: 'Rejected', CANCELLED: 'Cancelled', }; function getLink(result: SearchResult): string { if (result.type === 'drawing') return `/drawings/${result.publicId}`; return `/${result.type}s/${result.publicId}`; } export function SearchResults({ results, query, loading }: SearchResultsProps) { if (loading) { return (
); } if (results.length === 0) { return ( {query ? `No results found for "${query}"` : 'Enter a search term to start'} ); } return (
{results.map((result, index) => { const meta = TYPE_META[result.type] ?? TYPE_META.correspondence; const Icon = meta.icon; const statusClass = STATUS_VARIANT[result.status] ?? 'bg-gray-100 text-gray-700'; const statusLabel = STATUS_LABEL[result.status] ?? result.status; return (
{result.documentNumber} {statusLabel} {meta.label}

{result.description && (

{result.description}

)}

{format(new Date(result.createdAt), 'dd MMM yyyy')}

); })}
); }