#!/bin/bash

operation="${1}"
WOBSOCK="$XDG_RUNTIME_DIR/wob.sock"
source "${HOME}/.config/de-vars/colors/active/colors.sh"
opacity="BF"

case "$operation" in
  up)
    wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
    ;;&
  down)
    wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
    ;;&
  mute)
    pactl set-sink-mute @DEFAULT_SINK@ toggle
    ;;&
  up|down|mute)
    if [ "$(pactl get-sink-mute @DEFAULT_SINK@)" = "Mute: yes" ];then
      vol_lvl="0"
    else
      vol_lvl="$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed 's/[^0-9]//g')"
    fi
    echo "${vol_lvl}" "${de_color_0}${opacity}" "${de_color_1}${opacity}" "${de_color_2}${opacity}" > "$WOBSOCK"
    paplay "$HOME/.config/sway/assets/sounds/volume.ogg"
    ;;
esac
