(defwindow sidebar
    :geometry (geometry :x "0px"
                        :y "10px"
                        :width "1px"
                        :height "724"
                        :anchor "bottom left")
    :stacking "fg"
    :monitor "0"
(sidebar))

(defwidget sidebar [] 
	(eventbox 
         :class "side_class"
	 :halign "start" 
	 :onhover "${EWW_CMD} update side=true"
	 :onhoverlost "${EWW_CMD} update side=false"
	 (revealer 
	  :transition "slideright"
	  :reveal side 
	  :duration "250ms"
	  (side))))

(defvar side false)

;; background
(defwidget side [] 
           (box 
            :class "side" 
            :orientation "v" 
            :space-evenly "false" 
            :spacing "30"
            :halign "start"
            (fetch)
            (top)
            (system-side)
            (tray))
)

(defwidget top [] 
    (box 
        :orientation "h" 
        :space-evenly "false" 
        :spacing "30" 
        :halign "center"
    (date))
)

;; weather
(defwidget weather [] 
	   (box 
	    :class "weather"  
	    :orientation "v" 
	    :spacing -2 
	    :space-evenly "false" 
	    :vexpand "true" 
	    :hexpand "false" 
	    :valign "start" 
	    :halign "center"
	    (label 
	     :class "iconweather" 
	     :halign "center" 
	     :valign "center" 
	     :style "color: ${HEX};" :text ICON)
	    (button 
	     :onclick "scripts/weather --getdata && eww reload &" 
	     :class "label_temp" 
	     :valign "center" 
	     :halign "center" 
	     "${TEMP}")))

(defwidget date [] 
	   (box :class "date" :orientation "v" :valign "start" :space-evenly "false" :halign "center"
		(label 
		 :text DAY)
		(label 
		 :text POO)
	        (label :class "foo"
	               :text FOO)))

(defpoll FOO :interval "6h"  "date '+%d'")  	
(defpoll DAY :interval "6h" "date '+%A'")
(defpoll POO :interval "6h" "date '+%B'")


;; Weather vars
(defpoll ICON :interval "15m" `scripts/weather --icon`)
(defpoll TEMP :interval "15m" `scripts/weather --temp`)
(defpoll HEX :interval "15m" `scripts/weather --hex`)

;; <-- System -->
(defwidget system-side [] 
	(box 
	    :class "stats-box" 
	    :space-evenly "false" 
	    :width "300px"
	    :orientation "v" 
	    :valign "start" 
	    :halign "center" 
	    :spacing 12
		(box 
		    :class "stats" 
		    :hexpand "false" 
		    :vexpand "false" 
		    :space-evenly "false"
			(label 
			    :tooltip "${round(EWW_CPU.avg, 0)}%" 
			    :class "stats-icon" :text "")
			(scale 
			    :min 0 
			    :max 101 
			    :active false 
			    :value {EWW_CPU.avg} 
			    :class "scale" 
			    :width 280))
		(box 
		    :class "stats" 
		    :hexpand "false" 
		    :vexpand "false" 
		    :space-evenly "false"
			(label 
			    :tooltip "${round(EWW_RAM.used_mem_perc, 0)}%" 
			    :class "stats-icon" 
			    :text "﬙")
			(scale 
			    :min 0 
			    :max 101 
			    :active false 
			    :value {EWW_RAM.used_mem_perc} 
			    :class "scale" 
			    :width 280))
		(box 
		    :class "stats" 
		    :hexpand "false" 
		    :vexpand "false" 
		    :space-evenly "false"
			(label 
			    :tooltip "${round(EWW_DISK["/"].used_perc, 0)}%" 
			    :class "stats-icon" 
			    :text "")
			(scale 
			    :min 0 
			    :max 101 
			    :active false 
			    :value {(EWW_DISK["/"].used / EWW_DISK["/"].total) * 100} 
			    :class "scale" 
			    :width 280))
		;; (box 
		;;     :class "stats" 
		;;     :hexpand "false" 
		;;     :vexpand "false" 
		;;     :space-evenly "false"
		;; 	(label 
		;; 	    :tooltip "${gpu}%" 
		;; 	    :class "stats-icon" 
		;; 	    :text "調")
		;; 	(scale 
		;; 	    :min 0 
		;; 	    :max 101 
		;; 	    :active false 
		;; 	    :value gpu 
		;; 	    :class "scale" 
		;; 	    :width 280))
		(box 
		    :class "stats" 
		    :hexpand "false" 
		    :vexpand "false" 
		    :space-evenly "false"
			(button 
			    :tooltip "${volume_percent}%" 
			    :onclick "amixer set Master toggle" 
			    :onrightclick "alsamixer &" 
			    :class "stats-icon" "墳")
			(scale 
			    :min 0 
			    :max 101 
			    :active true 
			    :value volume_percent
			    :class "scale" 
			    :width 280 
			    :onchange "pamixer --set-volume {}")
			)))

    (deflisten gpu "scripts/gpu")

(defwidget tray []
	(box 
	    :class "buttons" 
	    :orientation "h" 
	    :space-evenly "false" 
	    :halign "center"  
	    :valign "start" 
	    :spacing "2"
	    (button 
	        :class "poweroff" 
	        :halign "center"  
			:tooltip "Shut Down" 
	        :onclick "alacritty poweroff &" "⏻")
	    (button 
	        :class "reboot" 
	        :halign "center"  
			:tooltip "Reboot" 
	        :onclick "alacritty reboot &" "")
	    (button 
	        :class "firmware" 
	        :halign "center"  
			:tooltip "Reboot to EFI" 
	        :onclick "alacritty systemctl reboot --firmware &" "拉")
	    (button 
	        :class "exit" 
	        :halign "center"  
			:tooltip "Quit Hyprland" 
	        :onclick "hyprctl dispatch exit exit" "")
	    (button 
	        :class "restart" 
	        :halign "center"  
			:tooltip "edit Config" 
	        :onclick "emacsclient ~/.config/hypr/hyprland.conf &" "")))

(defpoll uptime :interval "1m" "uptime | awk '{print $3}' | sed 's/,//;s/\(.*\):\(.*\)/\1 h \2 m/")
(defpoll packages :interval "5m" `pacman -Q | wc -l`)
(defpoll kernal :interval "5m" `uname -r`) 
(defpoll name :interval "5m" `whoami`)  
(defpoll host :interval "5m" `uname -n`) 
(defpoll wm :interval "5m" `echo $XDG_CURRENT_DESKTOP`) 

(defwidget fetch []
            (box 
             :class "fetch"  
             :orientation "v" 
             :space-evenly "false" 
             :halign "center"  
             :valign "start" 
             :spacing "10"
             (label 
              :class "host" 
              :halign "start"
              :text " : ${name}@${host}")
             (label 
              :class "wm" 
              :halign "start"
              :text " : ${wm}")
             (label 
              :class "uptime" 
              :halign "start"
              :text " : ${uptime}")
             ;; (label 
             ;;     :class "packages" 
             ;;     :halign "start"
             ;;     :text " : ${packages}")
             (label 
              :class "kernal" 
              :halign "start"
              :text " : ${kernal}")))