// "Track layout: Layout 3 - since 12 Sep [New layout]" strip, shared by Training stats, // Race Day and the Dashboard. Changing layout is a practice-only action, so callers hide // the button while the session in focus is a race-format one; addTrackLayout additionally // refuses while any race session is running. import { getTrackLayoutIdAt, getTrackLayoutLabel, nextTrackLayoutLabel, normalizeTrackLayouts } from "./track_layouts_logic.js"; export function renderTrackLayoutBar({ state, t, escapeHtml, showNewButton = true }) { const layouts = normalizeTrackLayouts(state.trackLayouts); const currentId = getTrackLayoutIdAt(layouts); const current = layouts.find((layout) => layout.id === currentId); const text = current ? t("layouts.bar_current", { label: getTrackLayoutLabel(layouts, currentId), date: new Date(current.startedAt).toLocaleDateString() }) : t("layouts.bar_none"); return `
${escapeHtml(text)} ${showNewButton ? `` : ""}
`; } export function bindTrackLayoutBar(root, { state, t, addTrackLayout, renderView }) { root?.querySelectorAll("[data-track-layout-new]").forEach((button) => { button.addEventListener("click", () => { const suggested = nextTrackLayoutLabel(normalizeTrackLayouts(state.trackLayouts)); const label = window.prompt(t("layouts.new_prompt"), suggested); if (label === null) return; // Optional: a rebuilt track often needs its own minimum lap time (empty = the event's). const minLapSec = Number(String(window.prompt(t("layouts.new_min_lap_prompt"), "") || "").replace(",", ".")); const result = addTrackLayout(label.trim() || suggested, Date.now(), { minLapMs: Number.isFinite(minLapSec) && minLapSec > 0 ? Math.round(minLapSec * 1000) : 0 }); if (!result.ok) { window.alert(result.message); return; } renderView(); }); }); }