'use client'; import { useState, useEffect } from 'react'; import { Mail, FileText, ChevronDown, ChevronUp } from 'lucide-react'; import PDFViewer from '../components/PDFViewer'; interface Document { id: number; title: string; summary?: string; notes?: string; displayOrder: number; } interface DocketEntry { id: number; date: string; title: string; summary: string; notes?: string; documents: Document[]; } export default function HomePage() { const [docketEntries, setDocketEntries] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [expandedEntries, setExpandedEntries] = useState>(new Set()); const [email, setEmail] = useState(''); const [subscribing, setSubscribing] = useState(false); const [subscribeMessage, setSubscribeMessage] = useState(''); const [selectedDocument, setSelectedDocument] = useState<{ id: number; title: string; url: string; } | null>(null); const [isMobile, setIsMobile] = useState(false); useEffect(() => { fetchDocketEntries(); }, []); useEffect(() => { const checkMobile = () => { setIsMobile(window.innerWidth < 768); }; checkMobile(); window.addEventListener('resize', checkMobile); return () => window.removeEventListener('resize', checkMobile); }, []); const fetchDocketEntries = async () => { try { const response = await fetch('/api/docket-entries'); if (!response.ok) { throw new Error('Failed to fetch docket entries'); } const data = await response.json(); setDocketEntries(data.entries || []); } catch (err) { setError(err instanceof Error ? err.message : 'An error occurred'); } finally { setLoading(false); } }; const toggleEntry = (entryId: number) => { const newExpanded = new Set(expandedEntries); if (newExpanded.has(entryId)) { newExpanded.delete(entryId); } else { newExpanded.add(entryId); } setExpandedEntries(newExpanded); }; const handleSubscribe = async (e: React.FormEvent) => { e.preventDefault(); setSubscribing(true); setSubscribeMessage(''); try { const response = await fetch('/api/subscriptions/subscribe', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email }), }); const data = await response.json(); if (response.ok) { setSubscribeMessage('Successfully subscribed! You will receive notifications for new filings.'); setEmail(''); } else { setSubscribeMessage(data.message || 'Failed to subscribe. Please try again.'); } } catch (err) { setSubscribeMessage('Failed to subscribe. Please try again.'); } finally { setSubscribing(false); } }; const formatDate = (dateString: string) => { // Extract date parts directly to avoid timezone conversion issues const datePart = dateString.split('T')[0]; // Get just YYYY-MM-DD part if (!datePart) return 'Invalid Date'; const parts = datePart.split('-'); if (parts.length !== 3) return 'Invalid Date'; const [year, month, day] = parts; if (!year || !month || !day) return 'Invalid Date'; const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day)); return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric', }); }; const getLastUpdated = () => { if (docketEntries.length === 0) return 'No entries'; const latest = docketEntries.length > 0 ? docketEntries[docketEntries.length - 1] : null; return latest ? formatDate(latest.date) : 'No entries'; }; const handleDocumentClick = (doc: Document) => { const documentUrl = `/api/documents/${doc.id}/download`; if (isMobile) { // On mobile, open PDF directly in new tab (MCDI approach) window.open(documentUrl, '_blank'); } else { // On desktop, use modal viewer setSelectedDocument({ id: doc.id, title: doc.title, url: documentUrl }); } }; if (loading) { return (

Loading court documents...

); } return (
{/* Centered Header */}

ELIZABETH KRAGH
v.
MONTANA ASSOCIATION OF THE DEAF

Court Docket & Legal Documents

Stay Informed

setEmail(e.target.value)} placeholder="Enter your email address" style={{ flex: '1', padding: '0.5rem 0.75rem', fontSize: '0.875rem', border: '1px solid #d1d5db', borderRadius: '0.375rem' }} required />
{subscribeMessage && (

{subscribeMessage}

)}
{/* Centered Case Information */}

Case Information

Case Title
Elizabeth Kragh v. Montana Association of the Deaf
Status
Active Litigation
Last Updated
{getLastUpdated()}
{/* Centered Court Docket Entries */}

Court Docket Entries

Chronological record of all court filings and proceedings

{error ? (

{error}

) : docketEntries.length === 0 ? (

No Docket Entries

No court documents have been filed yet.

) : (
{docketEntries.map((entry, index) => (
{/* Expanded Content */} {expandedEntries.has(entry.id) && (
{entry.summary && (

Brief Summary:

{entry.summary}

)}
{entry.documents .sort((a, b) => a.displayOrder - b.displayOrder) .map((doc) => (
))}
)}
))}
)}
{/* PDF Viewer Modal */} {selectedDocument && ( setSelectedDocument(null)} documentTitle={selectedDocument.title} documentUrl={selectedDocument.url} /> )} {/* Footer */}
); }