"""Debug script — find Pinterest board page selectors. Run inside container."""
import sys, time, json
from pathlib import Path
sys.path.insert(0, '/app')
from pinterest.client import PinterestClient

data_dir = Path('/app/data/pinterest')
with PinterestClient(data_dir) as client:
    client.is_authenticated()
    client.page.goto('https://www.pinterest.com/me/boards/', timeout=30000)
    time.sleep(6)
    client.page.screenshot(path=str(data_dir / 'debug_boards_page.png'))

    # Dump all buttons and interactive elements
    elems = client.page.query_selector_all('button, [role="button"], a[href*="board"], [data-test-id]')
    print(f'Found {len(elems)} elements')
    seen = set()
    for e in elems:
        try:
            txt = (e.inner_text() or '').strip()[:60]
            aria = e.get_attribute('aria-label') or ''
            testid = e.get_attribute('data-test-id') or ''
            tag = e.evaluate('el => el.tagName')
            key = f'{txt}|{aria}|{testid}'
            if key not in seen and (txt or aria or testid):
                seen.add(key)
                print(f'  {tag}: text={txt!r} aria={aria!r} testid={testid!r}')
        except Exception as ex:
            pass

    # Also dump page source snippet around 'create' keyword
    src = client.page.content()
    idx = src.lower().find('create')
    if idx > 0:
        print('\n--- HTML around "create" ---')
        print(src[max(0,idx-200):idx+500])
