import { useState, useEffect } from 'react' import axios from 'axios' import { Building, Search, Upload, Globe, MapPin, Play, Search as SearchIcon, Loader2, LayoutGrid, List, ChevronLeft, ChevronRight, ArrowDownUp, Flag } from 'lucide-react' import clsx from 'clsx' interface Company { id: number name: string city: string | null country: string website: string | null status: string industry_ai: string | null created_at: string updated_at: string has_pending_mistakes: boolean } interface CompanyTableProps { apiBase: string onRowClick: (companyId: number) => void refreshKey: number onImportClick: () => void } export function CompanyTable({ apiBase, onRowClick, refreshKey, onImportClick }: CompanyTableProps) { const [data, setData] = useState([]) const [total, setTotal] = useState(0) const [page, setPage] = useState(0) const [search, setSearch] = useState("") const [sortBy, setSortBy] = useState('name_asc') const [loading, setLoading] = useState(false) const [processingId, setProcessingId] = useState(null) const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid') const limit = 50 const fetchData = async () => { setLoading(true) try { const res = await axios.get(`${apiBase}/companies?skip=${page * limit}&limit=${limit}&search=${search}&sort_by=${sortBy}`) setData(res.data.items) setTotal(res.data.total) } catch (e) { console.error("Failed to fetch companies", e) } finally { setLoading(false) } } useEffect(() => { const timer = setTimeout(fetchData, 300) return () => clearTimeout(timer) }, [page, search, refreshKey, sortBy]) const triggerDiscovery = async (id: number) => { setProcessingId(id); try { await axios.post(`${apiBase}/enrich/discover`, { company_id: id }); setTimeout(fetchData, 2000); } catch (e) { alert("Discovery Error"); } finally { setProcessingId(null); } } const triggerAnalysis = async (id: number) => { setProcessingId(id); try { await axios.post(`${apiBase}/enrich/analyze`, { company_id: id }); setTimeout(fetchData, 2000); } catch (e) { alert("Analysis Error"); } finally { setProcessingId(null); } } return (
{/* Toolbar */}

Companies ({total})

{ setSearch(e.target.value); setPage(0); }}/>
{/* Content Area */}
{loading &&
Loading companies...
} {data.length === 0 && !loading ? (

No companies found

Import a list or create one manually to get started.

) : viewMode === 'grid' ? (
{data.map((c) => (
onRowClick(c.id)} className="bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-lg p-4 hover:shadow-lg transition-all flex flex-col gap-3 group cursor-pointer border-l-4" style={{ borderLeftColor: c.status === 'ENRICHED' ? '#22c55e' : c.status === 'DISCOVERED' ? '#3b82f6' : '#94a3b8' }}>
{c.name}
{c.city && c.country ? (<> {c.city} ({c.country})) : (-)}
{processingId === c.id ? : c.status === 'NEW' || !c.website || c.website === 'k.A.' ? ( ) : ( )}
{c.website && c.website !== "k.A." ? (
{new URL(c.website).hostname.replace('www.', '')}
) : (
No website found
)}
{c.industry_ai || "Industry Pending"}
))}
) : ( {data.map((c) => ( onRowClick(c.id)} className="hover:bg-slate-50 dark:hover:bg-slate-800/50 cursor-pointer"> ))}
Company Location Website AI Industry Actions
{c.name}
{c.city && c.country ? `${c.city}, (${c.country})` : '-'} {c.website && c.website !== "k.A." ? {new URL(c.website).hostname.replace('www.', '')} : 'n/a'} {c.industry_ai || 'Pending'} {processingId === c.id ? : c.status === 'NEW' || !c.website || c.website === 'k.A.' ? ( ) : ( )}
)}
{/* Pagination */}
{total} Companies total
Page {page + 1}
) }