import React, { useState, useEffect } from 'react'; import { useLocation } from 'react-router-dom'; import { scanTextAsync, downloadForensicReport, type TextResult } from '../../services/textService'; import { useAuth } from '../../hooks/useAuth.tsx'; const ForensicGauge: React.FC<{ score: number; label: string; color: string; sublabel: string; size?: "sm" | "lg" | "xl"; }> = ({ score, label, color, sublabel, size = "lg" }) => { const radius = size === "xl" ? 90 : size === "lg" ? 75 : 35; const circumference = 2 * Math.PI * radius; const strokeDashoffset = circumference - (score / 100) * circumference; const viewSize = size === "xl" ? 220 : size === "lg" ? 200 : 100; return (
{Math.round(score)}% {(size === "lg" || size === "xl") && {sublabel}}
{label && (

{label}

)}
); }; import DashboardLayout from '../../components/layout/DashboardLayout'; const TextLabPage: React.FC = () => { const { token } = useAuth(); const location = useLocation(); const [text, setText] = useState(''); const [loading, setLoading] = useState(false); const [statusMsg, setStatusMsg] = useState(''); const [result, setResult] = useState(null); const [downloading, setDownloading] = useState(false); useEffect(() => { const params = new URLSearchParams(location.search); const scanId = params.get('scan_id'); if (scanId && token) { const fetchScan = async () => { setLoading(true); setStatusMsg("RECOVERING FORENSIC DATA..."); try { const res = await fetch(`http://127.0.0.1:8001/api/v1/dashboard/scan/${scanId}`, { headers: { Authorization: `Bearer ${token}` } }); if (res.ok) { const json = await res.json(); // Use full_result if available, otherwise fallback to data const scanData = json.data.full_result || json.data; setResult(scanData); if (scanData.text_preview) setText(scanData.text_preview); } } catch (err) { console.error("Failed to load historical scan:", err); } finally { setLoading(false); } }; fetchScan(); } }, [location.search, token]); const handleAnalyze = async () => { if (!text.trim()) return; setLoading(true); setResult(null); try { const res = await scanTextAsync(text, token, (msg) => setStatusMsg(msg)); setResult(res); } catch (err: any) { console.error("Forensic analysis failed:", err); alert(`Forensic Engine Error: ${err.message || "Unknown Failure"}`); } finally { setLoading(false); } }; const handleDownload = async () => { if (!result?.scan_id) return; setDownloading(true); try { await downloadForensicReport(result.scan_id, token); } catch (err) { alert("Error generating PDF. Please try again."); } finally { setDownloading(false); } }; return (

Text lab

Forensic linguistic audit engine

{result && ( )}
{/* TOP ROW: EVIDENCE & MASTER VERDICT */}
{/* EVIDENCE AREA (Col 1-8) */}
{!result ? ( <>
Input content CHARACTER COUNT: {text.length}