"use client"; import { useState } from "react"; import { Skeleton } from "@/components/ui/skeleton"; import { cn } from "@/lib/utils"; import { CheckCircle2, XCircle, AlertCircle, ChevronUp, ChevronDown } from "lucide-react"; export interface ResultRow { id: string; companyName?: string; domain?: string; contactName?: string; contactTitle?: string; email?: string; confidence?: number; linkedinUrl?: string; status?: string; selected?: boolean; } interface ResultsTableProps { rows: ResultRow[]; loading?: boolean; selectable?: boolean; onSelectionChange?: (ids: string[]) => void; extraColumns?: Array<{ key: string; label: string }>; } function EmailStatusIcon({ email, confidence }: { email?: string; confidence?: number }) { if (!email) return ; if (confidence && confidence < 0.7) return ; return ; } export function ResultsTable({ rows, loading, selectable, onSelectionChange, extraColumns }: ResultsTableProps) { const [selected, setSelected] = useState>(new Set()); const [sort, setSort] = useState<{ key: string; dir: "asc" | "desc" } | null>(null); const toggleSelect = (id: string) => { const next = new Set(selected); next.has(id) ? next.delete(id) : next.add(id); setSelected(next); onSelectionChange?.(Array.from(next)); }; const toggleAll = () => { if (selected.size === rows.length) { setSelected(new Set()); onSelectionChange?.([]); } else { const all = new Set(rows.map(r => r.id)); setSelected(all); onSelectionChange?.(Array.from(all)); } }; if (loading) { return (
{Array.from({ length: 5 }).map((_, i) => ( ))}
); } if (rows.length === 0) return null; return (
{selectable && ( )} {extraColumns?.map(col => ( ))} {rows.map((row, idx) => ( selectable && toggleSelect(row.id)} > {selectable && ( )} {extraColumns?.map(col => ( ))} ))}
0} onChange={toggleAll} className="rounded border-[#2e2e3e] bg-[#1e1e2e]" /> Company Domain Contact Title Email Confidence{col.label}
e.stopPropagation()}> toggleSelect(row.id)} className="rounded border-[#2e2e3e] bg-[#1e1e2e]" /> {row.companyName || "—"} {row.domain || "—"} {row.contactName || "—"} {row.contactTitle || "—"}
{row.email || "—"}
{row.confidence !== undefined ? ( = 0.8 ? "text-green-400" : row.confidence >= 0.6 ? "text-yellow-400" : "text-red-400")}> {Math.round(row.confidence * 100)}% ) : "—"} {((row as unknown) as Record)[col.key] || "—"}
); }