import sys
import time
from playwright.sync_api import sync_playwright

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

print("Targeted accept for authentic accounts...")
with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp("http://127.0.0.1:9224")
    page = browser.contexts[0].pages[0]

    # Target specific authentic accounts we verified on screen:
    targets = ["Hà Khuyên", "Hoàng Long", "Nguyễn Mạnh Tường", "Lường Văn Kiêm", "Minh Pham"]
    
    for name in targets:
        try:
            # Find row with name
            row = page.locator(f"div:has-text('{name}')").last
            if row.is_visible():
                btn = row.locator("div[role='button']:has-text('Confirm'), div[role='button']:has-text('Xác nhận')").first
                if btn.is_visible():
                    print(f"✅ Clicking Confirm for {name}...")
                    btn.click(force=True)
                    time.sleep(1.5)
        except Exception as e:
            print(f"Error accepting {name}: {e}")

    time.sleep(2)
    page.screenshot(path="FacebookAutoPoster/friends_accepted_batch2.png")
    print("Saved friends_accepted_batch2.png")
