;; Définition de la fenêtre principale
(defwindow control_center
  :monitor 0
  :geometry (geometry :x "8px"
                     :y "42px"
                     :width "280px"
                     :height "400px"
                     :anchor "top right")
  :stacking "fg"
  :exclusive false
  (control_center_widget))

;; Widget principal qui organise tous nos contrôles
(defwidget control_center_widget []
  (box :class "control-center"
       :orientation "v"
       :space-evenly false
    
    ;; En-tête avec le titre
    (box :class "header"
         :orientation "h"
         :space-evenly false
      (label :text "Control Center")
      (button :onclick "eww close control_center"
              :class "close-button"
        "×"))
    
    ;; Section des curseurs
    (box :class "section sliders-box"
         :orientation "v"
         :spacing 10
      (volume-slider)
      (brightness-slider))
    
    ;; Section d'information système
    (box :class "section system-info"
         :orientation "v"
         :spacing 5
      (cpu-info)
      (memory-info)
      (battery-info))))

;; Widgets individuels pour chaque contrôle
(defwidget volume-slider []
  (box :class "slider"
       :orientation "h"
       :space-evenly false
    (button :onclick "pactl set-sink-mute @DEFAULT_SINK@ toggle"
            :class "icon ${volume-muted ? 'muted' : ''}"
      {volume-muted ? "󰝟" : "󰕾"})
    (scale :min 0
           :max 101
           :value volume
           :onchange "pactl set-sink-volume @DEFAULT_SINK@ {}%")))

(defwidget brightness-slider []
  (box :class "slider"
       :orientation "h"
       :space-evenly false
    (label :class "icon" :text "")
    (scale :min 0
           :max 101
           :value brightness
           :onchange "brightnessctl set {}%")))

(defwidget cpu-info []
  (box :class "system-info-item"
       :orientation "h"
       :space-evenly false
    (label :class "icon" :text "󰻠")
    (label :text "CPU: ${cpu}%")
    (progress :value cpu
              :class "progress-bar")))

(defwidget memory-info []
  (box :class "system-info-item"
       :orientation "h"
       :space-evenly false
    (label :class "icon" :text "󰍛")
    (label :text "RAM: ${memory}%")
    (progress :value memory
              :class "progress-bar")))

(defwidget battery-info []
  (box :class "system-info-item"
       :orientation "h"
       :space-evenly false
    (label :class "icon" :text {battery-icon})
    (label :text "Battery: ${battery}%")
    (progress :value battery
              :class "progress-bar")))

;; Variables pour les écouteurs d'événements
(deflisten volume :initial "0"
  "scripts/get-volume.sh")

(deflisten volume-muted :initial "false"
  "scripts/get-mute-state.sh")

(deflisten brightness :initial "0"
  "scripts/get-brightness.sh")

(deflisten cpu :initial "0"
  "scripts/get-cpu.sh")

(deflisten memory :initial "0"
  "scripts/get-memory.sh")

(deflisten battery :initial "0"
  "scripts/get-battery.sh")

(deflisten battery-icon :initial ""
  "scripts/get-battery-icon.sh")"
