import time
import sys
from pathlib import Path

sys.path.insert(0, str(Path(".").resolve()))
from src.common.win32_window import find_poe2_window, get_client_rect, attach_to_window_desktop, ensure_window_focus
from src.common.win32_input import click, post_message_click, set_input_simulation_mode
from src.common.screen_capture import capture_window_bitblt

hwnd = find_poe2_window()
print("HWND:", hex(hwnd))
attach_to_window_desktop(hwnd)
ensure_window_focus(hwnd)

cl, ct, cw, ch = get_client_rect(hwnd)
print("Client rect:", cl, ct, cw, ch)

set_input_simulation_mode(True)

# Click the MAP DEVICE label at (310, 192)
print("Clicking MAP DEVICE label at client (310, 192)...")
click(cl + 310, ct + 192, hold_ms=0.08, delay_after=0.2)
post_message_click(hwnd, 310, 192, hold_ms=0.08, delay_after=0.2)

# Also click the altar base at (310, 240)
print("Clicking MAP DEVICE altar base at client (310, 240)...")
click(cl + 310, ct + 240, hold_ms=0.08, delay_after=0.2)
post_message_click(hwnd, 310, 240, hold_ms=0.08, delay_after=2.0)

img_after = capture_window_bitblt(hwnd, client_only=True)
img_after.save("captures/after_click_map_device.png")
print("Saved captures/after_click_map_device.png")
