import { PROLOGUE_OPTIONS_SEC, formatPrologueOption } from "./prologue_logic.js";
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,
sessionTypeChoices,
sessionTypeHintKey,
raceTeams,
getSessionEntrants,
getSessionTypeLabel,
getStartModeLabel,
getStatusLabel,
normalizeStartMode,
branding,
driverOptions,
carOptions,
manageStatuses,
renderManageStatusBadgeView,
selectedParticipantCount,
raceDrivers,
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 }) => `
${t("events.seed_best_laps_hint")} ${t("events.free_practice_note")} ${t("events.open_practice_note")} ${t("events.branding_note")}
${t("events.tp_rule")}
${t("events.manage_step_setup_hint")} ${t("events.manage_step_format_hint")} ${t("events.manage_step_generate_hint")} ${t("events.manage_step_live_hint")}${escapeHtml(session.name)} • ${escapeHtml(getSessionTypeLabel(session.type))}
${markup}
${t("events.manage_title")}: ${escapeHtml(event.name)}
`;
})
)}
${escapeHtml(s.name)}
${escapeHtml(getSessionTypeLabel(s.type))}
${s.type === "open_practice" ? t("events.open_practice_untimed") : `${s.durationMin} min`}
${escapeHtml(getStartModeLabel(s.startMode))}
${s.seedBestLapCount > 0 ? `${s.seedBestLapCount}` : "-"}
${escapeHtml(getStatusLabel(s.status))}
${assignCount || (event.mode === "track" ? t("events.na") : "-")}
${
event.mode === "race" && normalizeStartMode(s.startMode) === "position"
? ``
: ""
}
${
event.mode === "race" && ["qualification", "final"].includes(s.type)
? `
`
: ""
}
${t("events.branding")}
${t("events.sponsor_tools")}
${t("events.assign_title")}
${t("events.team_race_intro")}
${t("events.team_steps")}
${t("events.team_hint")}
${t("events.team_form_drivers")}
${t("events.team_driver_fallback")}
${t("common.no_entries")}
` }${t("events.team_form_cars")}
${t("common.no_entries")}
` }${t("events.no_teams")}
` }${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")}
${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")}
`}