#!/usr/bin/env python3
"""Check current state of a booking in Launch27"""
import sys
import asyncio
from playwright.async_api import async_playwright

BOOKING_ID = sys.argv[1] if len(sys.argv) > 1 else "77663"
EMAIL = "mike@nomorechores.com"
PASSWORD = "er!NCY73J"
BASE_URL = "https://nomorechores.launch27.com"

async def check():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page()
        page.set_default_timeout(30000)

        await page.goto(f"{BASE_URL}/login", wait_until="networkidle")
        await page.wait_for_timeout(2000)
        await page.fill('input[ng-model="ctrl.user.email"]', EMAIL)
        await page.fill('input[ng-model="ctrl.user.password"]', PASSWORD)
        await page.click('button:has-text("Sign In")')
        await page.wait_for_load_state("networkidle")
        await page.wait_for_timeout(2000)

        await page.goto(f"{BASE_URL}/admin/bookings/{BOOKING_ID}", wait_until="domcontentloaded")
        await page.wait_for_timeout(5000)
        print(f"URL: {page.url}")
        text = await page.evaluate("() => document.body.innerText")
        print(f"Page text (first 500): {text[:500]}")
        await page.screenshot(path="/Users/harvey/.openclaw/workspace/l27-booking-check.png")
        await browser.close()

asyncio.run(check())
