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 get_links():
    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/library/artifacts", wait_until="domcontentloaded", timeout=30000)
        time.sleep(4)
        
        # Check all links
        for l in page.locator('a').all():
            href = l.get_attribute("href")
            txt = l.inner_text().strip()
            if href and any(k in href for k in ["library", "video", "artifact", "media"]):
                print(f"Link: text='{txt}' -> href='{href}'")
                
        # Also check buttons or nav items
        for b in page.locator('button, div[role="button"]').all():
            txt = b.inner_text().strip()
            if txt in ["Video", "Hình ảnh", "Tất cả giả liệu"]:
                print(f"Button: text='{txt}' tag={b.evaluate('el => el.tagName')}")

if __name__ == '__main__':
    get_links()
