(defvar wifi-reveal false)
(defpoll winfo
  :initial "{\"connected\": \"false\"}"
  :interval "10s"
  "bash ~/.config/eww/scripts/get-wifi-info.sh")


(defwidget wifi-module []
  (eventbox :onhover "${EWW_CMD} update wifi-reveal=true"
            :onhoverlost "${EWW_CMD} update wifi-reveal=false"
            :onclick "$HOME/.config/rofi/menus/wifi/wifi.sh &"
            (box :class "module wifi"
                 :orientation "h"
                 :space-evenly "false"
                 :tooltip {winfo.connected ? "Signal: ${winfo.signal}%" : "Disconnected"}
                 (label :text { !winfo.connected ? "󰤭" :
                               winfo.signal < 25 ? "󰤟" :
                               winfo.signal < 50 ? "󰤢" :
                               winfo.signal < 75 ? "󰤥" : "󰤨"}
                        :class "wifi icon")
                 (revealer :transition "slideleft"
                           :duration "750ms"
                           :reveal {wifi-reveal && winfo.connected}
                           (label :class "wifi-text"
                                  :text {winfo.connected ? winfo.ssid : "Disconnected"})))))
