import sys, time
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/rmacsparran/_created/', timeout=30000)
    time.sleep(5)

    # Click the edit-profile-cover / + button at x=1210, y=24
    print('Clicking x=1210, y=24 (the + icon)...')
    client.page.mouse.click(1210, 24)
    time.sleep(3)
    client.page.screenshot(path=str(data_dir / 'debug_click_plus.png'))

    # Check for any new dialogs/modals
    for e in client.page.query_selector_all('[role="dialog"], [aria-modal="true"], [data-test-id*="modal"], [data-test-id*="create"], [data-test-id*="board"]'):
        try:
            testid = e.get_attribute('data-test-id') or ''
            role = e.get_attribute('role') or ''
            txt = (e.inner_text() or '').strip()[:100]
            print(f'  testid={testid!r} role={role!r} txt={txt!r}')
        except:
            pass

    # Also check current URL
    print('URL after click:', client.page.url)

    # Now try navigating to direct board creation URL
    print('\nTrying direct board creation URL...')
    client.page.goto('https://www.pinterest.com/board-creation/', timeout=15000)
    time.sleep(3)
    client.page.screenshot(path=str(data_dir / 'debug_board_creation_url.png'))
    print('URL:', client.page.url)
    for e in client.page.query_selector_all('[data-test-id]'):
        try:
            testid = e.get_attribute('data-test-id') or ''
            txt = (e.inner_text() or '').strip()[:60]
            if testid and txt:
                print(f'  testid={testid!r} txt={txt!r}')
        except:
            pass
