#!/usr/bin/env python3
"""Find all buttons on Launch27 booking edit page"""
import asyncio
from playwright.async_api import async_playwright

BOOKING_ID = "77663"
EMAIL = "mike@nomorechores.com"
PASSWORD = "er!NCY73J"
BASE_URL = "https://nomorechores.launch27.com"

async def find_buttons():
    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}/edit", wait_until="domcontentloaded")
        await page.wait_for_timeout(6000)

        # Find all buttons and clickable elements
        buttons = await page.query_selector_all('button')
        print(f"Found {len(buttons)} buttons:")
        for btn in buttons:
            txt = ''
            try:
                txt = await btn.inner_text()
            except:
                pass
            cls = await btn.get_attribute('class') or ''
            t = await btn.get_attribute('type') or ''
            ng = await btn.get_attribute('ng-click') or ''
            print(f"  type={t} text='{txt[:50]}' class='{cls[:50]}' ng-click='{ng[:80]}'")

        # Also find input[type=submit]
        submits = await page.query_selector_all('input[type="submit"]')
        print(f"\nFound {len(submits)} input[type=submit]:")
        for s in submits:
            v = await s.get_attribute('value') or ''
            print(f"  value='{v}'")

        # Find anchors that look like buttons
        links = await page.query_selector_all('a')
        print(f"\nFound {len(links)} links:")
        for lnk in links:
            txt = ''
            try:
                txt = await lnk.inner_text()
            except:
                pass
            if any(kw in txt.lower() for kw in ['save', 'update', 'submit', 'book', 'confirm', 'reschedule']):
                cls = await lnk.get_attribute('class') or ''
                href = await lnk.get_attribute('href') or ''
                ng = await lnk.get_attribute('ng-click') or ''
                print(f"  text='{txt[:60]}' class='{cls[:40]}' href='{href[:40]}' ng-click='{ng[:80]}'")

        await page.screenshot(path="/Users/harvey/.openclaw/workspace/l27-buttons.png", full_page=True)
        print("\nFull page screenshot saved.")
        await browser.close()

asyncio.run(find_buttons())
