'use client'; import { useEffect, useState } from 'react'; import { Scale, AlertTriangle, BookOpen, ChevronRight } 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 SectionData { sectionId: number; lawId: number; lawNameTh: string; articleKey: string | null; sectionNumber: string | null; sectionText: string; isLaborRelated: number; isCancelled: number; chapter: string | null; notes: string | null; relatedJudgments: Array<{ judgmentId: number; caseNumber: string | null; caseYear: string | null; category: string | null; title: string | null; fact: string | null; decision: string | null; sourceUrl: string | null; sourceName: string | null; licenseNote: string | null; }>; } export function SectionView({ sectionId }: { readonly sectionId: number }) { const { navigate } = useNavigation(); const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { setLoading(true); fetch(`/api/sections?id=${sectionId}`) .then(r => { if (!r.ok) throw new Error('Section not found'); return r.json(); }) .then(data => { setData(data); import('@/lib/recently-viewed').then(({ addRecentlyViewed }) => { const label = `${data.lawNameTh} มาตรา ${data.articleKey || data.sectionNumber || ''}`; addRecentlyViewed({ type: 'section', id: sectionId, label, url: `/?view=section&id=${sectionId}` }); }); }) .catch(e => setError(e.message)) .finally(() => setLoading(false)); }, [sectionId]); if (loading) return
กำลังโหลด…
; if (error) return
เกิดข้อผิดพลาด: {error}
; if (!data) return null; return (
{/* Section header */}
{data.isLaborRelated === 1 && ( มาตราแรงงาน )} {data.isCancelled === 1 && ( ยกเลิกแล้ว )} {data.chapter && ( {data.chapter} )}

{data.articleKey || `มาตรา ${data.sectionNumber}`}

{data.lawNameTh}

{/* Section text */}
{data.sectionText}
{data.notes && (
หมายเหตุ: {data.notes}
)}
{/* Related judgments */}

คำพิพากษาฎีกาที่อ้างถึงมาตรานี้ ({data.relatedJudgments.length})

{data.relatedJudgments.length === 0 ? (

ยังไม่มีคำพิพากษาในระบบที่อ้างถึงมาตรานี้โดยตรง

) : (
{data.relatedJudgments.map(j => ( ))}
)}
); }