// Данные примерные: их легко заменить на реальные (массив UNIVERSITIES).
const UNIVERSITIES = [
{ name: "КазНУ им. аль-Фараби", specialty: "Прикладная математика", city: "Алматы", min: 162, budget: 85, scholarship: 14500 },
{ name: "КазНУ им. аль-Фараби", specialty: "Высшая математика в финансах", city: "Алматы", min: 159, budget: 40, scholarship: 14500 },
{ name: "КазНУ им. аль-Фараби", specialty: "Математика и анализ данных", city: "Алматы", min: 156, budget: 55, scholarship: 14000 },
{ name: "Eurasian National University", specialty: "Высшая математика", city: "Астана", min: 152, budget: 35, scholarship: 13500 },
{ name: "Kazakh-British Technical University", specialty: "Высшая математика и моделирование", city: "Астана", min: 155, budget: 30, scholarship: 13500 },
{ name: "КазНТУ им. Т. Рысқұлова", specialty: "Высшая математика", city: "Алматы", min: 148, budget: 68, scholarship: 12500 },
{ name: "АУ «Сарыарка»", specialty: "Высшая математика", city: "Караганда", min: 138, budget: 25, scholarship: 10000 },
{ name: "ЮЗГУ", specialty: "Математика и статистика", city: "Костанай", min: 132, budget: 30, scholarship: 9500 },
];
const body = document.getElementById("uni-body");
const note = document.getElementById("uni-note");
function renderTable(rows) {
if (!body) return;
body.innerHTML = "";
for (const r of rows) {
const tr = document.createElement("tr");
tr.innerHTML =
'
' + r.name + " | " +
'' + r.specialty + " | " +
'' + r.city + " | " +
'' + r.min + " | " +
'' + r.budget + " | " +
'' + r.scholarship.toLocaleString("ru-RU") + " тг | ";
body.appendChild(tr);
}
note.textContent = rows.length
? "Показано вариантов: " + rows.length + "."
: "Ничего не нашлось — попробуй другой запрос или сбрось балл.";
}
function fmt(v) {
return v == null ? "" : String(v).trim().toLowerCase();
}
document.getElementById("btn-search")?.addEventListener("click", function () {
const q = fmt(document.getElementById("f-specialty").value);
const score = parseInt(document.getElementById("f-score").value, 10);
let rows = UNIVERSITIES.filter(function (u) {
const okQ = !q || u.specialty.toLowerCase().includes(q) || u.name.toLowerCase().includes(q);
const okScore = isNaN(score) || u.min <= score;
return okQ && okScore;
});
if (!isNaN(score)) rows = rows.slice().sort(function (a, b) { return a.min - b.min; });
renderTable(rows);
document.getElementById("search-note").hidden = true;
document.getElementById("universities").scrollIntoView({ behavior: "smooth" });
});
(function () {
const avg = Math.round(UNIVERSITIES.reduce(function (s, u) { return s + u.min; }, 0) / UNIVERSITIES.length);
const el = document.getElementById("prog-avg");
const num = document.getElementById("prog-avg-num");
if (el) el.style.width = Math.min(100, Math.round(avg / 2)) + "%";
if (num) num.textContent = avg;
})();
renderTable(UNIVERSITIES);