#!/usr/bin/env python3
"""Render all 9 creatives at 2x DPR (2160x2160) + optimize PNG."""
from playwright.sync_api import sync_playwright

FILES = ['zrd_bomber', 'zrd_windbreaker', 'zrd_reflector', 'zrd_workflow', 'zrd_belyj',
         'zrd_cnt', 'zrd_nocolor', 'zrd_fullgrey', 'zrd_nylon']
BASE = 'http://localhost:8768/'
OUT = '/root/.hermes/image_cache/zrd_1x1/rendered/'

import os
os.makedirs(OUT, exist_ok=True)

with sync_playwright() as p:
    b = p.chromium.launch(args=['--no-sandbox', '--force-color-profile=srgb'])
    for name in FILES:
        pg = b.new_page(viewport={'width': 1080, 'height': 1080}, device_scale_factor=2)
        pg.goto(BASE + name + '.html', wait_until='networkidle')
        pg.wait_for_timeout(400)
        pg.screenshot(path=OUT + name + '.png', clip={'x': 0, 'y': 0, 'width': 1080, 'height': 1080})
        pg.close()
        print('saved', name)
    b.close()
print('done')
