import sys
import time
from pathlib import Path

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

def inspect_latest_reply():
    sync_worker_profile()
    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(3)
        
        screenshot_path = Path("04_Assets/task232_result_screen.png").resolve()
        page.screenshot(path=str(screenshot_path))
        print("Screenshot saved to:", screenshot_path)
        
        print("\n--- ALL ASSISTANT MESSAGES ---")
        msgs = page.locator('[data-message-author="assistant"], [role="article"]').all()
        for i, m in enumerate(msgs):
            print(f"[{i}] {m.inner_text()[:400]}")
            
        print("\n--- ALL BUTTONS WITH TEXT ---")
        btns = page.locator("button").all()
        for b in btns:
            t = b.inner_text().strip()
            a = b.get_attribute("aria-label") or ""
            if t or a:
                print(f"btn: text='{t}' | aria='{a}'")

if __name__ == "__main__":
    inspect_latest_reply()
