import sys, os, time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from youtube_studio_manager import YouTubeStudioManager

manager = YouTubeStudioManager(mode='chrome_stealth')
manager.start(headless=False)

try:
    url = "https://www.youtube.com/channel/UClZnv08RDTD4vgLOw1jmOuA/posts"
    manager.page.goto(url, wait_until="domcontentloaded", timeout=45000)
    time.sleep(6)

    # Click with Playwright locator on the placeholder
    box = manager.page.locator("#placeholder, yt-formatted-string:has-text('người hâm mộ'), #simplebox-placeholder, [id*='placeholder']").first
    print("Placeholder visible?:", box.is_visible(timeout=5000))
    if box.is_visible():
        box.click()
        print("Clicked placeholder via locator!")
        time.sleep(3)
        manager.capture_status("downloads/community_placeholder_clicked.png")

        # Type text
        manager.page.keyboard.type("🚨 TONIGHT AT 19:00 VN: EPISODE 2 DROPS! ⚔️", delay=20)
        time.sleep(2)
        manager.capture_status("downloads/community_typed.png")

finally:
    manager.close()
