// Everything known about one school: catalog agreements, all research sections with sources,
// money breakdown for your stay, your notes, and your pick history for it.
import { html, bar, extLink, ICONS } from '../ui.js';
import {
shortName, fullName, place, languageFit, subjectFit, monthlyGrant, netCost, money, moneyRange, LANG_NAMES,
} from '../metrics.js';
const CONF_LABEL = { high: 'high confidence', medium: 'medium confidence', low: 'low confidence' };
const conf = (c) => (c ? html`${CONF_LABEL[c]} ` : '');
const para = (t) => (t ? html`
${t}
` : '');
const list = (items, cls = '') => (items?.length ? html`${items.map((i) => html`${i} `)} ` : '');
function scored(label, node, tone = '') {
if (!node) return '';
return html`${label} ${bar(node.score, tone)}
${para(node.text)}
`;
}
function section(title, body, confidence) {
return html`${title} ${conf(confidence)} ${body} `;
}
function agreementsBlock(s, app) {
return html`
${s.agreements.map((a) => html`
${a.scope === 'FEL' ? 'FEL agreement' : 'CTU-wide'}
${a.places == null ? '?' : a.places >= 99 ? 'open' : a.places} place${a.places === 1 ? '' : 's'} ·
levels ${a.levels.join(' ')}
${a.isced.length ? a.iscedLabels.map((l, i) => `${a.isced[i]} ${l}`).join(' · ') : 'Any subject area'}
${a.languages.length
? a.languages.map((l) => html`${LANG_NAMES[l.lang] ?? l.lang} ${l.level} `)
: html`No language listed `}
${a.factsheet ? html`${extLink(a.factsheet, 'CTU factsheet (CTU login)')}
` : ''}
`)}
Subject fit: ${subjectFit(s).text} ·
Language: ${languageFit(s, app.settings.languages).text}
`;
}
function moneyBlock(s, app) {
const r = s.research;
const g = monthlyGrant(s, app.settings, app.data);
const n = netCost(s, app.settings, app.data);
const m = app.settings.stayMonths;
const country = app.data.countries?.[s.country];
const range = (x) => moneyRange(x, app.settings, app.data);
const liv = r?.living;
return html`
Money from CTU ${money(g.eur, app.settings, app.data)} /month · ${s.funding?.label}
${s.funding?.note}
${r?.fees?.hostFunding?.monthlyEUR ? html`Host scholarship ${money(r.fees.hostFunding.monthlyEUR, app.settings, app.data)}/month (not guaranteed)
${r.fees.hostFunding.text}
` : ''}
${liv ? html`
Living /month ${range(liv.totalEUR)}
rent ${range(liv.rentEUR)} · food ${range(liv.foodEUR)} · transport ${range(liv.transportEUR)} · other ${range(liv.otherEUR)}
Housing ${liv.housing} ` : ''}
${r?.fees ? html`Mandatory fees ${r.fees.mandatoryEUR != null ? money(r.fees.mandatoryEUR, app.settings, app.data) : '?'} per semester
${r.fees.text}
` : ''}
${r?.travel ? html`Getting there ${r.travel.duration} · ${range(r.travel.roundTripEUR)} round trip
${r.travel.text}
` : ''}
${country?.visa ? html`Visa ${country.visa.required ? `${country.visa.type || 'Required'} · ${country.visa.costEUR != null ? money(country.visa.costEUR, app.settings, app.data) : 'cost unknown'}` : 'Not needed'}
${country.visa.text}
` : ''}
${n ? html`Out of pocket (${m} months) ${range([n.lo, n.hi])}
living ${range(n.parts.living)} + travel ${range(n.parts.travel)} + visa ${money(n.parts.visa, app.settings, app.data)}
+ fees ${money(n.parts.fees, app.settings, app.data)} − money received ${money(n.parts.grant, app.settings, app.data)}
` : ''}
${liv ? para(liv.text) : ''}`;
}
function safetyBlock(s, app) {
const r = s.research;
const c = app.data.countries?.[s.country];
return html`
${r ? scored('City safety', { score: r.safety.score, text: r.safety.text }) : ''}
${r ? html`Hazards: ${r.safety.hazards}
` : ''}
${c ? html`
${scored('Country stability', { score: c.stabilityScore, text: c.text })}
World Bank political stability: ${c.wgiPoliticalStability?.percentile ?? '?'}th percentile (${c.wgiPoliticalStability?.year}) ·
Global Peace Index #${c.gpi?.rank ?? '?'} (${c.gpi?.year})
Czech MFA: ${c.mfaAdvisory?.level} ${c.mfaAdvisory?.text}
Health insurance: ${c.health?.text}
` : ''}`;
}
export function render(root, app, slug) {
const s = app.bySlug.get(slug);
if (!s) {
root.innerHTML = String(html``);
return;
}
const r = s.research;
const st = app.state.stats.get(s.code);
const rank = app.rankOf(s.code);
const note = app.notes[s.code]?.text ?? '';
const history = [...st.history].reverse().slice(0, 30);
root.innerHTML = String(html`
${ICONS.back} Back
${s.flag}
${fullName(s)}
${shortName(s) !== fullName(s) ? `${shortName(s)} · ` : ''}${place(s)} · ${s.code}
${Math.round(st.rating)} Elo ${rank && st.games ? `· #${rank}` : ''} · ${st.games} games (${st.wins}W ${st.losses}L ${st.draws}D)
${st.dropped ? html`dropped ` : ''}
${st.dropped
? html`Restore to the race `
: html`Compare it now
Drop `}
${s.web ? extLink(s.web, 'Website') : ''} ${s.qs ? extLink(s.qs, 'QS') : ''}
${extLink(`https://www.openstreetmap.org/?mlat=${s.lat}&mlon=${s.lon}#map=12/${s.lat}/${s.lon}`, 'Map')}
${r ? html`
${r.summary}
${list(r.highlights, 'hl-list')}${list(r.watchouts, 'wo-list')}
` : html`
Research for this school is still pending. You can still compare it using the catalog data.
`}
${section('Agreements', agreementsBlock(s, app))}
${r ? html`
${section('AI & robotics', html`
${scored('Research', r.aiRobotics.academic)}
${scored('Hands-on', r.aiRobotics.practical)}
${scored('Course access for you', r.aiRobotics.access)}
${Object.entries(r.aiRobotics.rankings).filter(([, v]) => v).map(([k, v]) => html`${({ qsWorld: 'QS', qsCS: 'QS CS', csrankings: 'CSRankings', other: '' })[k]} ${v} `)}
${r.aiRobotics.labs.length ? html`Labs & groups ${list(r.aiRobotics.labs)}` : ''}
${r.aiRobotics.courses.length ? html`Relevant English courses ${list(r.aiRobotics.courses)}` : ''}
${r.aiRobotics.teams.length ? html`Student teams ${list(r.aiRobotics.teams)}` : ''}`, r.confidence.aiRobotics)}
${section('Money', moneyBlock(s, app), r.confidence.living)}
${section('Language', html`
Teaching ${r.language.teaching}
Proof needed ${r.language.proof}
Local language in daily life ${bar(r.language.localNeed)} (10 = essential)
${para(r.language.text)}`, r.confidence.language)}
${section('Social life & solitude', html`
${scored('Social', r.social)}
${r.social.esn ? html`ESN/buddy: ${r.social.esn}` : ''}${r.social.internationals ? html` · Internationals: ${r.social.internationals}` : ''}
${scored('Calm & solitude', r.solitude)}`, r.confidence.social)}
${section('Nature', html`
${scored('Climbing', r.nature.climbing)}
${scored('Hiking', r.nature.hiking)}
${scored('Ocean', r.nature.ocean)}
${scored('Skiing', r.nature.skiing)}
Climate (Sep–Feb): ${r.nature.climate}
`, r.confidence.nature)}
` : ''}
${section('Safety & stability', safetyBlock(s, app), r?.confidence?.safety)}
${r ? html`
${section('Calendar & application', html`
Term ${r.calendar.term}
Fit with CTU winter ${r.calendar.fit} · full year: ${r.calendar.fullYear}
Host deadline ${r.application.nominationDeadline ?? 'unknown'}
${para(r.calendar.text)}${para(r.application.text)}`, r.confidence.calendar)}
${section('Sources', html`
${r.sources.map((src) => html`${extLink(src.url, src.label)} `)}
Researched ${r.researchedAt} · overall ${CONF_LABEL[r.confidence.overall]}. Check money and language rules officially before applying.
`)}
` : ''}
${section('My notes', html`
${note ? 'Saved' : 'Saved automatically'}
`)}
${history.length ? section('My picks', html`
${history.map((m) => {
const meA = m.a === s.code;
const other = app.byCode.get(meA ? m.b : m.a);
const delta = meA ? m.da : m.db;
const outcome = m.r === 'draw' ? 'tied with' : (m.r === 'a') === meA ? 'beat' : 'lost to';
return html`${delta >= 0 ? '+' : ''}${Math.round(delta)} ${outcome} ${shortName(other)} `;
})} `) : ''}
`);
root.onclick = (e) => {
const t = e.target.closest('[data-action]');
if (!t) return;
const action = t.dataset.action;
if (action === 'back') app.back();
else if (action === 'drop') app.drop(s.code);
else if (action === 'restore') app.restore(s.code);
else if (action === 'duel') app.duelWith(s.code);
};
const textarea = root.querySelector('textarea[name="note"]');
const status = root.querySelector('[data-note-status]');
let timer;
const save = () => {
clearTimeout(timer);
if (textarea.value === (app.notes[s.code]?.text ?? '')) return;
status.textContent = 'Saving…';
app.saveNote(s.code, textarea.value)
.then(() => { status.textContent = 'Saved'; })
.catch(() => { status.textContent = 'Not saved: offline? It will retry when you leave the field.'; });
};
textarea.addEventListener('input', () => { status.textContent = 'Editing…'; clearTimeout(timer); timer = setTimeout(save, 1200); });
textarea.addEventListener('blur', save);
}