"""Achievements widget rendering.""" from ..models import AchievementData from ..themes import THEMES from ..utils import escape, card_wrapper def _achievement_icon_svg(icon_type: str, color: str) -> str: """Returns SVG for achievement icons (24x24).""" icons = { "trophy": f''' ''', "medal": f''' ''', "star": f''' ''', "hackathon": f''' ''', } return icons.get(icon_type, icons["trophy"]) def render_achievements_widget( achievements: list[AchievementData], theme_name: str = "dark", max_items: int = 5, settings: dict | None = None, ) -> str: """Renders the achievements widget with icons and descriptions. Settings: max_items (int): Max achievements to show (default 5) """ t = THEMES[theme_name] s = settings or {} max_items = min(max(int(s.get("max_items", max_items)), 1), 10) items = "" accent_colors = [t["orange"], t["green"], t["accent"], t["purple"], t["pink"]] shown = achievements[:max_items] if not shown: return "" for i, ach in enumerate(shown): y = i * 56 color = accent_colors[i % len(accent_colors)] icon_svg = _achievement_icon_svg(ach.icon, color) items += f''' {icon_svg} {escape(ach.title)} {escape(ach.subtitle)}{(" ยท " + ach.event_date) if ach.event_date else ""} ''' total_h = len(shown) * 56 + 50 return card_wrapper(items, 380, total_h, t, "Achievements")