"use client"; import { useEffect, useRef } from "react"; import { useI18n } from "@/lib/i18n/client"; export type DialogueHistoryItem = { id: string; sceneIndex: number; speaker?: string; body?: string; narration?: string; selectedChoice?: string; freeformAction?: string; }; export function DialogueHistoryModal({ items, portrait, onClose, playerName, }: { items: DialogueHistoryItem[]; portrait: boolean; onClose: () => void; playerName?: string; }) { const { t } = useI18n(); const displaySpeaker = (s: string | undefined) => s === "你" && playerName ? playerName : s; const listRef = useRef(null); useEffect(() => { const el = listRef.current; if (!el) return; el.scrollTop = el.scrollHeight; }, [items.length]); useEffect(() => { function onKeyDown(e: KeyboardEvent) { if (e.key === "Escape") onClose(); } window.addEventListener("keydown", onKeyDown); return () => window.removeEventListener("keydown", onKeyDown); }, [onClose]); return (
e.stopPropagation()} style={{ background: "rgba(14, 10, 6, 0.88)", border: "1.5px solid rgba(175, 138, 72, 0.72)", borderRadius: "6px", backdropFilter: "blur(14px)", WebkitBackdropFilter: "blur(14px)", boxShadow: "0 10px 42px rgba(0,0,0,0.62), inset 0 1px 0 rgba(200,165,90,0.12)", }} role="dialog" aria-modal="true" aria-label={t("history.ariaLabel")} >
{t("history.title")}
{items.length === 0 ? (

{t("history.noHistory")}

) : (
{items.map((item) => (
{t("history.scene", { n: String(item.sceneIndex).padStart(3, "0") })} {item.speaker && ( {displaySpeaker(item.speaker)} )}
{item.narration && (

{item.narration}

)} {item.body && (

{item.body}

)} {item.selectedChoice && (

{t("history.choice")} {item.selectedChoice}

)} {item.freeformAction && (

{t("history.action")} {item.freeformAction}

)}
))}
)}
); }