import React, { useState } from 'react'; import { X, ShieldAlert, MapPin, Loader2, Phone, Mail, AlertTriangle } from 'lucide-react'; import { useTranslation } from '../hooks/useTranslation'; interface ReportBusinessModalProps { isOpen: boolean; onClose: () => void; initialLatitude?: number; initialLongitude?: number; } export const ReportBusinessModal: React.FC = ({ isOpen, onClose, initialLatitude, initialLongitude }) => { const { t } = useTranslation(); const [type, setType] = useState('RESTAURANT'); const [name, setName] = useState(''); const [phone, setPhone] = useState(''); const [email, setEmail] = useState(''); const [address, setAddress] = useState(''); const [latitude, setLatitude] = useState(initialLatitude ? String(initialLatitude) : ''); const [longitude, setLongitude] = useState(initialLongitude ? String(initialLongitude) : ''); const [reason, setReason] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const [success, setSuccess] = useState(false); React.useEffect(() => { if (isOpen) { setLatitude(initialLatitude ? String(initialLatitude) : ''); setLongitude(initialLongitude ? String(initialLongitude) : ''); setSuccess(false); setError(''); } }, [isOpen, initialLatitude, initialLongitude]); if (!isOpen) return null; const handleGetCurrentLocation = () => { if (!navigator.geolocation) { setError('Trình duyệt không hỗ trợ định vị GPS.'); return; } navigator.geolocation.getCurrentPosition( (position) => { setLatitude(String(position.coords.latitude.toFixed(6))); setLongitude(String(position.coords.longitude.toFixed(6))); }, () => { setError('Không thể lấy vị trí hiện tại. Vui lòng bật định vị GPS.'); } ); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); try { const response = await fetch(`/api/v1/reports`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ type, name, phone: phone || null, email: email || null, address: address || null, latitude: latitude ? parseFloat(latitude) : null, longitude: longitude ? parseFloat(longitude) : null, reason, }), }); const data = await response.json(); if (!response.ok) { throw new Error(data.message || 'Gửi báo cáo thất bại.'); } setSuccess(true); setTimeout(() => { onClose(); // Reset form setName(''); setPhone(''); setEmail(''); setAddress(''); setLatitude(''); setLongitude(''); setReason(''); }, 2000); } catch (err: any) { setError(err.message); } finally { setIsLoading(false); } }; return (
{/* Backdrop */}
{/* Content Container */}
{/* Header */}

{t('reportModalTitle')}

Báo cáo các hành vi không lành mạnh hoặc lừa đảo kinh doanh.

{success ? (

{t('success')}!

{t('reportSuccess')}

) : (
{error && (
{error}
)} {/* Loại hình */}
{/* Tên */}
setName(e.target.value)} placeholder="VD: Nhà hàng ABC, Homestay X..." className="w-full px-4 py-3 bg-gray-50 border border-gray-100 rounded-2xl focus:ring-2 focus:ring-blue-500 focus:bg-white outline-none transition-all text-sm text-gray-800" />
{/* Số điện thoại */}
setPhone(e.target.value)} placeholder="0987xxxxxx" className="w-full px-4 py-3 bg-gray-50 border border-gray-100 rounded-2xl focus:ring-2 focus:ring-blue-500 focus:bg-white outline-none transition-all text-sm text-gray-800" />
{/* Email */}
setEmail(e.target.value)} placeholder="contact@business.com" className="w-full px-4 py-3 bg-gray-50 border border-gray-100 rounded-2xl focus:ring-2 focus:ring-blue-500 focus:bg-white outline-none transition-all text-sm text-gray-800" />
{/* Địa chỉ */}
setAddress(e.target.value)} placeholder="VD: 123 Đường Trần Phú, Đà Lạt..." className="w-full px-4 py-3 bg-gray-50 border border-gray-100 rounded-2xl focus:ring-2 focus:ring-blue-500 focus:bg-white outline-none transition-all text-sm text-gray-800" />
{/* Tọa độ địa lý */}
📍 Vị trí địa lý (Tùy chọn)
setLatitude(e.target.value)} placeholder="11.9404" className="w-full px-3 py-2 bg-white border border-gray-200 rounded-xl outline-none text-xs text-gray-800" />
setLongitude(e.target.value)} placeholder="108.4382" className="w-full px-3 py-2 bg-white border border-gray-200 rounded-xl outline-none text-xs text-gray-800" />
{/* Lý do */}