// Field-level "?" reference dialogs. Sibling to why-panels.js: why-panels are always-visible // section prose ("why this works"); this is an on-demand, per-field reference library ("what are // my options"). See FIELD_HELP_SPEC.md (deleted after implementation) for the design rationale. import { HELP_TOPICS } from "./field-help-content.js"; export function initFieldHelp({ getPlan }) { const dialog = document.getElementById("field-help-dialog"); if (!dialog) return; const titleEl = document.getElementById("help-dialog-title"); const bodyEl = document.getElementById("help-dialog-body"); let lastTrigger = null; function openTopic(key, trigger) { const topic = HELP_TOPICS[key]; if (!topic) return; lastTrigger = trigger; titleEl.textContent = topic.title; bodyEl.replaceChildren(topic.render(getPlan())); bodyEl.scrollTop = 0; dialog.showModal(); } function makeButton(key, title) { const btn = document.createElement("button"); btn.type = "button"; btn.className = "help-btn"; btn.dataset.helpTopic = key; btn.setAttribute("aria-label", `Field guide: ${title.split(" — ")[0]}`); btn.setAttribute("aria-haspopup", "dialog"); btn.textContent = "?"; // Several triggers live inside