(include "/home/guz/.config/eww/vars.yuck");

(defpoll week-day :interval "1m"
                  :initial "1"
  `date +%w`)

(defpoll quarter :interval "24h"
                  :initial "1"
  `date +%q`)

(defpoll time :interval "10s"
              :initial "00:00"
  `date +%H:%M`)

(defpoll date :interval "1m"
              :initial "00/00"
  `date +%d/%m`)


(defwidget empty [] "")

(defwidget day []
  (box :orientation "h"
    ; Sun, Moon, Mars, Mercury, Jupiter, Venus, Saturn
    "${[" Sun", " Mon", " Tue", "󰬸 Wed", "󱡓 Thu", " Fri", " Sat"][week-day]} ${date} ${time}"))

(defwidget season []
  (box :orientation "h"
    "${["", "󰖨 Summer", "󰌪 Autumn", " Winter", "󰉊 Spring"][quarter]}"))

(defwidget metric [label value ?value-text ?onchange ?onclick]
  (box :orientation "h"
       :tooltip "${value-text != "" ? value-text : value}"
       :space-evenly false
       :class "metric"
    (box :orientation "h" 
         :class "label"
      (eventbox :active {onclick != ""} 
                :width 15 
                :cursor "pointer"
                :onclick onclick 
        label))
    (scale :min 0
           :max 101
           :active {onchange != ""}
           :onchange onchange
           :value value)))

(defwidget system-stats []
  (box :class "system-stats"
      ""))

(defwidget workspaces [workspace]
  (box :class "workspace"
       :orientation "h"
    "${
      workspace == 1 ? '' : ''
    } ${
      workspace == 2 ? '' : ''
    } ${
      workspace == 3 ? '' : ''
    } ${
      workspace == 4 ? '' : ''
    } ${
      workspace == 5 ? '' : ''
    }"))

(defwindow bar
           :monitor 0
           :geometry (geometry :x "0%"
                               :y "0%"
                               :width "100%"
                               :height "20px"
                               :anchor "top center")
           :stacking "fg"
           :reserve (struts :distance "40px" :side "top")
           :windowtype "dock"
           :wm-ignore false
           :exclusive true
  (box :orientation "h"
       :class "wrapper"
  (centerbox :orientation "h"
             :class "bar"
    (box :orientation "h"
               :halign "start"
               :class "rightstuff"
      (workspaces :workspace active-workspace)
      (empty)
      (empty))
    (box :orientation "h"
               :halign "center"
               :class "middlestuff"
      (day))
    (box :orientation "h"
               :halign "end"
               :class "leftstuff"
               :space-evenly false
      (metric :label volume-label 
              :value volume 
              :value-text "${volume-label}  Volume ${volume}%"
              :onclick volume-toggle
              :onchange volume-set)))))

(defwindow bar-2
           :monitor 1
           :geometry (geometry :x "0%"
                               :y "0%"
                               :width "100%"
                               :height "20px"
                               :anchor "top center")
           :stacking "fg"
           :reserve (struts :distance "40px" :side "top")
           :windowtype "dock"
           :wm-ignore false
           :exclusive true
  (box :orientation "h"
       :class "wrapper"
  (centerbox :orientation "h"
             :class "bar"
    (box :orientation "h"
               :halign "start"
               :class "rightstuff"
      (metric :label ""
              :value "${EWW_RAM.used_mem_perc}" 
              :value-text "   Ram ${round(EWW_RAM.used_mem_perc, 2)}%")
      (metric :label ""
              :value "${EWW_CPU.avg}" 
              :value-text "   CPU ${round(EWW_CPU.avg, 2)}%")
      (metric :label "󰨣"
              :value "${EWW_DISK["/"].used_perc}" 
              :value-text "󰨣   Disk ${round(EWW_DISK["/"].used_perc, 2)}%")
      (empty)
      (empty))
    (box :orientation "h"
         :halign "center"
         :class "middlestuff"
         :space-evenly false
      (box :class "season"
        (season)) 
      (label :tooltip "󱣖  ${temperature}°C -   ${wind}km/h"
           :class "temperature"
           :text "${round(temperature, 0)}󰔄") 
      (label :tooltip "󰖗  ${rain}mm - 󰖌 ${precipitation}mm"
           :class "rain"
           :text "${round(precipitation, 2)}mm"))
    (box :orientation "h"
               :halign "end"
               :class "leftstuff"
      (empty)
      (workspaces :workspace "${active-workspace - 5}")))))

