/** Pure toast state — testable without a DOM. */ export interface Toast { id: number; tone: 'ok' | 'err'; message: string } export interface ToastState { nextId: number; toasts: Toast[] } export const TOAST_LIMIT = 3 export const initialToasts: ToastState = { nextId: 1, toasts: [] } export function pushToast(s: ToastState, tone: Toast['tone'], message: string): ToastState { const toast: Toast = { id: s.nextId, tone, message } const toasts = [...s.toasts, toast].slice(-TOAST_LIMIT) return { nextId: s.nextId + 1, toasts } } export function dismissToast(s: ToastState, id: number): ToastState { return { ...s, toasts: s.toasts.filter((t) => t.id !== id) } }