(defwidget central [] 
  (box :class "central-widget" :space-evenly false :orientation "v" :spacing 10
    (box-profile)
    (box-calendar)
    (box-system)
    (music)
  )
)

(defwidget box-profile []
  (box
    :class "box-profile"
    :space-evenly false
    :hexpand false
    :spacing 10
      (box  :class "profile" 
        :style "background-image: url('${perfil}')"
        :valign "start"
      )
      (box 
        :class "box-about"
        :halign "start"
        :spacing 5
	    (box
	      :orientation "v" :space-evenly false :halign "start"
          (label :class "name" :halign "start"  :text {name})
	        (label :class "wm"   :halign "start"  :text {wm})
        (box
          (label :class "uptime"  :text `Uptime: ${uptime}`)
        )))
    (box 
    :halign "end"
    :valign "center"
    :hexpand true
    :spacing 10
      (eventbox
      :cursor "pointer"
        (button
        :class "lock"
        :onclick "poweroff&"
        ""
        ))
      (eventbox
        :cursor "pointer"
          (button
          :class "exit"
          :onclick "eww open --toggle powercontrol && eww close central"
          "⏻" 
  )))))

(defwidget box-system []
  (box 
    :class "system"
    :spacing 10
    (ram)
    (cpu)
    (temp)
    (disk)
  )
)

(defwidget system_progress [data icon css tip] 
  (box 
    :class "progress" 
    (circular-progress
      :class css
      :value data
      :thickness 7
      :tooltip tip
      (overlay
        :valign "center"
        (label 
          :class "icon" 
          :text icon
        )
      )
    )
  )
)


(defwidget cpu [] 
  (system_progress
    :css "cpu"
    :tip "CPU ${round(EWW_CPU.avg,0)}%"
    :data {round(EWW_CPU.avg, 0)} 
    :icon "󰻠"
  )
)

(defwidget ram [] 
  (system_progress
    :css "ram"
    :tip "RAM ${round(EWW_RAM.used_mem / 1048576, 2)}MB"
    :data {round(EWW_RAM.used_mem_perc, 0)}
    :icon "󰍛"
  )
)

(defwidget temp [] 
  (system_progress
    :css "temp"
    :tip "Temperature ${EWW_TEMPS["AMDGPU_EDGE"]}°C"
    :data {round(EWW_TEMPS.AMDGPU_EDGE, 0)} 
    :icon "󰔄"
  )
)

(defwidget disk [] 
  (system_progress
    :css "disk"
    :tip "SSD ${round(EWW_DISK["/"].used_perc, 2)}%"
    :data {round(EWW_DISK["/"].used_perc, 0)}
    :icon "󰗮"
  )
)


(defwidget music []
  (box
    :class "music"
    :space-evenly false
    :spacing 15
    :halign "start"
    (box
      :class "player-art"
			:style "background-image: url('${music-art}')"
    )
    (box
      :class "player-info"
      :space-evenly false
      :orientation "v"
        (label :class "player-title"  :halign "start" :valign "center" :text music-title  :limit-width 30 )
        (label :class "player-artist" :halign "start" :valign "center" :text music-artist :limit-width 30 )
        (box
					:space-evenly false
					:orientation "v"
					:valign "end"
					(box 
						:class "player-bar" 
						:halign "center" 
						:valign "end"
            :hexpand true
						(eventbox
							:cursor "pointer"
							(scale 
								:onchange "playerctl -p spotify position {}"
								:min 0 
								:max music-lengths 
								:value music-positions
							)
						)
					)
					(box 
						:class "player-position" 
						:space-evenly true 
						:valign "start"

						(label 
							:class "player-time"
              :halign "start"
							:text "${music-position} / ${music-length}"
						)
          (box 
			      :class "player-controls" 
			      :valign "center"
			      :space-evenly false
            :halign "end"
			      :spacing 10
			        (eventbox
				        :cursor "pointer"
				        (button 
					        :class "player-previous" 
					        :onclick "scripts/mediacontrol --previous" 
					      ""
				)
			)
			(eventbox
				:cursor "pointer"
				(button 
					:class "player-toggle" 
					:onclick "scripts/mediacontrol --toggle" 
					music-toggle
				)
			)
			(eventbox
				:cursor "pointer"
				(button 
					:class "player-next" 
					:onclick "scripts/mediacontrol --next" 
					""
				)
			)
		)	)
				)
			)
    )
)

(defwidget box-calendar []
	(box 
		:class "calendar-main-box" 
		:space-evenly false 
		:orientation "v" 
		:spacing 20
			(box 
				:class "date" 
				:space-evenly false 
				:orientation "v"
				(box 
					:space-evenly false 
					:halign "center" 
					:spacing 10
					(label 
						:class "time" 
						:text hour)
						(box 
							:class "timeboxes" 
							:space-evenly false 
							:valign "center" 
							:orientation "v" 
							:spacing 5
							(box 
								:class "timebox-1" 
								"󰝤"
							)
							(box 
								:class "timebox green" 
								"󰝤"
							)
						)
					(label 
						:class "time" 
						:text minute
					)
				)
				(box 
					:halign "center" 
					:valign "start"
					(label 
						:class "today" 
						:text date
					)
				)
			)
		(box 
			:class "cal" 
			:orientation "v"
			(box 
				:class "cal-inner-box"
				(calendar 
					:class "calendar" 
					:day calendar-day 
					:month calendar-month 
					:year calendar-year
					:show-day-names true
					:show-heading true
					:show-details true
				)
			)
		)
	)
)

(defwindow central 
  :monitor 0
  :geometry (geometry :x "-1%"
                      :y "0%"
                      :height "85%"
                      :anchor "center left")
  :reserve (struts :side "top" :distance "4%")
  (central))
