#!/usr/bin/env bash

# Suppress locale-related float warnings
LC_NUMERIC=C

# Get default sink volume info safely
VOL_LINE=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ 2>/dev/null)
if [ -z "$VOL_LINE" ]; then
    echo "🔇 No Sink"
    exit 0
fi

# Extract volume (0.00–1.50 range) and convert to integer percent
VOL=$(echo "$VOL_LINE" | awk '{printf "%d", $2 * 100}')

# Check mute status
MUTE=$(echo "$VOL_LINE" | grep -q "MUTED" && echo yes || echo no)

# Sanitize volume
if [ -z "$VOL" ]; then VOL=0; fi
if [ "$VOL" -gt 150 ]; then VOL=150; fi
if [ "$MUTE" = "yes" ]; then VOL=0; fi

# Choose icon
if [ "$VOL" -eq 0 ]; then
    EMOJI="🔇"
elif [ "$VOL" -le 30 ]; then
    EMOJI="🔈"
elif [ "$VOL" -le 70 ]; then
    EMOJI="🔉"
else
    EMOJI="🔊"
fi

# Output
echo "$EMOJI $VOL%"

