/** 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}
{custom}
} {at !== undefined && Number.isFinite(at) && ({decidedOn(at)}
)} {full && owner && ({error}
} {pending && ({pending === "discard" ? "Discarding…" : "Reopening…"}
)} > ); }