import sys, asyncio
from playwright.async_api import async_playwright
base, out, doc_id, question = sys.argv[1], sys.argv[2], int(sys.argv[3]), sys.argv[4]
async def main():
    async with async_playwright() as p:
        b = await p.chromium.launch(executable_path="/usr/bin/google-chrome")
        pg = await b.new_page(viewport={"width": 1400, "height": 900})
        await pg.goto(base, wait_until="networkidle")
        # open the document from the library by its card
        await pg.wait_for_selector("text=Q4 2025 Earnings Supplement", timeout=30000)
        cards = pg.get_by_text("Q4 2025 Earnings Supplement")
        await cards.first.click()
        await pg.wait_for_selector("textarea", timeout=30000)
        await pg.fill("textarea", question)
        await pg.get_by_role("button", name="Send").click()
        await pg.wait_for_selector(".refs-list, .refs-ledger", timeout=120000)
        await pg.wait_for_timeout(800)
        pane = await pg.query_selector(".chat-scroll")
        await pane.screenshot(path=out)
        await b.close()
asyncio.run(main())
