'use client'; import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { apiFetch } from '../../../../lib/api'; import { useSession } from '../../../../components/session-provider'; interface CompanyResult { cui?: string; companyId?: string; name?: string; companyName?: string; industry?: string; county?: string; city?: string; country?: string; employees?: number; revenue?: number; registrationDate?: string; isActive?: boolean; caenCode?: string; caenLabel?: string; } export default function CompaniesIntelligencePage() { const { activeTenant } = useSession(); const tenantId = activeTenant?.tenantId ?? ''; const [q, setQ] = useState(''); const [submitted, setSubmitted] = useState(''); const { data, isLoading, error } = useQuery({ queryKey: ['intel-companies', tenantId, submitted], queryFn: () => apiFetch<{ results?: CompanyResult[]; total?: number } | CompanyResult[]>( `/v1/intelligence/companies/search?q=${encodeURIComponent(submitted)}&limit=20`, { tenantId } ), enabled: Boolean(tenantId) && submitted.length >= 2, staleTime: 300_000, }); const results: CompanyResult[] = Array.isArray(data) ? data : (data as any)?.results ?? []; return (

Baza de date Companii

Caută companii din registrul de business — nume, CUI, domeniu de activitate.

{/* Search box */}
{ e.preventDefault(); if (q.trim().length >= 2) setSubmitted(q.trim()); }} className="flex gap-2"> setQ(e.target.value)} className="flex-1 rounded-lg border bg-card px-4 py-2.5 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" />
{/* Results */} {isLoading && (
Se caută…
)} {error && (

Eroare la căutare. Verifică conexiunea la baza de date.

)} {!isLoading && submitted && results.length === 0 && !error && (

🔍

Niciun rezultat pentru "{submitted}"

)} {results.length > 0 && (

{results.length} rezultate pentru "{submitted}"

{results.map((company, i) => { const name = company.name ?? company.companyName ?? '—'; const id = company.cui ?? company.companyId ?? String(i); return (

{name}

{(company.cui || company.companyId) && (

CUI: {company.cui ?? company.companyId}

)}
{company.isActive !== undefined && ( {company.isActive ? 'Activ' : 'Inactiv'} )}
{company.industry && ( 🏭 {company.industry} )} {(company.caenCode || company.caenLabel) && ( 📋 {company.caenCode}{company.caenLabel ? ` — ${company.caenLabel}` : ''} )} {(company.city || company.county) && ( 📍 {[company.city, company.county].filter(Boolean).join(', ')} )} {company.employees && ( 👥 {company.employees.toLocaleString('ro-RO')} angajați )} {company.registrationDate && ( 📅 {company.registrationDate.slice(0, 10)} )}
); })}
)} {!submitted && (

Cum funcționează

{[ '🔍 Caută după denumire completă sau parțială', '🔢 Caută după CUI (cod unic de identificare)', '📊 Rezultatele includ date ONRC: CAEN, angajați, locație', '⚡ Rezultatele sunt live din baza de date de intelligence', ].map((s) =>

{s}

)}
)}
); }