import React, { useState } from 'react'; import { Star, X } from 'lucide-react'; const FeedbackModal = ({ isOpen, onClose, toolName, projectName, isArabic, inline = false }) => { const [rating, setRating] = useState(0); const [hoveredRating, setHoveredRating] = useState(0); const [reason, setReason] = useState(''); const [submitting, setSubmitting] = useState(false); const [submitted, setSubmitted] = useState(false); if (!isOpen && !inline) return null; const handleSubmit = async () => { if (rating === 0) return; if (rating < 4 && !reason.trim()) { alert(isArabic ? 'يرجى كتابة سبب التقييم المنخفض لتحسين الخدمة.' : 'Please provide a reason for the low rating to help us improve.'); return; } setSubmitting(true); try { const token = localStorage.getItem('qto_token'); const res = await fetch('/api/feedback', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, body: JSON.stringify({ tool_name: toolName, project_name: projectName, rating: rating, reason: reason }) }); if (res.ok) { setSubmitted(true); setTimeout(() => { if (onClose) onClose(); // reset state for next time setTimeout(() => { setRating(0); setHoveredRating(0); setReason(''); setSubmitted(false); }, 500); }, 2000); } else { alert(isArabic ? 'فشل إرسال التقييم. حاول مرة أخرى.' : 'Failed to submit feedback. Try again.'); } } catch (err) { console.error(err); alert(isArabic ? 'حدث خطأ غير متوقع.' : 'An unexpected error occurred.'); } finally { setSubmitting(false); } }; const cardContent = (
{isArabic ? 'تم إرسال تقييمك بنجاح.' : 'Your feedback has been submitted successfully.'}
{isArabic ? `كيف كانت تجربتك في أداة ${toolName} لمشروع ${projectName}؟` : `How was your experience using ${toolName} for project ${projectName}?`}