const { useState, useEffect } = React;
const { Mail, Calendar, Eye, ShieldAlert, ArrowRight, CornerDownRight, Inbox } = window.lucide;
function EmailLogsPanel() {
const [logs, setLogs] = useState([]);
const [loading, setLoading] = useState(true);
const [selectedLog, setSelectedLog] = useState(null);
useEffect(() => {
fetchLogs();
}, []);
const fetchLogs = async () => {
try {
const res = await fetch('api.php?action=email_logs');
if (res.ok) {
const text = await res.text();
try {
const data = JSON.parse(text);
setLogs(data);
if (data.length > 0) {
setSelectedLog(data[0]);
}
} catch (jsonErr) {
console.error('Expected JSON from /api/email-logs but got HTML/text:', text.substring(0, 100));
}
}
} catch (e) {
console.error('Failed to fetch email logs:', e);
} finally {
setLoading(false);
}
};
if (loading) {
return (
);
}
return (
{/* Logs List (Left) */}
ประวัติการแจ้งเตือนอีเมล (Email Outbox Logs)
{logs.length === 0 ? (
ยังไม่มีบันทึกการส่งอีเมล
เมื่อคุณอัปโหลดสแกนสำเร็จ และเปิดโหมด Email Notification ระบบจะทำการบันทึกและแสดงสรุปจดหมายที่นี่
) : (
{logs.map((log) => (
))}
)}
{/* Log Preview Frame (Right) */}
{selectedLog ? (
{/* Header */}
{selectedLog.subject}
ถึง (To):
{selectedLog.to}
{new Date(selectedLog.timestamp).toLocaleString('th-TH')}
{selectedLog.status === 'simulated' && (
โหมดจดหมายจำลอง (Email Simulation): สรุปรายงานสแกนถูกบันทึกสำเร็จโดยไม่ต้องส่งออกจริง หากต้องการส่งตรงเข้า Inbox กรุณากรอกการตั้งค่า SMTP ในแทบ "ตั้งค่าระบบ"
)}
{selectedLog.status === 'failed' && (
การส่งอีเมลจริงล้มเหลว (SMTP Error): {selectedLog.errorMessage || 'เกิดข้อผิดพลาดในการเชื่อมต่อเซิร์ฟเวอร์ SMTP'}
)}
{/* Email Body Preview via iframe */}
) : (
เลือกรายการแจ้งเตือนเพื่อดูพรีวิว
)}
);
}
window.EmailLogsPanel = EmailLogsPanel;