import app from "ags/gtk3/app"
import style from "./style.scss"
import Heartbeat from "./widget/Heartbeat"
import Bar from "./widget/Bar"
import BrainPower from "./widget/panels/BrainPower"

app.start({
  css: style,
  main() {
    const monitors = app.get_monitors()
    for (const monitor of monitors) {
      Heartbeat(monitor)
      Bar(monitor)
    }
    // Brain Power on primary monitor only
    const primary = monitors[0]
    if (primary) BrainPower(primary)
  },
  requestHandler(request: any, res: (response: any) => void) {
    const cmd = String(request)
    if (cmd.includes("toggle-brain")) {
      const win = app.get_window("brain-power")
      if (win) {
        win.visible = !win.visible
        res("toggled")
      } else {
        res("window not found")
      }
    } else {
      res(`unknown: '${cmd}'`)
    }
  },
})
