import asyncio
from playwright.async_api import async_playwright

async def render(html_path, png_path, w, h):
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page(viewport={'width': w, 'height': h})
        await page.goto(f'file://{html_path}')
        await page.wait_for_load_state('networkidle')
        await asyncio.sleep(1)
        await page.screenshot(path=png_path, full_page=False)
        await browser.close()
    print(f'Rendered: {png_path}')

async def main():
    base = '/home/jay/workspace/output/banners'
    cells = [
        ('cell-1-incar-fair', 'meta-feed-1080x1080', 1080, 1080),
        ('cell-1-incar-fair', 'google-resp-1200x628', 1200, 628),
        ('cell-2-incar-leader', 'meta-feed-1080x1080', 1080, 1080),
        ('cell-2-incar-leader', 'google-resp-1200x628', 1200, 628),
        ('cell-3-incar-support', 'meta-feed-1080x1080', 1080, 1080),
        ('cell-3-incar-support', 'google-resp-1200x628', 1200, 628),
    ]
    for cell_dir, name, w, h in cells:
        await render(f'{base}/{cell_dir}/{name}.html', f'{base}/{cell_dir}/{name}.png', w, h)

asyncio.run(main())
