import asyncio
from playwright.async_api import async_playwright

async def debug_favorites():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True)
        context = await browser.new_context(storage_state="auth.json")
        page = await context.new_page()

        print("Loading favorites page...")
        await page.goto("https://www.properstar.nl/favorites", timeout=60000)
        await page.wait_for_load_state("load")
        await asyncio.sleep(3)

        # Get all listings
        listings = await page.query_selector_all("article.item-adaptive.card-basic")
        print(f"Found {len(listings)} listings\n")

        if listings:
            # Check first listing
            first = listings[0]
            html = await first.inner_html()
            print("=== FIRST LISTING HTML ===")
            print(html[:1500])  # First 1500 chars
            print("\n=== Looking for links ===")

            # Try different selectors
            selectors = [
                "a[href*='/property-for-sale']",
                "a[href*='/listing/']",
                "a[href]",
                "a.item-link"
            ]

            for selector in selectors:
                links = await first.query_selector_all(selector)
                print(f"{selector}: found {len(links)} links")
                if links:
                    href = await links[0].get_attribute("href")
                    print(f"  First href: {href}")

        await browser.close()

asyncio.run(debug_favorites())
