import sys,os
sys.path.insert(0,os.path.abspath(os.path.join(os.path.dirname(__file__),'..','..')))
import render2
from playwright.sync_api import sync_playwright
w=int(sys.argv[1]);url=sys.argv[2];out=sys.argv[3]
with sync_playwright() as p:
  br=p.chromium.launch();c=render2.mkctx(br,w);pg=c.new_page()
  pg.on('console',lambda m: print('CONSOLE',m.type,m.text) if m.type in('error','warning') else None)
  pg.on('pageerror',lambda e: print('PAGEERR',e))
  pg.goto('https://mock.local/MOCK/out-v3/src/final-v3.html?'+url);pg.wait_for_timeout(1200)
  for e in pg.query_selector_all('#list .card'):
    sc=e.get_attribute('data-mk-sc') or e.query_selector('.icao').text_content().strip()
    e.screenshot(path=f'{out}_{sc}.png',animations='disabled')
  br.close()
