"""Collaborators widget rendering.""" from ..models import CollaboratorData from ..themes import THEMES from ..utils import escape, card_wrapper, safe_color def render_collaborators_widget(collabs: list[CollaboratorData], theme_name: str = "dark", settings: dict | None = None) -> str: """Renders the top collaborators widget with avatars and contribution bars. Settings: max_count (int): Number of collaborators to show (default 5) bar_color (str): Hex color for the contribution bars (default theme purple) """ t = THEMES[theme_name] s = settings or {} max_count = min(max(int(s.get("max_count", 5)), 1), 10) bar_color = safe_color(s.get("bar_color"), t["purple"]) items = "" for i, c in enumerate(collabs[:max_count]): 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[:max_count]), 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[:max_count]) * 50 + 48 return card_wrapper(items, 380, total_h, t, "Top Collaborators")