#!/usr/bin/env python3
"""Pilot v1 - 5개 컨셉 A-1 슬라이드 렌더링 (Playwright)"""

from pathlib import Path
from playwright.sync_api import sync_playwright

BASE = Path("/home/jay/workspace/output/meta-ads/pilot-v1")

TEMPLATES = [
    ("template-concept09.html", "pilot-v1-concept09-minimal.png"),
    ("template-concept17.html", "pilot-v1-concept17-newsflash.png"),
    ("template-concept23.html", "pilot-v1-concept23-nike.png"),
    ("template-concept44.html", "pilot-v1-concept44-hangul-monument.png"),
    ("template-concept45.html", "pilot-v1-concept45-finance-luxury.png"),
]

def render_all():
    with sync_playwright() as p:
        browser = p.chromium.launch()
        try:
            for template_name, output_name in TEMPLATES:
                template_path = BASE / template_name
                output_path = BASE / output_name

                page = browser.new_page(viewport={"width": 1080, "height": 1080})
                page.goto(f"file://{template_path.resolve()}", wait_until="networkidle")

                # Wait for fonts to load
                page.evaluate("async () => { await document.fonts.ready; }")
                page.wait_for_timeout(2000)

                page.screenshot(
                    path=str(output_path),
                    type="png",
                    clip={"x": 0, "y": 0, "width": 1080, "height": 1080}
                )
                size_kb = output_path.stat().st_size / 1024
                print(f"[OK] {output_name} ({size_kb:.0f} KB)")
                page.close()
        finally:
            browser.close()

if __name__ == "__main__":
    render_all()
    print("\n[완료] 5개 파일럿 이미지 렌더링 완료")
