#!/usr/bin/env python3
"""Generate Hevy Companion app icon for Fitbit Sense 2."""

from PIL import Image, ImageDraw
import math

# Colors
BG = (10, 10, 26)       # #0a0a1a
ACCENT = (78, 205, 196)  # #4ecdc4

def draw_dumbbell(draw, cx, cy, size, color):
    """Draw a minimal geometric dumbbell centered at (cx, cy)."""
    # Proportions relative to icon size
    bar_height = size * 0.06          # thin bar
    bar_width = size * 0.40           # length of handle
    plate_width = size * 0.08         # thickness of each weight plate
    plate_height = size * 0.18        # height of each weight plate
    plate_gap = size * 0.04           # gap between plate and end of bar
    
    bar_left = cx - bar_width / 2
    bar_right = cx + bar_width / 2
    bar_top = cy - bar_height / 2
    bar_bottom = cy + bar_height / 2
    
    # Draw handle bar
    draw.rectangle(
        [bar_left, bar_top, bar_right, bar_bottom],
        fill=color
    )
    
    # Left weight plates (two rectangles stacked with slight gap)
    left_outer = bar_left - plate_gap - plate_width
    left_inner = bar_left - plate_gap
    
    # Outer plate (left)
    draw.rounded_rectangle(
        [left_outer, cy - plate_height / 2,
         left_inner, cy + plate_height / 2],
        radius=size * 0.012,
        fill=color
    )
    
    # Right weight plates
    right_inner = bar_right + plate_gap
    right_outer = bar_right + plate_gap + plate_width
    
    draw.rounded_rectangle(
        [right_inner, cy - plate_height / 2,
         right_outer, cy + plate_height / 2],
        radius=size * 0.012,
        fill=color
    )
    
    # Inner collars (small rectangles near bar ends)
    collar_width = size * 0.015
    collar_height = size * 0.22
    
    # Left collar
    lc_left = bar_left - plate_gap * 0.5 - collar_width
    lc_right = bar_left - plate_gap * 0.5
    draw.rounded_rectangle(
        [lc_left, cy - collar_height / 2,
         lc_right, cy + collar_height / 2],
        radius=size * 0.005,
        fill=color
    )
    
    # Right collar
    rc_left = bar_right + plate_gap * 0.5
    rc_right = bar_right + plate_gap * 0.5 + collar_width
    draw.rounded_rectangle(
        [rc_left, cy - collar_height / 2,
         rc_right, cy + collar_height / 2],
        radius=size * 0.005,
        fill=color
    )

def create_icon(size):
    """Create a Hevy Companion icon at the given size."""
    img = Image.new('RGB', (size, size), BG)
    draw = ImageDraw.Draw(img)
    
    cx, cy = size / 2, size / 2
    draw_dumbbell(draw, cx, cy, size, ACCENT)
    
    return img

if __name__ == '__main__':
    # Generate at 160x160 (scales down well to 80x80)
    icon_160 = create_icon(160)
    icon_160.save('/tmp/hevy-icon-watch.png')
    
    # Also generate 80x80 version
    icon_80 = create_icon(80)
    icon_80.save('/tmp/hevy-icon-watch-80.png')
    
    print("Icons generated:")
    print("  /tmp/hevy-icon-watch.png (160x160)")
    print("  /tmp/hevy-icon-watch-80.png (80x80)")
