/** The same compact decision facts in the hover preview and pinned popover. */ import { ChosenList } from "@chopin/question/react"; import { ClockIcon, CloseIcon, MessageForwardIcon } from "@chopin/icons"; import { decidedOn, discussionLine } from "./decision-format"; import { Face } from "./face"; import type { ReactNode, Ref } from "react"; import type { Questionnaire } from "@chopin/dialect"; import type { Question } from "@chopin/protocol"; export function DecisionSummary( { actions, full = false, meta, value, }: { actions?: ReactNode; full?: boolean; meta: Question.CardMeta; value: Questionnaire; }, ) { let question = value.questions[0]; if (!question) return null; let selected = question.choices?.length ? question.choices : question.options.filter(option => option.label === question.answer).map(option => option.id); let answer: Question.Answer = { question: question.prompt, optionIds: selected, choices: question.options.filter(option => selected.includes(option.id)).map(option => option.label ), }; let item: Question.Item = { id: question.id, header: question.header, question: question.prompt, multiple: question.multiple, options: question.options.map(option => ({ id: option.id, label: option.label, description: option.description ?? "", })), }; let custom = selected.length === 0 && question.answer ? question.answer : undefined; let owner = meta.owner ?? value.by; let at = meta.decidedAt ?? (value.at ? Date.parse(value.at) / 1_000 : undefined); let handles = owner ? [owner, ...meta.involved.filter(handle => handle !== owner)].slice(0, 8) : meta.involved.slice(0, 8); return ( <>

{question.prompt}

{actions ?? (owner && )}
{custom &&

{custom}

} {at !== undefined && Number.isFinite(at) && (

)} {full && owner && (
{discussionLine(owner, meta.involved)}
)} ); } export function DecisionDialogContent( { closeRef, confirming = false, editable, error, meta, onClose, onDiscard, onKeep, onReopen, onSource, pending, value, }: { closeRef?: Ref; confirming?: boolean; editable: boolean; error?: string; meta: Question.CardMeta; onClose: () => void; onDiscard: () => void; onKeep: () => void; onReopen: () => void; onSource?: () => void; pending?: "discard" | "reopen"; value: Questionnaire; }, ) { return ( <> {meta.thread && onSource && ( )} } full meta={meta} value={value} /> {error &&

{error}

} {pending && (

{pending === "discard" ? "Discarding…" : "Reopening…"}

)} ); }