// Urgent telegrams: the game warns that a way of losing power is getting close. // They slide in over the desk and time stays stopped until the player acknowledges. import { t, tx } from "../i18n/i18n.js"; import { $, esc } from "./desk.js"; export function createTelegram(root, { alerts, onDismiss }) { root.addEventListener("click", (e) => { if (e.target.closest("button[data-dismiss]")) onDismiss(); }); let shown = ""; function update(state) { const alert = state.pending.alert && !state.over ? state.alerts[0] : null; const key = alert ? `${alert.kind}:${alert.day}` : ""; if (key === shown) return; shown = key; if (!alert) { root.hidden = true; root.innerHTML = ""; return; } const text = alerts[alert.kind]; root.innerHTML = `
${t("alert.urgent")} ${state.alerts.length > 1 ? `+${state.alerts.length - 1}` : ""}

${esc(tx(text.title))}

${esc(tx(text.body))}

`; root.hidden = false; $(root, "button").focus(); } return { update }; }