import { Badge, Text } from "@cloudflare/kumo"; import { numberFormat } from "@cloudhal/messages/format"; import { Flag } from "@phosphor-icons/react"; import type { ReactNode } from "react"; import { CommentTime } from "./CommentParts.tsx"; import { COMMENT_REPORT_REASONS, type CommentReportReason } from "./comment-model.ts"; import { InsetPanel } from "./InsetPanel.tsx"; /** A `comment_reports` row as the thread view receives it (RFC-0007 §4.1, §6.6): never the reporter's email. */ export interface CommentReport { id: string; reason: CommentReportReason; /** The reporter's words: untrusted plain text, at most 1,000 characters. */ details?: string; createdAt: string; resolvedAt?: string; /** The decision in words, already worded by the screen ("Hidden — abuse", "No action"). */ resolution?: string; } export interface CommentReportsLabels { /** Accessible name of the list ("Reports"). */ title: string; /** `(open, total)` → "2 open reports of 3". */ summary: (open: number, total: number) => string; /** Report reasons as the reader picked them: Spam, Abuse, Personal data, Illegal content, Other. */ reason: Record; /** "Open" and "Resolved". */ open: string; resolved: string; /** When the reader gave no details ("No details given"). */ noDetails: string; /** Above the details: "The reader's words, as sent". */ details: string; } export interface CommentReportsProps { reports: readonly CommentReport[]; locale: string; now?: number; labels: CommentReportsLabels; /** A report's buttons ("Resolve…"), shown on open reports. */ renderActions?: (report: CommentReport) => ReactNode; } /** * The reports on one comment (EU DSA Art. 16 notices; RFC-0007 §6.6, §14 thread): a summary line * with the count per reason, then each report — reason badge, open or resolved, time, the * reader's details as plain text in a recessed `InsetPanel` (untrusted, no links), and the * resolution. A report never changes a comment's status by itself; the screen's actions decide. */ export function CommentReports({ reports, locale, now, labels, renderActions, }: CommentReportsProps) { if (reports.length === 0) return null; const open = reports.filter((r) => !r.resolvedAt).length; const counts = COMMENT_REPORT_REASONS.map( (reason) => [reason, reports.filter((r) => r.reason === reason).length] as const, ).filter(([, n]) => n > 0); const number = numberFormat(locale); // Open reports first, newest first within each group. const sorted = [...reports].sort( (a, b) => Number(Boolean(a.resolvedAt)) - Number(Boolean(b.resolvedAt)) || b.createdAt.localeCompare(a.createdAt), ); return (
{labels.summary(open, reports.length)} {counts.map(([reason, n]) => ( {labels.reason[reason]} · {number.format(n)} ))}
    {sorted.map((r) => (
  1. {labels.reason[r.reason]} {r.resolvedAt ? labels.resolved : labels.open} {!r.resolvedAt && renderActions && ( {renderActions(r)} )}
    {r.details ? ( {r.details} ) : ( {labels.noDetails} )} {r.resolution && ( {r.resolution} )}
  2. ))}
); }