'use client'; import { useEffect, useState } from 'react'; import { ExternalLink, AlertTriangle, Scale, ChevronRight, BookOpen, Tag, Gavel } from 'lucide-react'; import { useNavigation } from '@/lib/navigation'; import { Badge } from '@/components/ui/badge'; import { BookmarkButton } from '@/components/common/BookmarkButton'; import { BackButton } from '@/components/common/BackButton'; interface JudgmentData { judgmentId: number; caseNumber: string | null; caseYear: string | null; court: string | null; category: string | null; caseTypeGroup: string | null; categoryCode: string | null; issueNumber: string | null; lawReferences: string | null; lawsCited: string | null; lawsCitedList?: string[]; topic: string | null; topics: string | null; topicsList?: string[]; fact: string | null; decision: string | null; ruling: string | null; verdict: string | null; issue: string | null; title: string | null; sourceId: number | null; sourceUrl: string | null; sourceName: string | null; sourceDescription: string | null; licenseNote: string | null; relatedSections: Array<{ sectionId: number; lawId: number; lawNameTh: string; articleKey: string | null; sectionNumber: string | null; sectionText: string; isLaborRelated: number; }>; } export function JudgmentView({ judgmentId }: { readonly judgmentId: number }) { const { navigate } = useNavigation(); const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { setLoading(true); fetch(`/api/judgments?id=${judgmentId}`) .then(r => { if (!r.ok) throw new Error('Judgment not found'); return r.json(); }) .then(data => { setData(data); import('@/lib/recently-viewed').then(({ addRecentlyViewed }) => { addRecentlyViewed({ type: 'judgment', id: judgmentId, label: `ฎีกา ${data.caseNumber}${data.title ? ' — ' + data.title : ''}`, url: `/?view=judgment&id=${judgmentId}` }); }); }) .catch(e => setError(e.message)) .finally(() => setLoading(false)); }, [judgmentId]); if (loading) return
กำลังโหลด…
; if (error) return
เกิดข้อผิดพลาด: {error}
; if (!data) return null; const isTSCC = data.licenseNote?.includes('TSCC'); // Use lawsCitedList if available (proper JSON array from v2 metadata), else parse legacy string const lawRefs = (data.lawsCitedList && data.lawsCitedList.length > 0) ? data.lawsCitedList : (data.lawReferences || '') .split(/[;,]/) .map(s => s.trim()) .filter(Boolean); // Topics array (tags) const topics = data.topicsList || []; return (
{/* Header */}
ฎีกา {data.caseNumber} {data.caseYear && ( ปี {data.caseYear} )} {data.category === 'แรงงาน' && ( คดีแรงงาน )} {data.category === 'อาญา' && ( คดีอาญา )} {data.caseTypeGroup && ( {data.caseTypeGroup} )} {data.court && ( {data.court} )}
{data.title && (

{data.title}

)} {/* Topics chips */} {topics.length > 0 && (
{topics.map((t, i) => ( {t} ))}
)}

แหล่งข้อมูล: {data.sourceName || 'ไม่ระบุ'} {data.sourceDescription && ` — ${data.sourceDescription}`}

{/* License warning */} {isTSCC && (
ข้อควรระวังด้าน License:{' '} คำพิพากษานี้มาจาก TSCC Dataset ซึ่งกำหนดให้ใช้เพื่อการวิจัยเท่านั้น (academic use only) ห้ามนำไปใช้เชิงพาณิชย์ ใช้ผ่านระบบ RAG เพื่อการศึกษา
)} {/* Fact */} {data.fact && (

ข้อเท็จจริง / สรุปคดี

{data.fact}
)} {/* Issue (ประเด็นของคดี) */} {data.issue && (

ประเด็นของคดี

{data.issue}
)} {/* Decision */} {data.decision && (

คำวินิจฉัย

{data.decision}
)} {/* Verdict (บทสุดท้าย) */} {data.verdict && (

คำพิพากษา

{data.verdict}
)} {/* External link */} {data.sourceUrl && ( )}
{/* Law references (citations) */} {lawRefs.length > 0 && (

กฎหมายที่อ้างอิง ({lawRefs.length} มาตรา)

{lawRefs.map((ref, i) => ( {ref} ))}
)} {/* Related sections */} {data.relatedSections.length > 0 && (

มาตราที่เกี่ยวข้อง ({data.relatedSections.length})

{data.relatedSections.map(s => ( ))}
)}
); }