import { esc } from '../http.js';
import { layout, flash } from './layout.js';
export function homePage(list) {
const rows = list.length
? list.map(x => `${esc(phaseLabel(x.phase))} ${esc(x.name)} ${esc(x.date ?? '')} · ${x.teams} teams `).join('')
: `
No tournaments yet. An organizer creates one from the desk .
`;
return layout({ title: 'Tournaments', body: `Tournaments ${rows}
` });
}
export const phaseLabel = p => ({ checkin: 'Registration open', closed: 'Registration closed', live: 'Live', final: 'Final' }[p] ?? p);
/** Registration form, shown while phase = checkin. */
export function registerPage(state, { error = null, values = {} } = {}) {
const r = state.rules;
const body = `
${esc(state.date ?? '')}
${esc(state.name)}
${esc(r.teamSize)}s · ${esc(r.pointsTo)} points, win by ${esc(r.winBy)}${r.cap ? `, cap ${esc(r.cap)}` : ''} · ${state.teams.length} team${state.teams.length === 1 ? '' : 's'} registered
${state.notes ? `${esc(state.notes)}
` : ''}
${flash(error, 'error')}
Registered so far
${state.teams.length ? `${state.teams.map(t => `${esc(t.name)} (${t.players}) `).join('')} ` : 'Be the first.
'}
`;
return layout({ title: state.name, body });
}
export function registeredPage(state, team, origin) {
const link = `${origin}/t/${state.slug}/team/${team.code}`;
const body = `
You're in
${esc(team.name)} ${team.players} players · captain ${esc(team.captain ?? '')}
Your team link
This page will show your next match, which court, and your record. Bookmark it or add it to your home screen.
${esc(link)}
Copy link Text it to myself
Team code: ${esc(team.code)} . Anyone with the code can see your team page; nobody can change scores from it.
Back to the tournament
`;
return layout({ title: `${team.name} registered`, body });
}
/** Everything after check-in: closed, live and final are all rendered client-side from the state JSON. */
export function boardPage(state, { teamId = null, display = false } = {}) {
const body = `This page needs JavaScript to show live scores. Loading ${esc(state.name)}…
`;
return layout({ title: state.name, body, state, script: '/static/board.js', bodyClass: display ? 'display' : '' });
}