(defvar battery-reveal false)

(defwidget battery-module []
  (eventbox :onhover "${EWW_CMD} update battery-reveal=true"
            :onhoverlost "${EWW_CMD} update battery-reveal=false"
            (box :class "module battery ${EWW_BATTERY.BAT0.status == "Discharging" ? "discharging" : "charging"}"
                 :orientation "h"
                 :space-evenly "false"
                 :tooltip "Battery: ${EWW_BATTERY.BAT0.capacity}%"
                 (label :text {EWW_BATTERY.BAT0.status == "Discharging" ?
                               EWW_BATTERY.BAT0.capacity < 10 ? "󰂎" : EWW_BATTERY.BAT0.capacity < 30 ? "󱊡" : EWW_BATTERY.BAT0.capacity < 70 ? "󱊢" : "󱊣" :
                               EWW_BATTERY.BAT0.capacity < 10 ? "󰢟" : EWW_BATTERY.BAT0.capacity < 30 ? "󱊤" : EWW_BATTERY.BAT0.capacity < 70 ? "󱊥" : "󱊦"}
                        :class "battery icon")
                 (revealer :transition "slideleft"
                           :duration "750ms"
                           :reveal {battery-reveal}
                           (progress :class "battery-bar"
                                     :orientation "h"
                                     :valign "center"
                                     :width 60
                                     :value {EWW_BATTERY.BAT0.capacity})))))
