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

from src.assistant_tool.screen_capturer import ScreenCapturer, attach_to_default_desktop
capturer = ScreenCapturer()
hwnd = capturer.find_poe2_window()
print(f"ScreenCapturer.find_poe2_window(): {hex(hwnd) if hwnd else None}")

if hwnd:
    import ctypes
    from ctypes import wintypes
    user32 = ctypes.windll.user32
    rect = wintypes.RECT()
    user32.GetClientRect(hwnd, ctypes.byref(rect))
    wrect = wintypes.RECT()
    user32.GetWindowRect(hwnd, ctypes.byref(wrect))
    fg = user32.GetForegroundWindow()
    print(f"Foreground: {hex(fg)}, IsIconic: {user32.IsIconic(hwnd)}, ClientRect: ({rect.left}, {rect.top}, {rect.right}, {rect.bottom}), WindowRect: ({wrect.left}, {wrect.top}, {wrect.right}, {wrect.bottom})")
    brought = capturer.bring_to_foreground(hwnd)
    print(f"Brought to foreground: {brought}")
