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 sync_worker_profile, DEFAULT_PROFILE

def check_live():
    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(4)
        
        page.screenshot(path='04_Assets/current_muse_live_state.png')
        print("Screenshot saved to 04_Assets/current_muse_live_state.png")
        
        body = page.locator('body').inner_text()
        print('Connecting:', 'Đang kết nối' in body)
        print('Still sending:', 'Vẫn đang gửi' in body)
        
        # Check all assistant replies
        arts = page.locator('[data-message-author="assistant"], [role="article"]').all()
        print('Assistant replies count:', len(arts))
        for i, a in enumerate(arts):
            print(f"Reply [{i}]:", a.inner_text()[:200])
            
        # Check dl buttons
        dl = page.locator('button[aria-label="Tải video xuống"]').all()
        print('DL buttons count:', len(dl))

if __name__ == '__main__':
    check_live()
