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(3)
    
    # Inspect sidebar buttons structure
    for b in page.locator('button').all():
        txt = b.inner_text().strip()
        if 'làng quê 1980' in txt:
            print('Outer HTML of Shot 01 sidebar item:')
            print(b.evaluate('el => el.outerHTML'))
            # Try to see if clicking parent or clicking button navigates
            print('Tag:', b.evaluate('el => el.tagName'))
            print('Parent tag:', b.evaluate('el => el.parentElement.tagName'))
            print('Parent outer HTML:', b.evaluate('el => el.parentElement.outerHTML[:300]'))
            break
