#!/usr/bin/env python3
"""Renderiza os 9 HTMLs -> PNG via Playwright."""
from playwright.sync_api import sync_playwright
from pathlib import Path

BASE = Path('/opt/mia/workspace/clientes/px3lab/lancamento_photorf2/criativos')

# (html, png, largura, altura)
JOBS = [
    ('copy2.html',  'copy2_fila_v1.png',              1080, 1080),
    ('copy3.html',  'copy3_triagem_v1.png',           1080, 1080),
    ('copy4.html',  'copy4_vizinhanca_v1.png',        1080, 1080),
    ('copy5.html',  'copy5_familiares_story_v1.png',  1080, 1920),
    ('copy6.html',  'copy6_privacidade_v1.png',       1080, 1920),
    ('copy7.html',  'copy7_vizinhanca_story_v1.png',  1080, 1920),
    ('copy8.html',  'copy8_familiares_reels_v1.png',  1080, 1350),
    ('copy9.html',  'copy9_fila_reels_v1.png',        1080, 1350),
    ('copy10.html', 'copy10_triagem_reels_v1.png',    1080, 1350),
]

with sync_playwright() as p:
    browser = p.chromium.launch()
    for html_file, png_file, w, h in JOBS:
        html_path = BASE / html_file
        out = BASE / png_file
        assert html_path.exists(), f'HTML nao existe: {html_path}'
        page = browser.new_page(viewport={'width': w, 'height': h}, device_scale_factor=1)
        page.goto(f'file://{html_path}')
        page.wait_for_load_state('networkidle')
        page.wait_for_timeout(500)
        page.screenshot(path=str(out), clip={'x': 0, 'y': 0, 'width': w, 'height': h})
        page.close()
        print(f'OK: {out} ({out.stat().st_size} bytes)')
    browser.close()
