'use client'; import { useEffect, useState } from 'react'; import { FileText, ChevronRight, Download, Search } from 'lucide-react'; import { Input } from '@/components/ui/input'; import { Badge } from '@/components/ui/badge'; interface Template { templateId: number; templateCode: string; title: string; category: string; charsCount: number; } const CATEGORY_LABELS: Record = { labor: 'เอกสารแรงงาน', accounting: 'บัญชี/เงินเดือน', contracts: 'สัญญาธุรกิจ', court: 'เอกสารศาล', sso: 'เอกสาร สปส.', }; export function TemplatesView() { const [templates, setTemplates] = useState([]); const [loading, setLoading] = useState(true); const [filter, setFilter] = useState('all'); const [searchQ, setSearchQ] = useState(''); useEffect(() => { fetch('/api/templates') .then(r => r.json()) .then(d => setTemplates(d.data || [])) .catch(console.error) .finally(() => setLoading(false)); }, []); const visible = templates.filter(t => { if (filter !== 'all' && t.category !== filter) return false; if (searchQ && !t.title.includes(searchQ)) return false; return true; }); const categories = ['all', ...Array.from(new Set(templates.map(t => t.category)))]; return (

เอกสารและสัญญา (หมวด F)

65 เทมเพลตเอกสารพร้อมใช้ — คลิกเพื่อดู + ดาวน์โหลด PDF พร้อมกรอกชื่อพนักงาน

{/* Search */}
setSearchQ(e.target.value)} className="pl-10 bg-card-soft border-border/60" />
{/* Category filter */}
{categories.map(c => ( ))}
{/* Templates grid */} {renderTemplatesList(loading, visible)}
); } /** Renders the templates list — extracted to satisfy S3358 (no nested ternary). */ function renderTemplatesList(loading: boolean, visible: Template[]) { if (loading) { return
กำลังโหลด…
; } if (visible.length === 0) { return (
ไม่พบเอกสารที่ตรงกับเงื่อนไข
); } return (
{visible.map(t => ( ))}
); } function TemplateCard({ template }: { readonly template: Template }) { const catLabel = CATEGORY_LABELS[template.category] || template.category; return (
{template.templateCode} {catLabel}

{template.title}

{template.charsCount} ตัวอักษร ดู/ดาวน์โหลด PDF
); }