(deflisten cpu :initial '{}' "scripts/sys/cpu")
(deflisten gpu :initial '{"devices":[{"GRBM2":{}}]}' "scripts/sys/gpu")
(deflisten memory :initial '{"human":{"used":"0G","total":"0G"},"used":0.0,"total":1.0}' "scripts/sys/memory")

(deflisten battery :initial '{"visible":false,"percentage":0.0,"color":"#FFFFFF"}' "scripts/sys/battery")

(defwidget sys-mod []
  (module
    (eventbox
      :onclick "(sleep 0.1 && eww-open-on-current-screen sys --toggle)"
      (box
        :orientation "v"
          (circular-progress
            :value {EWW_CPU.avg}
            :class "cpubar"
            :thickness 6
            (label :class "icon-text" :text "C"))

          (circular-progress
            :value {gpu.devices[0].GRBM2?.CommandProcessor-Graphics?.value?:0}
            :class "gpubar"
            :thickness 6
            (label :class "icon-text" :text "G"))
        (circular-progress
          :value {100*memory.used/memory.total}
          :class "membar"
          :thickness 6
          :tooltip "${memory.human.used} / ${memory.human.total}"
          (label :class "icon-text" :text "M"))

        (circular-progress
          :value {battery.percentage}
          :class "batbar"
          :visible {battery.visible}
          :style "color: ${battery.color};"
          :thickness 6
          :tooltip "${battery.status} @ ${battery.wattage}"
          (label :class "icon-text" :text "B"))
      )
    )
  )
)
