#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Bikin contact sheet untuk preview design TS Law yang masih terjadwal.

- Sheet A: 6 gambar seri "Mitos atau Fakta" (tslaw_mitos_fakta_06..11.jpg)
- Sheet B: 10 slide carousel "Mitos atau Fakta: 8 Anggapan" (tslaw_mitos10_01..10.jpg)
"""
import os, shutil, glob
from PIL import Image, ImageDraw

WS = "/home/mantapman/.hermes/profiles/atun/workspace"
IMG = os.path.join(WS, "openclaw-img")


def sheet(files, out, tw=480, cols=2, label=None):
    th = int(tw * 1350 / 1080)
    top, gap = 30, 12
    rows = (len(files) + cols - 1) // cols
    sh = Image.new("RGB", (cols * tw + gap * (cols + 1), rows * (th + top) + gap), "white")
    d = ImageDraw.Draw(sh)
    for i, p in enumerate(files):
        x = gap + (i % cols) * (tw + gap)
        y = gap + (i // cols) * (th + top)
        im = Image.open(p).convert("RGB").resize((tw, th))
        sh.paste(im, (x, y + top))
        d.text((x, y + 8), os.path.basename(p), fill="black")
    sh.save(out, quality=88)
    print(out, sh.size)


a = [os.path.join(IMG, f"tslaw_mitos_fakta_{n:02d}.jpg") for n in range(6, 12)]
b = sorted(glob.glob(os.path.join(IMG, "tslaw_mitos10_*.jpg")))
sheet([f for f in a if os.path.exists(f)], "/tmp/sheet_tslaw_mitosfakta.jpg")
sheet([f for f in b if "contact" not in f], "/tmp/sheet_tslaw_mitos10.jpg")
