import { useCallback, useEffect, useMemo, useRef } from "react"; import { t } from "../i18n"; import { useShortcut, useViewport } from "../react/input"; import { Box, ScrollBox, type ScrollBoxRenderable } from "../ui"; import { useDialog, useDialogKeyboard, useDialogState, type AlertContext } from "../ui/dialog"; import { wrapTextLines } from "../utils/text-wrap"; import { usePaneFooter } from "./layout/pane/footer"; import { usePaneFooterScopeActive } from "./layout/pane/footer/registration"; import { Button } from "./ui/button"; import { DialogFrame } from "./ui/frame"; import { Prose } from "./ui/prose"; export interface UsePaneNoticeFooterOptions { registrationId: string; notices: readonly string[]; focused: boolean; title?: string; enabled?: boolean; } function NoticeDialog({ notices, title, dismiss, dialogId }: AlertContext & { notices: readonly string[]; title: string; }) { const viewport = useViewport(); const width = Math.max(8, Math.min(74, viewport.width - 8)); const contentHeight = notices.reduce((total, notice) => total + wrapTextLines(notice, Math.max(8, width - 1)).length, 0) + Math.max(0, notices.length - 1); const height = Math.max(1, Math.min(contentHeight, 18, viewport.height - 10)); const scrollRef = useRef(null); useDialogKeyboard((event) => { if (event.ctrl || event.alt || event.meta || event.super) return; const key = event.name ?? event.key; if (key === "enter" || key === "return" || key === "escape") { event.preventDefault(); event.stopPropagation(); dismiss(); return; } const scroll = scrollRef.current; if (!scroll) return; const delta = key === "down" ? 1 : key === "up" ? -1 : key === "pagedown" ? height : key === "pageup" ? -height : null; if (delta === null && key !== "home" && key !== "end") return; event.preventDefault(); event.stopPropagation(); scroll.scrollTo(key === "home" ? 0 : key === "end" ? scroll.scrollHeight : Math.max(0, scroll.scrollTop + (delta ?? 0))); }, { scope: dialogId }); return ( {notices.map((notice, index) => ( ))}