import sys
import time
from playwright.sync_api import sync_playwright

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

print("Accepting batch of 4 more reputable accounts...")

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

    # Find the next 4 confirm buttons
    btns = page.locator("div[aria-label='Confirm'], div[role='button']:has-text('Confirm')").all()
    print(f"Found {len(btns)} confirm buttons")

    for i in range(min(4, len(btns))):
        btns = page.locator("div[aria-label='Confirm'], div[role='button']:has-text('Confirm')").all()
        if btns:
            btns[0].click(force=True)
            print(f"Accepted request #{i+1}")
            time.sleep(2)

    page.screenshot(path="FacebookAutoPoster/requests_batch2_done.png")
    print("Saved requests_batch2_done.png")
