// frontend/js/render/dashboard-screen.js
import { state } from '../state.js';
import { drawExerciseProgress, drawBodyMetricsGraph } from './dashboard.js';
export function renderDashboard() {
const app = document.getElementById('app');
if (!app) return;
app.innerHTML = `
π Π‘ΡΠ°ΡΠΈΡΡΠΈΠΊΠ°
πͺ ΠΡΠΎΠ³ΡΠ΅ΡΡ ΡΠΏΡΠ°ΠΆΠ½Π΅Π½ΠΈΡ
ΠΠΎΠΊΠ°Π·Π°Π½Ρ ΠΌΠ°ΠΊΡ. Π²Π΅Ρ ΠΈ ΠΏΠΎΠ²ΡΠΎΡΠ΅Π½ΠΈΡ Π·Π° ΠΏΠΎΡΠ»Π΅Π΄Π½ΠΈΠ΅ 10 ΡΡΠ΅Π½ΠΈΡΠΎΠ²ΠΎΠΊ.
βοΈ ΠΠΈΠ½Π°ΠΌΠΈΠΊΠ° ΡΠ΅Π»Π°
`;
window.DashboardLogic = {
updateExerciseChart: () => {
const select = document.getElementById('dash-ex-select');
const canvas = document.getElementById('chart-exercise');
if (select.value) {
drawExerciseProgress(canvas, select.value);
} else {
const ctx = canvas.getContext('2d');
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.fillStyle='#666';
ctx.textAlign='center';
ctx.fillText('ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΡΠΏΡΠ°ΠΆΠ½Π΅Π½ΠΈΠ΅ Π²ΡΡΠ΅', canvas.width/2, canvas.height/2);
}
},
updateBodyChart: () => {
const clientSel = document.getElementById('dash-client-select');
const metricSel = document.getElementById('dash-metric-select');
const canvas = document.getElementById('chart-body');
const clientId = clientSel.value ? parseInt(clientSel.value) : null;
const metricId = metricSel.value ? parseInt(metricSel.value) : null;
if (metricId) {
drawBodyMetricsGraph(canvas, clientId, metricId);
}
}
};
// ΠΠ΅ΡΠ²ΠΈΡΠ½Π°Ρ ΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° (ΠΏΡΡΡΡΠ΅ ΡΠΎΡΡΠΎΡΠ½ΠΈΡ)
DashboardLogic.updateExerciseChart();
if(state.metricTypes.length > 0) {
document.getElementById('dash-metric-select').value = state.metricTypes[0].id;
DashboardLogic.updateBodyChart();
}
}
function getUniqueExercises() {
const set = new Set();
state.workouts.forEach(w => {
w.exercises.forEach(ex => {
set.add(ex.name);
});
});
return Array.from(set).sort();
}