// File: components/ai/document-comparison-view.tsx // Side-by-side PDF viewer + Form ที่มี AI Suggestions (ADR-018, ADR-020) import { useState } from 'react'; import { Eye, ChevronDown, ChevronUp } from 'lucide-react'; import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { AiSuggestionField } from './ai-suggestion-field'; import type { ExtractionResult } from '@/types/ai'; // Labels ภาษาไทยสำหรับ field ต่างๆ const FIELD_LABELS: Record = { subject: 'ชื่อเรื่อง', documentDate: 'วันที่เอกสาร', category: 'ประเภทเอกสาร', senderId: 'รหัสองค์กรผู้ส่ง', disciplineId: 'สาขา (Discipline)', issuedDate: 'วันที่ออกเอกสาร', receivedDate: 'วันที่รับเอกสาร', projectCode: 'รหัสโครงการ', documentNumber: 'เลขที่เอกสาร', }; // Fields ที่แสดงใน comparison view const DISPLAY_FIELDS = ['subject', 'documentDate', 'category', 'disciplineId', 'senderId']; export interface DocumentComparisonViewProps { fileUrl: string | null; extractedData: ExtractionResult | null; formData: Record; onFieldUpdate: (field: string, value: string) => void; extractedText?: string; reviewReason?: string; } export function DocumentComparisonView({ fileUrl, extractedData, formData, onFieldUpdate, extractedText, reviewReason, }: DocumentComparisonViewProps) { const [showRawText, setShowRawText] = useState(false); // แกะ metadata และ confidence จาก ExtractionResult const metadata = (extractedData?.extractedMetadata ?? {}) as Record; const fieldConfidences = metadata.fieldConfidences as Record | undefined; const getSuggestion = (field: string): string | undefined => { const val = metadata[field]; return val !== undefined ? String(val) : undefined; }; const getConfidence = (field: string): number | undefined => fieldConfidences?.[field] ?? extractedData?.confidenceScore; return (
{/* Left: PDF Viewer */} {fileUrl ? (