import os
from PIL import Image

def generate_icons():
    source_path = "src/assets/app_icon.png"
    iconset_dir = "src-tauri/icons.iconset"
    icons_dir = "src-tauri/icons"
    
    if not os.path.exists(iconset_dir):
        os.makedirs(iconset_dir)
        
    if not os.path.exists(icons_dir):
        os.makedirs(icons_dir)

    img = Image.open(source_path).convert("RGBA")

    # (Name, Size)
    iconset_sizes = [
        ("icon_16x16.png", 16),
        ("icon_16x16@2x.png", 32),
        ("icon_32x32.png", 32),
        ("icon_32x32@2x.png", 64),
        ("icon_128x128.png", 128),
        ("icon_128x128@2x.png", 256),
        ("icon_256x256.png", 256),
        ("icon_256x256@2x.png", 512),
        ("icon_512x512.png", 512),
        ("icon_512x512@2x.png", 1024)
    ]

    for name, size in iconset_sizes:
        resized = img.resize((size, size), Image.Resampling.LANCZOS)
        resized.save(os.path.join(iconset_dir, name))
        print(f"Generated {name}")

    # Explicit Tauri icons
    tauri_icons = [
        ("32x32.png", 32),
        ("128x128.png", 128),
        ("128x128@2x.png", 256),
        ("icon.png", 512)
    ]

    for name, size in tauri_icons:
        resized = img.resize((size, size), Image.Resampling.LANCZOS)
        resized.save(os.path.join(icons_dir, name))
        print(f"Generated {name}")

if __name__ == "__main__":
    generate_icons()
