'use client'; // File: app/(admin)/admin/ai/intent-classification/[intentCode]/page.tsx // Change Log // - 2026-05-19: สร้างหน้า Intent Detail + Patterns (Admin, ADR-024). import { useState } from 'react'; import { useParams, useRouter } from 'next/navigation'; import { useIntentDefinition, useUpdateIntentDefinition, useIntentPatterns, useCreateIntentPattern, useDeleteIntentPattern, } from '@/hooks/ai/use-intent-classification'; import { PatternForm } from '@/components/ai/intent-classification/pattern-form'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Switch } from '@/components/ui/switch'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table'; import { ArrowLeft, Plus, Trash2 } from 'lucide-react'; import type { PatternType, PatternLanguage } from '@/lib/services/ai-intent.service'; export default function IntentDetailPage() { const params = useParams(); const router = useRouter(); const intentCode = params.intentCode as string; const [showPatternForm, setShowPatternForm] = useState(false); const { data: definition, isLoading: defLoading } = useIntentDefinition(intentCode); const updateMutation = useUpdateIntentDefinition(intentCode); const { data: patterns, isLoading: patternsLoading } = useIntentPatterns(intentCode); const createPatternMutation = useCreateIntentPattern(intentCode); const deletePatternMutation = useDeleteIntentPattern(intentCode); const handleToggleActive = async (isActive: boolean) => { await updateMutation.mutateAsync({ isActive }); }; const handleCreatePattern = async (data: { patternType: PatternType; patternValue: string; language?: PatternLanguage; priority?: number; }) => { await createPatternMutation.mutateAsync(data); setShowPatternForm(false); }; const handleDeletePattern = async (publicId: string) => { if (!confirm('ต้องการลบ Pattern นี้?')) return; await deletePatternMutation.mutateAsync(publicId); }; if (defLoading) { return
กำลังโหลด...
; } if (!definition) { returnไม่พบ Intent: {intentCode}
; } return ({definition.descriptionTh}
{definition.descriptionEn}
กำลังโหลด...
) : patterns && patterns.length > 0 ? (ยังไม่มี Pattern — เพิ่มเพื่อให้ Pattern Matching ทำงาน
)}