(defpoll volume :interval "0.5s" `bash $HOME/.config/eww/scripts/audio.sh` )
(defpoll speaker_state :interval "1s" `bash $HOME/.config/eww/scripts/speakerstate.sh`)

(defpoll net_status :interval "60s" `bash $HOME/.config/eww/scripts/network.sh`)
(defpoll net_name :interval "60s" `nmcli | grep -Po '(?<=connected to ).*'`)

(defpoll rx_bandwidth :interval "5s" `bash $HOME/.config/eww/scripts/rx_bandwidth.sh`)
(defpoll tx_bandwidth :interval "5s" `bash $HOME/.config/eww/scripts/tx_bandwidth.sh`)

(defpoll battery :interval "10s" `cat /sys/class/power_supply/BAT0/capacity`)
(defpoll battery_status :interval "5s" `cat /sys/class/power_supply/BAT0/status`)

(defvar net_reveal false)
(defvar vol_reveal false)

(defwidget systeminfo []
    (box :space-evenly "false" :class "system_module" :spacing 5
        (box :space-evenly false :tooltip "${battery}%"
            (label :class "sysinfo" :text {battery > 10 ? "" : ""})
            (label :class "sysinfo"  :text {battery > 90 ? " " : battery > 65 ? " " : battery > 40 ? " " : battery > 15 ? " " : " "})
            (label :class "sysinfo" :text {battery_status == "Charging" ? "󱐋" : ""})
        )
        (eventbox :onhover "${eww} update vol_reveal=true" :onhoverlost "${eww} update vol_reveal=false"
            (box :space-evenly "false"
                (label :class "volume" :text {volume > 50 ? " " : volume > 0 ? " ": " "})
                (revealer :reveal vol_reveal :transition "slideright"
                    (scale :class "volbar"
                        :value volume 
                        :orientation "h"
                        :tooltip "${volume}%"
                        :max 100
                        :min 0
                        :onchange "amixer sset Master {}%"
                    )
                )
            )
        )
        (eventbox :onhover "${eww} update net_reveal=true" :onhoverlost "${eww} update net_reveal=false"
            (box :space-evenly "false" :tooltip net_name
                (label :class "net_status" :text { net_status ? "󰖩 " : "󰖪 " })
                (revealer :reveal net_reveal :transition "slideright"
                    (box :space-evenly false 
                        (label :class "net_status" :text "")
                        (label :class "net_status" :text tx_bandwidth)
                        (label :class "net_status" :text "")
                        (label :class "net_status" :text rx_bandwidth)
                    )
                )
            )
        )
    )
)


