import os, sys, time
from datetime import datetime
from PIL import Image

sys.path.insert(0, os.path.abspath('.'))
from src.common.win32_window import find_poe2_window, get_client_rect
from src.common.screen_capture import capture_rect_bitblt

hwnd = find_poe2_window()
print(f"POE2 HWND: {hex(hwnd) if hwnd else None}")

if hwnd:
    cl, ct, cw, ch = get_client_rect(hwnd)
    print(f"Client rect: ({cl}, {ct}, {cw}, {ch})")
    img = capture_rect_bitblt(cl, ct, cw, ch)
    if img:
        ts = datetime.now().strftime("%Y%m%d_%H%M%S")
        out_path = f"captures/live_ops/{ts}_REPORT_ITER11.png"
        os.makedirs("captures/live_ops", exist_ok=True)
        img.save(out_path)
        print(f"Saved live screenshot: {out_path}")
    else:
        print("Failed to capture bitblt")
else:
    print("POE2 window not found")
