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 check_new_chat():
    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)
        
        # Check buttons with + or 'mới' or 'new' or sidebar
        buttons = page.locator("button, a")
        print(f"Total elements: {buttons.count()}")
        for i in range(buttons.count()):
            b = buttons.nth(i)
            aria = b.get_attribute("aria-label") or ""
            text = b.inner_text().strip()
            title = b.get_attribute("title") or ""
            href = b.get_attribute("href") or ""
            if any(k in f"{aria} {text} {title} {href}".lower() for k in ["mới", "new", "chat", "+", "tạo"]):
                print(f"El {i}: tag={b.evaluate('el => el.tagName')} | text='{text}' | aria='{aria}' | title='{title}' | href='{href}'")

if __name__ == "__main__":
    check_new_chat()
