'use client'; import { useEffect, useState } from 'react'; import { Database, BookOpen, Scale, FileText, Link2, Boxes, TrendingUp, Calendar } from 'lucide-react'; import { BackButton } from '@/components/common/BackButton'; interface Stats { totalLaws: number; totalSections: number; totalJudgments: number; totalRegulations: number; totalTemplates: number; totalRagChunks: number; totalCrossRefs: number; totalLaborSections: number; lawsByCategory: Array<{ category: string; count: number; sectionCount: number; laborSectionCount: number }>; templatesByCategory: Array<{ category: string; count: number }>; regulationStatus: { active: number; superseded: number }; latestJudgmentYear: string | null; version: string; } const CATEGORY_LABELS: Record = { labor: 'แรงงาน', civil: 'แพ่งและพาณิชย์', criminal: 'อาญา', business: 'ธุรกิจ', other: 'อื่นๆ', }; export function DataDashboardView() { const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { fetch('/api/stats') .then(r => r.json()) .then(data => { setStats(data); setLoading(false); }) .catch(() => setLoading(false)); }, []); if (loading) { return (
กำลังโหลด...
); } if (!stats) return null; const cards = [ { icon: BookOpen, label: 'กฎหมาย', value: stats.totalLaws, color: 'text-blue-400', sub: `${stats.totalSections.toLocaleString()} มาตรา` }, { icon: Scale, label: 'คำพิพากษาฎีกา', value: stats.totalJudgments, color: 'text-purple-400', sub: `ล่าสุดปี ${stats.latestJudgmentYear || '-'}` }, { icon: FileText, label: 'อนุบัญญัติ/กฎกระทรัฐมนตรี', value: stats.totalRegulations, color: 'text-amber-400', sub: `${stats.regulationStatus?.active || 0} ใช้บังคับ` }, { icon: FileText, label: 'เทมเพลตเอกสาร', value: stats.totalTemplates, color: 'text-green-400', sub: 'พร้อมใช้งาน' }, { icon: Boxes, label: 'RAG Chunks', value: stats.totalRagChunks.toLocaleString(), color: 'text-cyan-400', sub: 'สำหรับ AI ค้นข้อมูล' }, { icon: Link2, label: 'Cross-references', value: stats.totalCrossRefs.toLocaleString(), color: 'text-pink-400', sub: 'เชื่อมโยงข้อมูล' }, ]; return (

สถานะข้อมูลระบบ

ภาพรวมข้อมูลทั้งหมดในฐานข้อมูล Panya-AI — อัปเดตล่าสุด: {new Date().toLocaleDateString('th-TH')}

{/* Stats cards */}
{cards.map((card) => { const Icon = card.icon; return (
{card.label}
{card.value}
{card.sub}
); })}
{/* Laws by category */}

กฎหมายแยกตามหมวด

{stats.lawsByCategory?.map((cat) => { const label = CATEGORY_LABELS[cat.category] || cat.category; const maxSections = Math.max(...stats.lawsByCategory.map(c => c.sectionCount)); const pct = maxSections > 0 ? (cat.sectionCount / maxSections) * 100 : 0; return (
{label} {cat.count} ฉบับ · {cat.sectionCount.toLocaleString()} มาตรา {cat.laborSectionCount > 0 && ({cat.laborSectionCount} แรงงาน)}
); })}
{/* Regulation status */} {stats.regulationStatus && (

สถานะอนุบัญญัติ

{stats.regulationStatus.active}
ใช้บังคับ (ฉบับรวมล่าสุด)
{stats.regulationStatus.superseded}
ฉบับเก่า (ถูกแทนที่)
)} {/* Data freshness */}

ความสดของข้อมูล

ฎีกาล่าสุดในระบบ: ปี {stats.latestJudgmentYear || 'ไม่ทราบ'}
ปีปัจจุบัน (พ.ศ.): {new Date().getFullYear() + 543}
ระบบตรวจสอบกฎหมายใหม่: เปิดใช้งาน (รายวัน)
); }