import React, { useState, useEffect } from 'react'; import { useUserStore } from '@/store/userStore'; import apiService from '@/services/api'; import { History, Search, RefreshCcw, RotateCcw, ArrowRight } from 'lucide-react'; const HistoryTab: React.FC = () => { const { isDark } = useUserStore(); const [simulations, setSimulations] = useState([]); const [loading, setLoading] = useState(true); const [search, setSearch] = useState(''); const [page, setPage] = useState(1); const [total, setTotal] = useState(0); const cardBg = isDark ? 'rgba(255,255,255,0.03)' : '#ffffff'; const cardBorder = isDark ? 'rgba(255,255,255,0.06)' : 'rgba(0,0,0,0.06)'; const textPrimary = isDark ? '#f8fafc' : '#0f172a'; const textMuted = isDark ? '#94a3b8' : '#64748b'; const fetchHistory = async () => { setLoading(true); try { const res = await apiService.getSimulationHistory(page, 20, search); setSimulations(res.data?.simulations || []); setTotal(res.data?.total || 0); } catch (err) { console.error(err); } finally { setLoading(false); } }; useEffect(() => { fetchHistory(); }, [page, search]); return (
{/* Search & Header */}
setSearch(e.target.value)} className="w-full pl-9 pr-3 py-2 rounded-xl text-xs border outline-none focus:ring-2 focus:ring-indigo-500/30" style={{ background: cardBg, borderColor: cardBorder, color: textPrimary }} />
{/* History Table */}
{['Simulation Name', 'Model', 'Target Metric', 'Impact', 'Confidence', 'Status', 'Date', 'Action'].map((h) => ( ))} {simulations.map((sim: any, i: number) => ( ))}
{h}
{sim.name} {sim.model_name || 'AutoML'} {typeof sim.prediction === 'number' ? sim.prediction.toLocaleString(undefined, { maximumFractionDigits: 2 }) : 'N/A'} = 0 ? 'text-emerald-500' : 'text-red-500'}`}> {(sim.impact_percentage || 0) >= 0 ? '+' : ''}{(sim.impact_percentage || 0).toFixed(1)}% {(sim.confidence || 90).toFixed(1)}% {sim.status || 'Completed'} {sim.created_at ? new Date(sim.created_at).toLocaleDateString() : 'Just now'}
{simulations.length === 0 && !loading && (

No past simulation records found.

)}
); }; export default HistoryTab;