import { MessageForwardIcon } from "@chopin/icons"; import { InlineCode } from "@chopin/question/react"; import { Face } from "@chopin/editor"; import { Fragment } from "react"; import type { SourceDestination } from "./card-parts"; import { hasEvidence } from "./evidence"; import type { EvidenceCounts, EvidenceItem, EvidenceRow } from "./evidence"; const KIND: Record = { reason: "Reason", constraint: "Constraint", objection: "Objection", }; function plural(count: number, noun: string) { return `${count} ${noun}${count === 1 ? "" : "s"}`; } /** The card's one-line summary; it doubles as the popover trigger's label. */ export function EvidenceSummary({ counts }: { counts: EvidenceCounts }) { let parts = [ counts.reasons ? { text: plural(counts.reasons, "reason") } : undefined, counts.constraints ? { text: plural(counts.constraints, "constraint") } : undefined, counts.objections ? { text: plural(counts.objections, "objection"), warning: true } : undefined, ].filter(part => part !== undefined); if (parts.length === 0) return <>Evidence; return ( <> {parts.map((part, index) => ( {index > 0 && } {part.text} ))} ); } function People({ handles, label, opposed = false }: { handles: string[]; label: string; opposed?: boolean; }) { if (handles.length === 0) return null; let shown = handles.slice(0, 8); return ( {label} {handles.join(", ")} {shown.map((handle, index) => ( ))} {handles.length > 8 && ( )} ); } export function EvidencePopover({ rows, onSource }: { rows: EvidenceRow[]; onSource: (destination: SourceDestination) => void; }) { return (
{rows.filter(row => hasEvidence([row])).map(row => { // An objection already names who raised it. let objectors = new Set(row.items.flatMap(item => item.by ? [item.by] : [])); let opposers = row.opposers.filter(handle => !objectors.has(handle)); return (

{row.optionId ? : "Applies to all options"}

{(row.origin === "planner" || row.supporters.length > 0 || opposers.length > 0) && (
{row.origin === "planner" && ( Planner suggested )}
)} {row.origin === "planner" && row.rationale && (

Why Chopin suggested this: {row.rationale}

)} {row.origin === "planner" && row.source && row.optionId && (
{row.source.author.kind === "member" ? `@${row.source.author.handle}` : "Planner"} {row.source.quote}
)} {row.items.length > 0 && (
    {row.items.map(item => { let source = item.sources[0]; return (
  • {KIND[item.kind]} {item.text} {item.by && {` @${item.by}`}} {source && ( )}
  • ); })}
)}
); })}
); }