#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""preview_album_korea.py — contact sheet 10 foto terpilih per album Korea (buat preview Bos)."""
import os
from PIL import Image, ImageDraw
import sys
sys.path.insert(0, "/home/mantapman/.hermes/profiles/atun/workspace")
from pasang_album_korea_uky import ALBUMS

IMG = "/home/mantapman/.hermes/profiles/atun/workspace/openclaw-img"
OUT = "/tmp/korea_album_preview"
os.makedirs(OUT, exist_ok=True)
cols, tw = 5, 420

for a in ALBUMS:
    files = a["files"]
    rows = (len(files) + cols - 1) // cols
    sheet = Image.new("RGB", (cols * tw, rows * (tw * 3 // 4 + 26)), "white")
    d = ImageDraw.Draw(sheet)
    for i, f in enumerate(files):
        im = Image.open(os.path.join(IMG, f)).convert("RGB")
        im.thumbnail((tw, tw * 3 // 4))
        x = (i % cols) * tw
        y = (i // cols) * (tw * 3 // 4 + 26)
        sheet.paste(im, (x, y))
        d.text((x + 6, y + tw * 3 // 4 + 6), f"{i+1}. {f}", fill="black")
    p = os.path.join(OUT, f"{a['tgl']}_{a['tema'].replace(' ', '_')}.jpg")
    sheet.save(p, quality=88)
    print(p, sheet.size)
