import React, { useState, useEffect } from 'react'; import { Database, Search, RefreshCw, ExternalLink, BookOpen, Scale, ShieldCheck, Building2, Home, Activity, Clock, CheckCircle2, Sparkles, FileText, AlertCircle, Layers, Zap, Globe, Share2, Check, Cpu, Hash, Fingerprint } from 'lucide-react'; import { INITIAL_CASE_HISTORIES, INITIAL_SCIENCE_PUBLICATIONS, INITIAL_ADR_ADX_UPDATES, searchPubMedArticles, searchEuropePMC, executePeriodicScienceAndAdrSync } from '../services/openLegalScienceService'; import { CaseHistoryRecord, PeerReviewScienceItem, AdrAdxLedgerUpdate } from '../types/document'; import { PacerBackgroundWorkerBanner } from './PacerBackgroundWorkerBanner'; export const CaseScienceDataHub: React.FC = () => { const [activeSubTab, setActiveSubTab] = useState<'cases' | 'science' | 'adxLedger' | 'ssdiHousing'>('cases'); const [caseFilter, setCaseFilter] = useState<'All' | 'Maryland State' | 'Federal Appellate' | 'Federal Bankruptcy'>('All'); const [searchQuery, setSearchQuery] = useState(''); // Data states const [caseHistories, setCaseHistories] = useState(INITIAL_CASE_HISTORIES); const [sciencePublications, setSciencePublications] = useState(INITIAL_SCIENCE_PUBLICATIONS); const [adxLedger, setAdxLedger] = useState(INITIAL_ADR_ADX_UPDATES); // Periodic Science Checker state const [isAutoCheckActive, setIsAutoCheckActive] = useState(true); const [isSyncing, setIsSyncing] = useState(false); const [lastSyncTime, setLastSyncTime] = useState(new Date().toLocaleTimeString()); const [syncCount, setSyncCount] = useState(3); const [customScienceQuery, setCustomScienceQuery] = useState(''); const [isSearchingScience, setIsSearchingScience] = useState(false); const sciencePublicationsRef = React.useRef(sciencePublications); sciencePublicationsRef.current = sciencePublications; const adxLedgerRef = React.useRef(adxLedger); adxLedgerRef.current = adxLedger; const handleSyncScienceAndAdx = React.useCallback(async (silent = false) => { setIsSyncing(true); try { const result = await executePeriodicScienceAndAdrSync(sciencePublicationsRef.current, adxLedgerRef.current); if (result.newPublications.length > 0) { setSciencePublications(prev => [...result.newPublications, ...prev]); } setAdxLedger(prev => [result.newUpdate, ...prev]); setLastSyncTime(new Date().toLocaleTimeString()); setSyncCount(prev => prev + 1); } catch (err) { console.warn('Periodic sync notice:', err); } finally { setIsSyncing(false); } }, []); const syncScienceRef = React.useRef(handleSyncScienceAndAdx); syncScienceRef.current = handleSyncScienceAndAdx; // Periodic science check timer (every 45 seconds when enabled) useEffect(() => { if (!isAutoCheckActive) return; const interval = setInterval(() => { if (syncScienceRef.current) { syncScienceRef.current(true); } }, 45000); return () => clearInterval(interval); }, [isAutoCheckActive]); const handleManualScienceSearch = async () => { if (!customScienceQuery.trim()) return; setIsSearchingScience(true); try { const pubmedResults = await searchPubMedArticles(customScienceQuery, 3); const epmcResults = await searchEuropePMC(customScienceQuery, 3); const merged = [...pubmedResults, ...epmcResults]; if (merged.length > 0) { setSciencePublications(prev => { const existingIds = new Set(prev.map(p => p.identifier)); const novel = merged.filter(m => !existingIds.has(m.identifier)); return [...novel, ...prev]; }); } } catch (e) { console.warn('Search error:', e); } finally { setIsSearchingScience(false); } }; const handleSelectDocket = React.useCallback((docketNumber: string) => { setSearchQuery(docketNumber); setCaseFilter('All'); }, []); const handleDocketsUpdated = React.useCallback((updated: CaseHistoryRecord[]) => { setCaseHistories(updated); }, []); const filteredCases = caseHistories.filter(c => { const matchesFilter = caseFilter === 'All' || c.jurisdiction === caseFilter; const matchesSearch = c.caseName.toLowerCase().includes(searchQuery.toLowerCase()) || c.docketNumber.toLowerCase().includes(searchQuery.toLowerCase()) || c.summary.toLowerCase().includes(searchQuery.toLowerCase()) || c.court.toLowerCase().includes(searchQuery.toLowerCase()); return matchesFilter && matchesSearch; }); return (
{/* Top Banner */}
OPEN CASE & SCIENCE INTELLIGENCE ZERO API KEY REQUIRED 30 ROW HOMES SSDI/SSI ALLOCATION

PACER / State Case Info & NIH PubMed / arXiv Periodic Science Monitor

Real-time ingestion of federal dockets via Free Law Project CourtListener RECAP, Maryland Judiciary Case Search (MDEC), NIH PubMed, and Europe PMC. Periodically checks for new peer-reviewed scientific literature and synchronizes verified blocks into the ADR/ADX Digital Reserve Ledger.

{/* Periodic Monitor Indicator & Control */}
{isAutoCheckActive ? 'Periodic Monitor: ACTIVE' : 'Periodic Monitor: PAUSED'}
Last Synced: {lastSyncTime} ({syncCount} audits)
{/* Navigation Sub-Tabs */}
{/* Search bar */}
setSearchQuery(e.target.value)} placeholder="Search dockets, case numbers..." className="w-full pl-8 pr-3 py-1.5 text-xs bg-slate-950 border border-slate-700 rounded-lg text-slate-200 placeholder-slate-500 focus:outline-none focus:border-indigo-500" />
{/* ========================================================================= */} {/* SUB-TAB 1: PACER & MARYLAND STATE COURT DOCKETS */} {/* ========================================================================= */} {activeSubTab === 'cases' && (
{/* PACER Background Worker Controls & Status Alerts */} {/* Filter badges */}
{(['All', 'Maryland State', 'Federal Appellate', 'Federal Bankruptcy'] as const).map(tab => ( ))}
{filteredCases.map(c => (
{c.docketNumber} {c.jurisdiction} {c.sourceDatabase}

{c.caseName}

Court: {c.court} | Filed: {c.filingDate} | Audited: {c.lastUpdated}
View Public Docket
Jurisprudential Relevance: {c.relevance}

{c.summary}

{/* Key Docket Orders & Filings */}
Key Docket Orders & Verified Filings:
{c.keyOrders.map((ord, i) => (
{ord.description}
{ord.documentNumber && [{ord.documentNumber}]} {ord.date}
))}
))}
)} {/* ========================================================================= */} {/* SUB-TAB 2: PEER-REVIEWED SCIENCE (PUBMED / PMC / ARXIV) */} {/* ========================================================================= */} {activeSubTab === 'science' && (
{/* Query Bar */}
setCustomScienceQuery(e.target.value)} placeholder="Query PubMed / Europe PMC (e.g. dopamine D4 receptor SAR, MORTAR queueing, NIST FIPS 203)..." className="w-full px-3 py-2 text-xs bg-slate-950 border border-slate-700 rounded-lg text-slate-200 placeholder-slate-500 focus:outline-none focus:border-indigo-500" />
Zero API Key • Direct Open Biomedical Endpoints
{sciencePublications.map(sci => (
{sci.source} • {sci.identifier} Peer-Reviewed

{sci.title}

Authors: {sci.authors.join(', ')}
{sci.journalOrVenue} ({sci.publicationDate})

{sci.abstractSnippet}

Algorithms: {sci.relevantAlgorithmIds.map(algo => ( {algo} ))}
{sci.algorithmicContext} Read Paper
))}
)} {/* ========================================================================= */} {/* SUB-TAB 3: ADR / ADX EXCHANGE LIVE LEDGER */} {/* ========================================================================= */} {activeSubTab === 'adxLedger' && (
Americana Digital Reserve (ADR) & Exchange (ADX) Synchronized Ledger

Cryptographic Merkle blocks linking peer-reviewed scientific breakthroughs, court orders, and housing reserve allocations into the immutable trust res.

Total Settlement: $500,000,000.00
45,850,000 LEU Shares
{adxLedger.map((update, idx) => (
{update.updateId} {update.triggerEvent}
{update.timestamp}
Algorithmic Correlation & Citation
{update.algorithmId}
{update.scientificCitation}
Housing & Fiduciary Delta
{update.housingAllocationDelta}
Merkle Root: {update.merkleRootHash}
))}
)} {/* ========================================================================= */} {/* SUB-TAB 4: 30 ROW HOMES SSDI / SSI HOUSING ALLOCATION */} {/* ========================================================================= */} {activeSubTab === 'ssdiHousing' && (

30 Historic Row Homes Dedicated PSDLEF SSDI/SSI Applicant Housing

Carveout under Baltimore Historic Rowhomes Housing Preservation SPV (300 Properties Total)

In direct execution of the user directive and Rule 18 Iteration II (Administrative Mortality Due Process Exaction), exactly 30 historic row homes across Baltimore County and City are perpetually designated as expedited, zero-cost transitional and supportive housing specifically for SSDI and SSI disability applicants facing protracted Social Security Administration hearing delays (exceeding 800+ days).

{/* Allocation Statistics Grid */}
Dedicated Housing Units
30 Row Homes
Part of 300 SPV Portfolio (10%)
Dedicated Capital Res
$12,500,000.00
1,146,250 Converted LEU Shares
Target Claimants
SSDI / SSI Applicants
800+ Day Administrative Queue
Triage Governance Engine
MORTAR Engine
Anti-Starvation Delay Invariant
{/* Housing Operational Protocols */}

Operational & Fiduciary Execution Architecture (30 Row Homes)

1. Architectural Rehabilitation

Historic masonry repointing, structural stabilization, and complete ADA Title II physical and cognitive accessibility retrofit across Baltimore County/City locations.

2. Anti-Starvation Allocation

Adjudicated via the MORTAR locality-sensitive queueing algorithm to prevent mortality and eviction while applicants wait for Title II/XVI administrative hearings.

3. Bankruptcy Remote Protection

Vested in the Wyoming Sovereign Purpose Trust under Wyo. Stat. Ann. § 17-23-114, completely insulated from municipal condemnation, tax sales, or commingling.

)}
); };