import { useState } from "react";
import { editComment } from "~/fns/issues";
import { useAction } from "~/hooks/use-action";
import { useViewer } from "~/hooks/use-viewer";
import { ReactionBar } from "./ReactionBar";
import { MarkdownEditor } from "./MarkdownEditor";
import { Avatar } from "~/ui/Avatar";
import { Badge } from "~/ui/Badge";
import { Markdown } from "~/ui/Markdown";
import { RelativeTime } from "~/ui/RelativeTime";
import { Button } from "~/ui/Button";
import type { getIssue } from "~/fns/issues";
import type { JsonValue } from "~/lib/types";
import { pullEventText } from "~/lib/pull-event-text";
import { TextLink } from "~/ui/TextLink";
import { ReportLink } from "./ReportLink";
type TimelineItem = Awaited<ReturnType<typeof getIssue>>["timeline"][number];
const REVIEW_COPY: Record<string, { label: string; tone: "success" | "danger" | "neutral" }> = {
approved: { label: "approved these changes", tone: "success" },
changes_requested: { label: "requested changes", tone: "danger" },
commented: { label: "reviewed", tone: "neutral" },
dismissed: { label: "review dismissed", tone: "neutral" },
};
function list(value: JsonValue | undefined): string {
return Array.isArray(value) ? value.map(String).join(", ") : typeof value === "string" ? value : "";
}
function eventText(kind: string, data: { [key: string]: JsonValue }): string {
switch (kind) {
case "closed":
return data.commit ? `closed this in ${String(data.commit).slice(0, 7)}` : "closed this";
case "reopened":
return "reopened this";
case "renamed":
return `changed the title from “${list(data.from)}” to “${list(data.to)}”`;
case "labeled":
return `set labels: ${list(data.labels) || "none"}`;