import React, { useState, useEffect } from 'react'; import { Activity, Map as MapIcon, Settings, ShieldAlert, CheckCircle2, XCircle, RefreshCw, Search, LayoutDashboard, ExternalLink, ChevronRight } from 'lucide-react'; const IntelligenceDashboard: React.FC = () => { const [stats, setStats] = useState(null); const [candidates, setCandidates] = useState([]); const [closures, setClosures] = useState([]); const [loading, setLoading] = useState(false); const [activeTab, setActiveTab] = useState<'summary' | 'candidates' | 'closures'>('summary'); const [message, setMessage] = useState(''); const API_BASE = (import.meta as any).env.VITE_API_URL || '/api'; const fetchData = async () => { setLoading(true); try { const [summaryRes, candRes, closeRes] = await Promise.all([ fetch(`${API_BASE}/map-refinement/summary`), fetch(`${API_BASE}/map-refinement/candidates?status=pending`), fetch(`${API_BASE}/map-refinement/closures`) ]); const summary = await summaryRes.json(); const cand = await candRes.json(); const close = await closeRes.json(); setStats(summary); setCandidates(cand || []); setClosures(close || []); } catch (error) { console.error("Dashboard fetch failed", error); } finally { setLoading(false); } }; useEffect(() => { fetchData(); const interval = setInterval(fetchData, 30000); return () => clearInterval(interval); }, []); const runAnalysis = async () => { setMessage('Brain starting deep analysis... 🧠'); try { await fetch(`${API_BASE}/telemetry/process-intelligence?days=2`, { method: 'POST' }); setMessage('Analysis initiated successfully. Check Telegram for report.'); } catch (error) { setMessage('Analysis failed to start.'); } setTimeout(() => setMessage(''), 5000); }; const handleCandidate = async (id: string, action: 'approve' | 'reject') => { try { await fetch(`${API_BASE}/map-refinement/candidates/${id}/${action}`, { method: 'PATCH' }); setMessage(`Road ${action}d successfully. 🛣️`); fetchData(); } catch (error) { setMessage(`Failed to ${action} road.`); } setTimeout(() => setMessage(''), 3000); }; return (
{/* Header */}

Map AI Intelligence

Intaleq SaaS Monitoring & Enrichment Platform

{/* Stats Quick View */}
{[ { label: 'Telemetry Points', value: stats?.telemetry?.total || 0, icon: , color: '#818cf8' }, { label: 'Analyzed Segments', value: stats?.roads?.analyzed || 0, icon: , color: '#60a5fa' }, { label: 'Road Candidates', value: candidates.length, icon: , color: '#fbbf24' }, { label: 'Active Closures', value: closures.length, icon: , color: '#f87171' }, ].map((stat, i) => (
{stat.icon}
{stat.label} {stat.value.toLocaleString()}
))}
{/* Main Content Area */}
{/* Navigation Tabs */}
{activeTab === 'candidates' && (

Detected Road Candidates / طرق مرشحة

{candidates.length === 0 ? (

No pending road candidates found. Everything is synced. ✅

) : (
{candidates.map((c) => (
0.8 ? '#22c55e' : '#eab308', borderRadius: '4px' }} />
New Segment {c.id.slice(-4)} {Math.round(c.lengthMeters)}m
{c.uniqueDriverCount} drivers • {c.totalPoints} points • Confidence: {Math.round(c.confidence * 100)}%
))}
)}
)} {activeTab === 'summary' && stats && (

Intelligence Quality Report

{/* Quality Metrics */} {[ { label: 'Data Density', value: 'High Accuracy', desc: 'Clusters are well-defined in Damascus & Amman', color: '#22c55e' }, { label: 'Map Freshness', value: 'Last 24h', desc: 'Telemetry analysis window is fully processed', color: '#6366f1' }, { label: 'Overpass Sync', value: 'Available', desc: 'Overture enrichment ready to pull labels', color: '#3b82f6' } ].map((item, i) => (
{item.label}
{item.desc}
{item.value}
))}

Action Log

{stats.history?.map((entry: any, i: number) => (
{entry}
)) || [
System initialized. Waiting for analysis...
]}
)} {activeTab === 'closures' && (

No active road closures detected in current telemetry. 🚧

)}
{/* Persistence Message */} {message && (
{message}
)}