#!/usr/bin/env python3
"""Create Roomfit Studio app icon: base RF logo + 'STUDIO' text below."""
from PIL import Image, ImageDraw, ImageFont
from pathlib import Path

SRC = Path("/Volumes/WorkSSD/Projects/Wespion/roomfit-soft/app-mjolnir/lib/public/assets/images/app_icon.png")
DST_1024 = Path(__file__).parent / "app_icon_studio_1024.png"
DST_512 = Path(__file__).parent / "app_icon_studio_512.png"

base = Image.open(SRC).convert("RGBA")
assert base.size == (1024, 1024), base.size
W, H = base.size

# Shrink the RF logo slightly to make room for STUDIO text
SCALE = 0.8
small = base.resize((int(W * SCALE), int(H * SCALE)), Image.LANCZOS)
canvas = Image.new("RGBA", (W, H), (255, 255, 255, 255))
# Find if original has transparent bg — if not, use white canvas and composite
# Paste logo centered but shifted up
offset_y = -int(H * 0.05)
x = (W - small.width) // 2
y = (H - small.height) // 2 + offset_y
canvas.paste(small, (x, y), small)

draw = ImageDraw.Draw(canvas)

# Find system font
font_paths = [
    "/System/Library/Fonts/HelveticaNeue.ttc",
    "/System/Library/Fonts/Helvetica.ttc",
    "/System/Library/Fonts/Avenir Next.ttc",
    "/System/Library/Fonts/SFNS.ttf",
]
font = None
for p in font_paths:
    try:
        font = ImageFont.truetype(p, size=150, index=0)
        break
    except (OSError, IOError):
        continue
if font is None:
    font = ImageFont.load_default()

text = "STUDIO"
bbox = draw.textbbox((0, 0), text, font=font)
tw, th = bbox[2] - bbox[0], bbox[3] - bbox[1]
tx = (W - tw) // 2 - bbox[0]
ty = int(H * 0.74) - bbox[1]
# Use the R/F indigo color for STUDIO text (approximate Roomfit brand)
draw.text((tx, ty), text, fill=(74, 78, 255, 255), font=font)

canvas.save(DST_1024, "PNG")
canvas.resize((512, 512), Image.LANCZOS).save(DST_512, "PNG")
print(f"Saved: {DST_1024}")
print(f"Saved: {DST_512}")
