#!/bin/bash

# 獲取預設輸出裝置的音量資訊 (輸出範例: Volume: 0.50 [MUTED])
GET_VOL=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)

# 提取數值並轉換為百分比 (0-100)
# 使用 printf %.0f 將小數四捨五入為整數
VOL=$(echo "$GET_VOL" | awk '{print $2 * 100}' | xargs printf "%.0f")

if [ "$1" == "get" ]; then
  echo "$VOL"
elif [ "$1" == "icon" ]; then
  # 檢查是否含有 [MUTED] 字樣
  if echo "$GET_VOL" | grep -q "\[MUTED\]"; then
    echo "🔇"
  else
    if [ "$VOL" -gt 60 ]; then echo "🔊";
    elif [ "$VOL" -gt 30 ]; then echo "🔉";
    else echo "🔈"; fi
  fi
fi
