"use client"; import { useRef, useState, type CSSProperties, type ReactNode } from "react"; import "./message-actions.css"; /** * Message Actions * The row sits at 55% until the message is hovered or focused. Each action * answers in its own way — nothing shares a generic "success" flash: * copy → the glyph morphs into a check for 1.4s * retry → turns once; a ‹ 2 / 3 › switcher appears for the versions * up → fills and pops * down → a single-line "what went wrong?" row folds open, then thanks you */ type Props = { versions: ReactNode[]; theme?: "paper" | "night"; className?: string }; const REASONS = ["Not accurate", "Too long", "Missed the point", "Unsafe"]; export function MessageActions({ versions, theme = "paper", className = "" }: Props) { const [v, setV] = useState(0); const [count, setCount] = useState(1); const [copied, setCopied] = useState(false); const [spin, setSpin] = useState(0); const [vote, setVote] = useState<"up" | "down" | null>(null); const [asking, setAsking] = useState(false); const [thanks, setThanks] = useState(false); const [shared, setShared] = useState(false); const body = useRef(null); const copy = async () => { try { await navigator.clipboard?.writeText(body.current?.innerText ?? ""); } catch { /* clipboard can be blocked in iframes — the confirmation still shows */ } setCopied(true); setTimeout(() => setCopied(false), 1400); }; const retry = () => { setSpin((s) => s + 1); const n = Math.min(versions.length, count + 1); setCount(n); setV(n - 1); }; const up = () => { setVote(vote === "up" ? null : "up"); setAsking(false); }; const down = () => { if (vote === "down") { setVote(null); setAsking(false); return; } setVote("down"); setAsking(true); setThanks(false); }; const reason = () => { setAsking(false); setThanks(true); setTimeout(() => setThanks(false), 2200); }; const share = () => { setShared(true); setTimeout(() => setShared(false), 1600); }; return (
{versions[v]}
{count > 1 && ( {v + 1} / {count} )}
{thanks ? (

Thanks — that helps the next answer.

) : (

What went wrong? {REASONS.map((r, i) => ( ))}

)}

{copied ? "Copied to clipboard" : shared ? "Link copied" : thanks ? "Feedback sent" : ""}

); }