"use client"; import { useEffect, useId, useRef, useState } from "react"; import { Flag } from "lucide-react"; import { api } from "@/lib/client-api"; import { communityCategories } from "@/shared/community"; import { useI18n } from "./I18nProvider"; export function ReportCommunity({ target, targetId, }: { target: "comment" | "account"; targetId: string; }) { const { t } = useI18n(); const titleId = useId(); const dialog = useRef(null); const [open, setOpen] = useState(false); const [category, setCategory] = useState("spam"); const [reason, setReason] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(""); const [message, setMessage] = useState(""); const label = target === "comment" ? "Report comment" : "Report account"; useEffect(() => { if (!open) return; const previous = document.activeElement instanceof HTMLElement ? document.activeElement : null; const element = dialog.current; element?.showModal(); return () => { element?.close(); previous?.focus(); }; }, [open]); async function submit(event: React.FormEvent) { event.preventDefault(); setBusy(true); setError(""); try { await api("community/reports", { target, targetId, category, reason }); setMessage("Report sent for moderator review."); setOpen(false); setReason(""); } catch (e) { setError((e as Error).message); } finally { setBusy(false); } } return ( <> {message && ( {t(message)} )} {open && ( setOpen(false)} >

{t(label)}

{t( "A moderator will review your report. Reports do not automatically remove content or ban accounts.", )}