#!/usr/bin/env python3
from pathlib import Path
from PIL import Image,ImageDraw
import sys
root=Path(sys.argv[1]);side=sys.argv[2]
for width,theme in [(1440,'dark'),(1440,'light'),(390,'dark'),(390,'light')]:
 files=[p/'initial.png' for p in sorted(root.glob(f'{side}-*-{width}-{theme}')) if (p/'initial.png').exists()]
 if not files:continue
 tw=720 if width==1440 else 390
 th=450 if width==1440 else 844
 cols=3 if width==1440 else 4
 rows=(len(files)+cols-1)//cols
 out=Image.new('RGB',(cols*tw,rows*(th+30)),'#ddd');draw=ImageDraw.Draw(out)
 for i,p in enumerate(files):
  x=(i%cols)*tw;y=(i//cols)*(th+30)
  im=Image.open(p).convert('RGB');im.thumbnail((tw,th));out.paste(im,(x,y+30));draw.text((x+8,y+8),p.parent.name,fill='black')
 path=root/f'{side}-{width}-{theme}-review.png';out.save(path);print(path)
