(deflisten workspaces :initial "[]" "bash ./scripts/get-workspaces")
(deflisten current_workspace :initial "1" "bash ./scripts/get-active-workspace")
(defpoll time :interval "1s" "date '+%d.%m.%Y - %H:%M'")

(defwidget workspaces []
  (eventbox :halign "start"
            :onscroll "bash ${EWW_CONFIG_DIR}/scripts/change-active-workspace {} ${current_workspace}"
            :class "workspaces-widget"
    (box :space-evenly true
      (for workspace in workspaces
        (eventbox :onclick "hyprctl dispatch workspace ${workspace.id}"
          (label :class {workspace.id == current_workspace ? "current" : ""}
                 :text " ${workspace.windows > 0 ? "◆" : "◇"} "))))))
            
(defwidget bar []
  (centerbox :class "bar"
    (workspaces)
    "${time}"
    (box :halign "end"
         :space-evenly true
         :width "150"
      "󰁹 ${EWW_BATTERY["BAT1"].capacity}%"
      "󰍛 ${round(EWW_RAM.used_mem_perc, 0)}%"
      "󰻠 ${round(EWW_CPU.avg, 0)}%")))

(defwindow bar
  :monitor 0
  :geometry (geometry :x 0 :y 0 :width "100%" :height "30px" :anchor "top center")
  :stacking "fg"
  :exclusive true
  (bar))