#!/bin/bash
# Create Windows .ico file from PNG icons

set -e

cd "$(dirname "$0")/.."

# Check if we have the icon source
if [ ! -f "Assets/AppIcon.iconset/icon_256x256.png" ]; then
    echo "Error: icon_256x256.png not found"
    exit 1
fi

echo "Creating Windows .ico file..."

# Use Python with PIL if available, otherwise manual creation
if command -v python3 &> /dev/null; then
    python3 << 'EOF'
try:
    from PIL import Image
    import os

    # Create ico with multiple sizes
    img_256 = Image.open("Assets/AppIcon.iconset/icon_256x256.png")
    img_128 = Image.open("Assets/AppIcon.iconset/icon_128x128.png")
    img_64 = img_256.resize((64, 64), Image.Resampling.LANCZOS)
    img_48 = img_256.resize((48, 48), Image.Resampling.LANCZOS)
    img_32 = Image.open("Assets/AppIcon.iconset/icon_32x32.png")
    img_16 = Image.open("Assets/AppIcon.iconset/icon_16x16.png")
    
    img_256.save("Assets/AppIcon.ico", 
                 format='ICO',
                 sizes=[(16, 16), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)],
                 append_images=[img_16, img_32, img_48, img_64, img_128])
    
    print("✓ Created Assets/AppIcon.ico")
except ImportError:
    print("Warning: PIL/Pillow not available. Please install with: pip3 install Pillow")
    print("Or manually create AppIcon.ico and place it in Assets/ folder")
    exit(1)
EOF
else
    echo "Warning: Python3 not available. Cannot create .ico file."
    echo "Please manually create AppIcon.ico and place it in Assets/ folder"
    exit 1
fi

