import sys, time
from pathlib import Path
sys.path.append(str(Path("05_Production_Pipeline").resolve()))
from invisible_playwright import InvisiblePlaywright
from muse_invpw_driver import DEFAULT_PROFILE

def inspect_state():
    with InvisiblePlaywright(profile_dir=DEFAULT_PROFILE, headless=True) as ctx:
        page = ctx.pages[0] if ctx.pages else ctx.new_page()
        page.goto("https://muse.ai", wait_until="domcontentloaded", timeout=30000)
        time.sleep(4)
        
        page.screenshot(path="04_Assets/current_muse_state.png", full_page=True)
        print("Page URL:", page.url)
        print("Page title:", page.title())
        
        # In toan bo noi dung van ban tren trang
        articles = page.locator('[data-message-author="assistant"], [role="article"], .chat-message').all()
        print(f"Assistant messages count: {len(articles)}")
        for i, a in enumerate(articles):
            print(f"--- Message {i+1} ---")
            print(a.inner_text()[:400])
            
        buttons = page.locator('button').all()
        btn_texts = []
        for b in buttons:
            try:
                t = b.inner_text().strip() or b.get_attribute("aria-label") or b.get_attribute("title")
                if t: btn_texts.append(t)
            except Exception: pass
        print("Buttons found:", btn_texts[:25])

if __name__ == '__main__':
    inspect_state()
