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

# Portal is right next to player at (1460, 360)
print("Moving cursor to portal at (1460, 360)...")
user32.SetCursorPos(1460, 360)
time.sleep(0.2)

# Click
print("Clicking portal...")
user32.mouse_event(0x0002, 0, 0, 0, 0)
time.sleep(0.08)
user32.mouse_event(0x0004, 0, 0, 0, 0)

# Also press F (interact)
user32.keybd_event(0x46, 0x21, 0, 0)
time.sleep(0.05)
user32.keybd_event(0x46, 0x21, 0x0002, 0)

print("Waiting 4.5s for loading transition to Shoreline Hideout...")
time.sleep(4.5)

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