#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Contact sheet 10 slide carousel (2 kolom x 5 baris) untuk QC & preview."""
import sys, glob
from PIL import Image, ImageDraw

indir = sys.argv[1] if len(sys.argv) > 1 else "/tmp/tslaw_mitos10"
out = sys.argv[2] if len(sys.argv) > 2 else f"{indir}/contact.jpg"
files = sorted(glob.glob(f"{indir}/*.png")) + sorted(glob.glob(f"{indir}/*.jpg"))
files = [f for f in files if "contact" not in f and "perbandingan" not in f]
cols = 2
tw = 480
th = int(tw * 1350 / 1080)
top, gap = 30, 12
rows = (len(files) + cols - 1) // cols
sheet = Image.new("RGB", (cols * tw + gap * (cols + 1), rows * (th + top) + gap), "white")
d = ImageDraw.Draw(sheet)
for i, p in enumerate(files):
    x = gap + (i % cols) * (tw + gap)
    y = gap + (i // cols) * (th + top)
    sheet.paste(Image.open(p).convert("RGB").resize((tw, th), Image.LANCZOS), (x, y + top))
    d.text((x + 6, y + 8), f"SLIDE {i+1:02d} — {p.split('/')[-1]}", fill="black")
sheet.save(out, "JPEG", quality=88)
print(out, sheet.size, len(files), "slide")
