'use client' import { useState } from 'react' import api from '@/services/api' type TargetType = 'post' | 'user' | 'comment' type ReportReason = | 'spam' | 'harassment' | 'misinformation' | 'inappropriate_content' | 'copyright_violation' | 'other' interface ReportModalProps { isOpen: boolean onClose: () => void targetType: TargetType targetId: string targetName?: string } interface ReportPayload { targetType: TargetType targetId: string reason: ReportReason details?: string } const REPORT_REASONS: { value: ReportReason; label: string; description: string }[] = [ { value: 'spam', label: 'Spam', description: 'Unwanted commercial content or repeated messages' }, { value: 'harassment', label: 'Harassment', description: 'Bullying, threats, or targeted abuse' }, { value: 'misinformation', label: 'Misinformation', description: 'False or misleading information' }, { value: 'inappropriate_content', label: 'Inappropriate Content', description: 'Nudity, violence, or graphic content', }, { value: 'copyright_violation', label: 'Copyright Violation', description: 'Unauthorized use of copyrighted material', }, { value: 'other', label: 'Other', description: 'Something else not listed above' }, ] const MAX_DETAILS_LENGTH = 500 export function ReportModal({ isOpen, onClose, targetType, targetId, targetName }: ReportModalProps) { const [selectedReason, setSelectedReason] = useState(null) const [details, setDetails] = useState('') const [submitting, setSubmitting] = useState(false) const [submitted, setSubmitted] = useState(false) const [error, setError] = useState(null) const handleClose = () => { setSelectedReason(null) setDetails('') setSubmitting(false) setSubmitted(false) setError(null) onClose() } const handleSubmit = async () => { if (!selectedReason) return setSubmitting(true) setError(null) const payload: ReportPayload = { targetType, targetId, reason: selectedReason, ...(details.trim() ? { details: details.trim() } : {}), } try { await api.post('/v1/reports', payload) setSubmitted(true) } catch (err: unknown) { const axiosError = err as { response?: { data?: { message?: string; error?: { message?: string } } } } const message = axiosError.response?.data?.error?.message || axiosError.response?.data?.message || 'Failed to submit report. Please try again.' setError(message) } finally { setSubmitting(false) } } if (!isOpen) return null const targetLabel = targetName ? `"${targetName}"` : `this ${targetType}` return (
{/* Backdrop */}