import sys
from playwright.sync_api import sync_playwright

if hasattr(sys.stdout, 'reconfigure'):
    sys.stdout.reconfigure(encoding='utf-8')

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp("http://127.0.0.1:9224")
    context = browser.contexts[0]
    page = context.pages[0] if context.pages else context.new_page()

    page.goto("https://www.facebook.com/profile.php?id=61594841053758", wait_until="domcontentloaded")
    page.wait_for_timeout(4000)

    # Chụp ảnh tổng quan trang cá nhân hiện tại
    page.screenshot(path="FacebookAutoPoster/profile_status_check.png")
    print("📸 Saved: FacebookAutoPoster/profile_status_check.png")

    # Kiểm tra số lượng bạn bè
    friends_box = page.locator("a[href*='/friends']")
    for i in range(friends_box.count()):
        txt = friends_box.nth(i).inner_text().strip()
        if txt:
            print(f"Friends link [{i}]: {txt}")

    # Cuộn nhẹ để kiểm tra tương tác trên bài đăng Day 1
    page.mouse.wheel(0, 800)
    page.wait_for_timeout(3000)
    page.screenshot(path="FacebookAutoPoster/day1_post_engagement.png")
    print("📸 Saved: FacebookAutoPoster/day1_post_engagement.png")
