#!/usr/bin/env python3
"""
Manual Login - Save Properstar Session
Opens browser, waits for you to press Enter after logging in, then saves session
"""
import asyncio
from playwright.async_api import async_playwright

AUTH_JSON = "auth.json"
FAVORITES_URL = "https://www.properstar.nl/favorites"

async def manual_login():
    print("🚀 Manual Properstar Login")
    print("=" * 70)
    print()

    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=False)
        context = await browser.new_context()
        page = await context.new_page()

        # Open favorites page
        print("🌐 Opening Properstar favorites page...")
        await page.goto(FAVORITES_URL, timeout=60000)

        # Wait for manual confirmation
        print()
        print("⏰ TAKE YOUR TIME!")
        print("1. Log in to Properstar in the browser window")
        print("2. Make sure you see your favorites page")
        print("3. Come back here and press ENTER")
        print()
        input("✅ Press ENTER when you're logged in and see your favorites...")

        # Give it a moment to stabilize
        await asyncio.sleep(2)

        # Save session
        print("\n⏳ Saving session...")
        try:
            await context.storage_state(path=AUTH_JSON)
            print(f"✅ Session saved to {AUTH_JSON}")
            print()
            print("🎉 SUCCESS! You can now use:")
            print("   - python3 favorites_scraper.py")
            print("   - python3 auto_scrape_favorites.py now")
            print("   - UI button 'Full Update'")
            print()
        except Exception as e:
            print(f"❌ Error saving session: {e}")
            print("Try again and make sure you're on the favorites page")

        await browser.close()

if __name__ == "__main__":
    asyncio.run(manual_login())
