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

from src.assistant_tool.screen_capturer import ScreenCapturer

capturer = ScreenCapturer(output_dir="captures")
hwnd = capturer.find_poe2_window()
if not hwnd:
    print("Could not find POE2 window")
    sys.exit(1)

capturer.bring_to_foreground(hwnd)
time.sleep(0.2)

user32 = ctypes.windll.user32

def send_mouse_click(x, y):
    # Set cursor
    user32.SetCursorPos(x, y)
    time.sleep(0.05)
    # Jiggle 1 pixel to trigger game engine hover event
    user32.mouse_event(0x0001, 1, 0, 0, 0) # MOUSEEVENTF_MOVE
    time.sleep(0.05)
    user32.mouse_event(0x0001, -1, 0, 0, 0)
    time.sleep(0.15)
    # Left click
    user32.mouse_event(0x0002, 0, 0, 0, 0) # LEFTDOWN
    time.sleep(0.06)
    user32.mouse_event(0x0004, 0, 0, 0, 0) # LEFTUP

# Click on STEPPE (COMPLETED) text label at (1210, 370)
print("Clicking STEPPE (COMPLETED) label at (1210, 370)...")
send_mouse_click(1210, 370)
time.sleep(2.5)

img_path = capturer.capture_screenshot(event_name="CLICK_STEPPE_LABEL", capture_ram=False)
print(f"Captured: {img_path}")
