#!/usr/bin/env python3
"""Debug: see what Google Maps looks like in headless Playwright."""
import time
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(
        headless=True,
        args=["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage", "--disable-gpu"]
    )
    page = browser.new_page(
        viewport={"width": 1920, "height": 1080},
        user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
        locale="en-IN",
        timezone_id="Asia/Kolkata",
    )
    
    page.goto("https://www.google.com/maps/@17.3,78.58,12z", timeout=30000)
    page.wait_for_timeout(8000)
    
    page.screenshot(path="/tmp/gmaps_debug.png")
    
    # Try to print what's on the page
    title = page.title()
    print(f"Title: {title}")
    
    # Check for search input by various selectors
    for sel in ['#searchboxinput', 'input[aria-label*="Search"]', 'input[placeholder*="Search"]']:
        count = page.locator(sel).count()
        print(f"Selector '{sel}': found {count}")
        if count > 0:
            text = page.locator(sel).first.get_attribute("aria-label") or ""
            print(f"  aria-label: {text}")
    
    # Check page text
    body_text = page.inner_text("body")[:2000]
    print(f"\nPage body:\n{body_text[:1000]}")
    
    browser.close()
