import React from 'react'; import clsx from 'clsx'; import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { SearchResult } from '@/api/hooks'; import { Badge } from '@/components/ui/Badge'; const TYPE_LABELS: Record = { company: 'search.companies', contact: 'search.contacts', mail: 'search.mails', file: 'search.files', event: 'search.events', message: 'search.messages', }; const TYPE_ICON_CLASSES: Record = { company: 'bg-primary-100 text-primary-700', contact: 'bg-accent-100 text-accent-700', mail: 'bg-success-100 text-success-700', file: 'bg-warning-100 text-warning-700', event: 'bg-secondary-100 text-secondary-700', message: 'bg-secondary-100 text-secondary-700', }; const TYPE_BADGE_VARIANTS: Record = { company: 'primary', contact: 'info', mail: 'success', file: 'warning', event: 'default', message: 'default', }; function typeIcon(type: string): string { switch (type) { case 'company': return 'F'; case 'contact': return 'K'; case 'mail': return '@'; case 'file': return '📄'; case 'event': return '📅'; case 'message': return '💬'; default: return '?'; } } interface SearchResultCardProps { result: SearchResult; query?: string; } function highlightMatch(text: string, query: string): React.ReactNode { if (!query.trim()) return text; const lowerText = text.toLowerCase(); const lowerQuery = query.toLowerCase(); const idx = lowerText.indexOf(lowerQuery); if (idx === -1) return text; return ( <> {text.slice(0, idx)} {text.slice(idx, idx + query.length)} {text.slice(idx + query.length)} ); } export function SearchResultCard({ result, query }: SearchResultCardProps) { const { t } = useTranslation(); const navigate = useNavigate(); const score = typeof result.score === 'number' ? result.score : 0; const scorePct = Math.round(score * 100); return ( ); }