;; The touch panel's on-screen dock — the primary local navigation surface (this
;; device is touched directly, unlike hosts/thin-client, which deliberately has no
;; bars because its primary control is HA/MQTT and wayvnc). Installed to
;; /home/<KIOSK_USERNAME>/.config/eww/eww.yuck by build-touch-panel-iso.sh.
;;
;; Session-scoped, not part of touchpanel-agent, same reasoning as the thin client's
;; now-playing widget: this is compositor UI, not device control, and dies with sway
;; rather than needing a restart-independent lifecycle. The :onclick strings below are
;; fixed constants in this file — nothing from MQTT, HA, or player metadata is ever
;; interpolated into them.

(defpoll active_workspace :interval "1s" :initial "2:home"
  "swaymsg -t get_workspaces | jq -r '.[] | select(.focused) | .name' 2>/dev/null || echo 2:home")

;; Is this panel's microphone being recorded right now — by anything, including a
;; desktop in another room using it as a remote microphone (mic-follow/). A room
;; microphone that can be opened remotely has to say so IN THE ROOM; Home Assistant
;; knowing is not the same as the person standing here knowing.
(defpoll mic_live :interval "2s" :initial "0"
  "mic-in-use 2>/dev/null || echo 0")

(defwidget dock-btn [ws icon label]
  (button :class {active_workspace == ws ? "dock-btn dock-btn-active" : "dock-btn"}
          :onclick "swaymsg workspace ${ws}"
    (box :orientation "vertical" :space-evenly false :spacing 2
      (label :class "dock-icon" :text icon)
      (label :class "dock-label" :text label))))

(defwidget dock-root []
  (box :class "dock-root" :orientation "horizontal" :space-evenly false :spacing 8
       :halign "center" :valign "center"
    (dock-btn :ws "1:spotify" :icon "🎵" :label "Spotify")
    (dock-btn :ws "2:home"    :icon "🏠" :label "Home")
    (dock-btn :ws "3:web"     :icon "🌐" :label "Web")
@DISCORD_DOCK_BTN@    (box :class "dock-sep")
    (button :class "dock-btn" :onclick "toggle-keyboard"
      (box :orientation "vertical" :space-evenly false :spacing 2
        (label :class "dock-icon" :text "⌨")
        (label :class "dock-label" :text "Keyboard")))
    ;; Not a button: nothing to press, it is a statement of fact. It takes no space
    ;; when the microphone is idle.
    (box :class "mic-badge" :visible {mic_live == "1"} :space-evenly false :spacing 4
      (label :class "mic-dot" :text "●")
      (label :class "mic-text" :text "MIC LIVE"))))

;; :exclusive true reserves this strip so it is never overlapped by, and never steals
;; area from behind, the app on screen — unlike the thin client's overlay widgets,
;; which deliberately float over fullscreen video. A dock a finger can miss because
;; something else drew over it is worse than a smaller app area.
(defwindow touch-dock
  :monitor 0
  :geometry (geometry :width "100%" :height "84px" :anchor "bottom center")
  :stacking "overlay"
  :exclusive true
  :focusable false
  (dock-root))
