'use client'; import { useState } from 'react'; import { ChevronRight, ChevronDown, ChevronUp, BookOpen } from 'lucide-react'; import { useNavigation } from '@/lib/navigation'; import { Badge } from '@/components/ui/badge'; import type { LawSummary } from '@/lib/types'; const CATEGORY_LABEL: Record = { labor: { th: 'กฎหมายแรงงาน', en: 'Labor' }, civil: { th: 'แพ่งและพาณิชย์', en: 'Civil' }, criminal: { th: 'อาญา', en: 'Criminal' }, civil_procedure: { th: 'วิธีพิจารณาแพ่ง', en: 'Civil Procedure' }, criminal_procedure: { th: 'วิธีพิจารณาอาญา', en: 'Criminal Procedure' }, land: { th: 'ที่ดิน', en: 'Land' }, rent: { th: 'เช่าเคหะ', en: 'Rent Control' }, narcotics: { th: 'ยาเสพติด', en: 'Narcotics' }, traffic: { th: 'จราจร', en: 'Traffic' }, other: { th: 'อื่นๆ', en: 'Other' }, }; /** Resolve law status badge className (extracted from nested ternary — SonarCloud S3358). */ function getStatusBadgeClass(status: string): string { if (status === 'repealed') return 'border-red-500/40 text-red-500 bg-red-500/10'; if (status === 'amended') return 'border-blue-500/40 text-blue-500 bg-blue-500/10'; return 'border-amber-500/40 text-amber-600 bg-amber-500/10'; } /** Resolve law status label in Thai (extracted from nested ternary — SonarCloud S3358). */ function getStatusLabel(status: string): string { if (status === 'repealed') return 'ยกเลิก'; if (status === 'amended') return 'แก้ไขแล้ว'; return status; } export function LawList({ laws }: { readonly laws: LawSummary[] }) { const { navigate } = useNavigation(); const [filter, setFilter] = useState('all'); const [expanded, setExpanded] = useState(false); // Group by category const grouped: Record = {}; for (const l of laws) { const cat = l.category || 'other'; if (!grouped[cat]) grouped[cat] = []; grouped[cat].push(l); } const visibleLaws = filter === 'all' ? laws : (grouped[filter] || []); const categories = ['all', ...Object.keys(grouped)]; const totalLaws = laws.length; return (

กฎหมายในระบบ

รวมทั้งหมด {totalLaws} ฉบับ — คลิก "ดูทั้งหมด" เพื่อแสดงรายการ หรือเลือกหมวดเพื่อกรอง

{/* Expand / collapse toggle — primary action */}
{/* Filter chips — always visible so user can pre-select a category */} {expanded && (
{categories.map(c => ( ))}
)} {/* Laws grid — only render when expanded; otherwise show category teaser cards */} {expanded ? ( ) : ( /* Collapsed teaser — show category counts only */
{Object.entries(grouped).map(([cat, items]) => { const label = CATEGORY_LABEL[cat]?.th || cat; return ( ); })}
)}
); } /** Renders the grid of law cards, or an empty-state message if no laws match the filter. */ function LawsGrid({ laws, navigate }: { readonly laws: LawSummary[]; readonly navigate: (v: any) => void }) { if (laws.length === 0) { return
ไม่มีกฎหมายในหมวดนี้
; } return (
{laws.map(law => ( navigate({ name: 'law', lawId: law.lawId })} /> ))}
); } function LawCard({ law, onClick }: { readonly law: LawSummary; readonly onClick: () => void }) { const cat = CATEGORY_LABEL[law.category || 'other'] || { th: law.category, en: '' }; return ( ); }