import { Check, Flag, Loader2 } from 'lucide-react' import { useState } from 'react' import { t, type TKey } from '../../i18n' import { useBackToClose } from '../../lib/backNav' import { REPORT_DETAILS_MAX, REPORT_REASONS, reportContent, type ReportReason, type ReportTarget } from '../../lib/cloud/moderation' import { useEscape } from '../../lib/escape' import { useScrollLock } from '../../lib/scrollLock' import { cx } from '../../lib/utils' const REASON_LABEL: Record = { spoiler: 'report.reason.spoiler', harassment: 'report.reason.harassment', hate: 'report.reason.hate', sexual: 'report.reason.sexual', spam: 'report.reason.spam', impersonation: 'report.reason.impersonation', other: 'report.reason.other', } export const reasonLabel = (r: ReportReason) => t(REASON_LABEL[r]) const TITLE: Record = { review: 'report.titleReview', profile: 'report.titleProfile', comment: 'report.titleComment', list: 'report.titleList', } /** * Fenêtre « Signaler » générique (avis, profil, commentaire, liste partagée) : * motif + précision facultative (500 caractères), envoyée à l'équipe de modération. */ export default function ReportDialog({ target, onClose }: { target: ReportTarget; onClose: () => void }) { const [reason, setReason] = useState() const [details, setDetails] = useState('') const [busy, setBusy] = useState(false) const [error, setError] = useState() const [done, setDone] = useState<'sent' | 'duplicate'>() useScrollLock() useEscape(onClose) useBackToClose(onClose) const submit = async () => { if (!reason || busy) return setBusy(true) setError(undefined) try { const r = await reportContent(target, reason, details) setDone(r.duplicate ? 'duplicate' : 'sent') } catch (e) { setError((e as Error).message) } finally { setBusy(false) } } return (
e.stopPropagation()} > {done ? (

{done === 'sent' ? t('report.thanks') : t('report.already')}

{t('report.thanksText')}

) : ( <>

{t(TITLE[target.type])}

{t('report.intro')}

{t('report.reason')}
{REPORT_REASONS.map((r) => ( ))}