"""Collaborators widget rendering.""" from ..models import CollaboratorData from ..themes import THEMES from ..utils import escape, card_wrapper def render_collaborators_widget(collabs: list[CollaboratorData], theme_name: str = "dark") -> str: """Renders the top collaborators widget with avatars and contribution bars.""" t = THEMES[theme_name] items = "" for i, c in enumerate(collabs[:4]): y = i * 50 avatar_el = "" if c.avatar_b64: avatar_el = f'''''' else: hue = hash(c.username) % 360 avatar_el = f''' {escape(c.username[0].upper())}''' bar_max = max((x.shared_commits for x in collabs[:4]), default=1) or 1 bar_w = c.shared_commits / bar_max * 120 items += f''' {avatar_el} {escape(c.username)} {c.shared_repos} repos ยท {c.shared_commits} commits ''' total_h = len(collabs[:4]) * 50 + 48 return card_wrapper(items, 380, total_h, t, "Top Collaborators")