import { renderHouseOfRcSendStatus } from "./houseofrc_view.js";
import { PROLOGUE_OPTIONS_SEC, formatPrologueOption } from "./prologue_logic.js";
import { groupSessionsBySteps } from "./race_list_logic.js";
// Done steps are folded; one the operator opened stays open across re-renders (this page only).
const openSessionGroups = new Set();
export const isSessionGroupOpen = (eventId, stepId) => openSessionGroups.has(`${eventId}:${stepId}`);
// A ⋯ menu closes when anything outside it is clicked.
if (typeof document !== "undefined") {
document.addEventListener("click", (event) => {
document.querySelectorAll("details.row-menu[open]").forEach((menu) => { if (!menu.contains(event.target)) menu.open = false; });
});
}
export function setSessionGroupOpen(eventId, stepId, open) {
if (open) openSessionGroups.add(`${eventId}:${stepId}`);
else openSessionGroups.delete(`${eventId}:${stepId}`);
}
function formatDateTimeLocalValue(ms) {
const date = new Date(ms);
date.setSeconds(0, 0);
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
return date.toISOString().slice(0, 16);
}
function formatClockTime(ms) {
return new Date(ms).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", hour12: false });
}
export function renderEventManagerMarkup(context) {
const {
event,
t,
escapeHtml,
sessions,
eventSchedule,
dayPlan = null,
sessionTypeChoices,
sessionTypeHintKey,
raceTeams,
getSessionEntrants,
getSessionTypeLabel,
getStartModeLabel,
getStatusLabel,
normalizeStartMode,
branding,
driverOptions,
carOptions,
manageStatuses,
renderManageStatusBadgeView,
selectedParticipantCount,
raceDrivers,
participantChoices = raceDrivers,
otherClassChoices = [],
teamDriverPool,
showTeamsSection,
parseQualifyingHeatName,
state,
getDriverDisplayById,
raceFormatAdvanced,
racePresets,
selectedPreset,
isEndurancePreset,
showBasicQualifyingFields = true,
showBasicFinalFields = true,
renderRaceFormatContextCardView,
renderRaceFormatFieldView,
raceSummaryWarnings,
raceSummaryItems,
selectedGridSession,
renderGridEditor,
renderRaceStandingsTableView,
buildPracticeStandings,
buildQualifyingStandings,
buildFinalStandings,
renderTeamRaceStandings,
renderSessionChannelAnalysis,
renderFinalMatrix,
editingTeam,
editingSession,
getModeLabel,
renderTable,
} = context;
// Checking a driver/car here moves them off whichever other team already has them (see
// reassignTeamMembers in event_race_logic.js) - name that team here so the admin sees
// the move coming rather than discovering it after saving.
const driverTeamElsewhere = (driverId, excludeTeamId = "") =>
raceTeams.find((team) => team.id !== excludeTeamId && team.driverIds.includes(driverId))?.name || "";
const carTeamElsewhere = (carId, excludeTeamId = "") =>
raceTeams.find((team) => team.id !== excludeTeamId && team.carIds.includes(carId))?.name || "";
// Same idea as driverTeamElsewhere above, but for qualifying heats: checking a driver
// onto this heat moves them out of whichever other heat in the SAME round they're
// currently on (see moveDriversIntoQualifyingHeat) - name that heat so the admin sees the
// move coming before saving, not after.
const driverHeatElsewhere = (driverId, targetSession) => {
const targetParsed = parseQualifyingHeatName(targetSession?.name);
if (!targetParsed) return "";
const other = sessions.find((session) =>
session.id !== targetSession.id
&& session.type === "qualification"
&& (session.driverIds || []).includes(driverId)
&& parseQualifyingHeatName(session.name)?.round === targetParsed.round
);
return other?.name || "";
};
const sessionChannelMarkup = sessions
.map((session) => ({ session, markup: renderSessionChannelAnalysis(session) }))
.filter((entry) => entry.markup)
.map(({ session, markup }) => `
${escapeHtml(session.name)} • ${escapeHtml(getSessionTypeLabel(session.type))}
${markup}
${t("events.manage_step_setup_hint")}
${t("events.manage_step_format_hint")}
${t("events.manage_step_generate_hint")}
${t("events.manage_step_live_hint")}
${t("events.participants_sync_hint")}
`; })()}${t("events.race_format_intro")}
${t("events.race_actions_hint")}
${t("events.race_package_hint")}
${t("timing.channel_analysis_race_hint")}
${sessionChannelMarkup}${t("events.schedule_hint")}${dayPlan ? ` ${t("events.schedule_day_link")}` : ""}
${eventSchedule && eventSchedule.length ? renderTable( [t("table.session"), t("table.type"), t("events.schedule_planned"), t("events.schedule_actual"), ""], eventSchedule.map((row) => { const session = sessions.find((item) => item.id === row.sessionId); if (!session) return ""; return `${t("events.schedule_not_set")}
`}${t("events.seed_best_laps_hint")}
${t("events.free_practice_note")}
${t("events.open_practice_note")}
${t("events.branding_note")}