// The main screen: two schools side by side, a comparison table, and pick buttons in thumb reach. import { html, bar } from '../ui.js'; import { COMPARE_ROWS, rowWinner, shortName, place } from '../metrics.js'; import { PROVISIONAL_GAMES } from '../elo.js'; function head(app, s, side) { const st = app.state.stats.get(s.code); const rank = app.rankOf(s.code); const provisional = st.games < PROVISIONAL_GAMES; return html` `; } function table(app, a, b) { let section = ''; const rows = []; for (const row of COMPARE_ROWS) { if (row.section !== section) { section = row.section; rows.push(html`
${section}
`); } const va = row.get(a, app.ctx); const vb = row.get(b, app.ctx); if (!va && !vb) continue; const win = rowWinner(row, va, vb); const cell = (v, side) => { if (!v) return html`
–
`; const content = v.bar != null ? bar(v.bar) : html`${v.text}`; return html`
${content}
`; }; rows.push(html`
${row.label}
${cell(va, 'a')}${cell(vb, 'b')}
`); } return html`
${rows}
`; } function flagsBlock(s, side) { const r = s.research; if (!r) return ''; const items = [ ...r.highlights.slice(0, 3).map((t) => html`
  • ${t}
  • `), ...r.watchouts.slice(0, 3).map((t) => html`
  • ${t}
  • `), ]; return html`

    ${side.toUpperCase()} ${shortName(s)}

    ${r.summary}

    `; } export function render(root, app) { const pair = app.currentPair(); if (!pair) { root.innerHTML = String(html`

    Not enough schools left

    You need at least two schools that aren't dropped. Restore some in the ranking.

    Open the ranking
    `); return; } const [a, b] = pair.map((c) => app.byCode.get(c)); const undoable = app.state.lastUndoable; root.innerHTML = String(html`

    Which would you rather go to?

    ${head(app, a, 'a')}${head(app, b, 'b')}
    ${table(app, a, b)}
    ${flagsBlock(a, 'a')}${flagsBlock(b, 'b')}
    ${app.state.matches.length} picks
    `); root.onclick = (e) => { const t = e.target.closest('[data-action]'); if (!t || t.disabled) return; const action = t.dataset.action; if (action === 'pick') app.pick(a.code, b.code, t.dataset.r); else if (action === 'skip') app.skip(); else if (action === 'undo') app.undo(); else if (action === 'drop') app.drop(t.dataset.code); else if (action === 'open') app.navigate(`#/school/${t.dataset.slug}`); }; } /** Desktop shortcuts: ←/→ pick, ↓ or = draw, space skip, z/backspace undo. */ export function onKey(e, app) { if (e.target.closest('input, textarea, select')) return false; const pair = app.currentPair(); if (!pair) return false; const map = { ArrowLeft: 'a', ArrowRight: 'b', ArrowDown: 'draw', '=': 'draw' }; if (map[e.key]) { app.pick(pair[0], pair[1], map[e.key]); return true; } if (e.key === ' ') { app.skip(); return true; } if (e.key === 'z' || e.key === 'Backspace') { app.undo(); return true; } return false; }