import sys
import time
from pathlib import Path

sys.path.insert(0, '05_Production_Pipeline')
if sys.platform == 'win32':
    sys.stdout.reconfigure(encoding='utf-8')
from invisible_playwright import InvisiblePlaywright

pdir = Path.home() / 'AntigravityProfiles' / 'phu2234_worker'
with InvisiblePlaywright(profile_dir=pdir, headless=True) as ctx:
    page = ctx.pages[0] if ctx.pages else ctx.new_page()
    page.goto('https://muse.ai/thread/new', wait_until='domcontentloaded', timeout=25000)
    time.sleep(4)
    print('Title:', page.title(), 'URL:', page.url)
    
    # Check for sidebar threads
    threads = page.locator('a[href*="/thread/"], [role="navigation"] a').all()
    print('Thread links count:', len(threads))
    for t in threads[:10]:
        print(' -', t.get_attribute('href'), '|', t.inner_text().strip().replace('\n', ' ')[:50])
        
    # Check what text is visible
    buttons = [b.inner_text().strip() for b in page.locator('button').all() if b.inner_text().strip()]
    print('Buttons found:', buttons[:15])

