"""Find JInternalFrame title bar buttons by probing the title bar area."""
import requests

HOST = "http://127.0.0.1:8765"

# Fund Maintenance: physical x=976, y=271, w=722, h=547
# PO Maintenance: physical x=852, y=214, w=887, h=576
# Title bar buttons are small (18x18 physical) near the edges of the title bar

print("=== Fund Maintenance title bar area (physical y=271-310) ===")
fm_x = 976  # frame left
fm_y = 271  # frame top
for x_offset in range(0, 50, 3):
    for y_offset in range(0, 30, 3):
        x = fm_x + x_offset
        y = fm_y + y_offset
        r = requests.post(f"{HOST}/info-at", json={"x": x, "y": y}, timeout=5)
        d = r.json()
        f = d.get("found", {})
        role = f.get("role", "?")
        name = f.get("name", "?")
        if role in ("push button", "toggle button", "button") or (name and name != "Fund Maintenance"):
            print(f"  ({x},{y}): role={role!r:22} name={name!r:30} bounds={f.get('bounds')}")

print("\n=== PO Maintenance title bar area (physical y=214-250) ===")
po_x = 852
po_y = 214
for x_offset in range(0, 50, 3):
    for y_offset in range(0, 30, 3):
        x = po_x + x_offset
        y = po_y + y_offset
        r = requests.post(f"{HOST}/info-at", json={"x": x, "y": y}, timeout=5)
        d = r.json()
        f = d.get("found", {})
        role = f.get("role", "?")
        name = f.get("name", "?")
        if role in ("push button", "toggle button", "button") or (name and name not in ("Purchase Order Maintenance", "")):
            print(f"  ({x},{y}): role={role!r:22} name={name!r:30} bounds={f.get('bounds')}")
