export function initSkills () { const panel = document.getElementById("skills-panel"); const list = document.getElementById("skills-list"); let current = []; document.getElementById("skills-toggle").addEventListener("click", () => { panel.hidden = !panel.hidden; }); function render (skills) { current = skills ?? []; list.replaceChildren(); for (const skill of current) { list.append(renderSkillRow(skill)); } } return { render, skillLevel (skillId) { return current.find((entry) => entry.skillId === skillId)?.level ?? 1; }, hide () { panel.hidden = true; } }; } function renderSkillRow (skill) { const row = document.createElement("div"); row.className = "skill-row"; const icon = document.createElement("img"); icon.className = "skill-icon"; icon.src = skill.icon; icon.alt = ""; icon.loading = "lazy"; const body = document.createElement("div"); body.className = "skill-body"; const title = document.createElement("div"); title.className = "skill-title"; title.textContent = `${skill.displayName} — Level ${skill.level}`; const track = document.createElement("div"); track.className = "skill-xp-track"; const fill = document.createElement("div"); fill.className = "skill-xp-fill"; const pct = skill.xpToNext > 0 ? Math.min(100, (skill.xp / skill.xpToNext) * 100) : 100; fill.style.width = `${pct}%`; track.title = `${skill.xp} / ${skill.xpToNext} XP to next level`; track.append(fill); body.append(title, track); row.append(icon, body); return row; }