import React, { useState, useEffect } from 'react'; import { FiX, FiSend, FiCpu, FiUser, FiInfo, FiRefreshCw, FiZap, FiCheck } from 'react-icons/fi'; import taService from '../../services/ta.service'; const AiComposeModal = ({ isOpen, onClose, context, onSend, isSending }) => { const [message, setMessage] = useState(''); const [generating, setGenerating] = useState(false); const [refineQuery, setRefineQuery] = useState(''); const [currentTone, setCurrentTone] = useState('helpful'); const tones = [ { id: 'helpful', label: 'Thân thiện', icon: '😊' }, { id: 'urgent', label: 'Nghiêm túc', icon: '⚖️' }, { id: 'inspire', label: 'Khích lệ', icon: '🔥' }, { id: 'casual', label: 'Gần gũi', icon: '🤝' }, ]; const compileRules = (rulesObj = {}) => { const ruleTexts = { useEmoji: "Sử dụng emoji phù hợp", friendlyTone: "Giọng văn thân thiện", noRobotic: "Tránh dùng từ ngữ máy móc", offerSupport1on1: "Đề nghị hỗ trợ 1-1", mentionLastSeen: "Đề cập đến thời gian vắng mặt", includeHomework: "Có mục bài tập về nhà", includeTips: "Có mục Tips & Tricks", useTable: "Sử dụng bảng tóm tắt", boldKeyInfo: "In đậm thông tin quan trọng", urgentAction: "Yêu cầu hành động khẩn cấp" }; return Object.entries(rulesObj) .filter(([_, enabled]) => enabled) .map(([key, _]) => `- ${ruleTexts[key] || key}`) .join('\n'); }; const generateMessage = async (tone = currentTone, instruction = '') => { if (!context?.id) return; setGenerating(true); try { // Sử dụng config đa tầng từ Dashboard const config = context.aiConfig || {}; const g = config.global || {}; const d = config.dm || {}; const finalInstruction = ` [MỤC TIÊU DM]: ${d.goal || 'hỏi thăm'} [ĐỘ DÀI]: ${d.length || 'vừa phải'} [QUY TẮC CHUNG]: ${compileRules(g.rules)} ${g.instruction || ''} [QUY TẮC DM]: ${compileRules(d.rules)} ${d.instruction || ''} ${instruction ? `[YÊU CẦU HIỆU CHỈNH]: ${instruction}` : ''} `.trim(); const res = await taService.generateSmartMessage(context.id, tone, { instruction: finalInstruction, pronouns: g.pronouns || 'mình - bạn', taName: context.taName || 'Trợ giảng' }); if (res.success && res.data?.content) { setMessage(res.data.content); setCurrentTone(tone); } } catch (error) { console.error('AI DM Error:', error); } finally { setGenerating(false); } }; useEffect(() => { if (isOpen && context?.id) { generateMessage('helpful'); } }, [isOpen, context?.id]); if (!isOpen) return null; return (
{/* Header */}

Trợ lý Soạn tin DM

Cá nhân hóa cho học viên
{/* Student Info Card */} {context?.student_info && (
{context.student_info.name}
Lý do: {context.at_risk_data?.reason || 'Cần hỗ trợ học tập'}
{context.at_risk_data?.level?.toUpperCase()}
)} {/* Tone Selection */}
{tones.map(t => ( ))}
{/* Message Area */}
{generating && (
AI đang soạn tin...
)}