#!/usr/bin/env bash

echo "=============================="
echo "🔊 PulseAudio Devices Checker"
echo "=============================="
echo

# تحقق أن PulseAudio شغال
if ! pactl info >/dev/null 2>&1; then
    echo "❌ PulseAudio is NOT running"
    echo "ℹ️  Use ALSA (hw:X,Y) instead"
    exit 1
fi

echo "✅ PulseAudio is running"
echo

# -------------------------------
# List Sinks (Speakers)
# -------------------------------
echo "🔈 AVAILABLE SINKS (Speakers)"
echo "------------------------------"
pactl list short sinks | awk '{printf "• Name: %-70s | Index: %s\n", $2, $1}'
echo

# -------------------------------
# List Sources (Microphones)
# -------------------------------
echo "🎤 AVAILABLE SOURCES (Microphones)"
echo "----------------------------------"
pactl list short sources | awk '{printf "• Name: %-70s | Index: %s\n", $2, $1}'
echo

# -------------------------------
# Highlight PowerConf if exists
# -------------------------------
echo "🔍 PowerConf Devices Found"
echo "--------------------------"

FOUND=0

pactl list short sinks | grep -i powerconf && FOUND=1
pactl list short sources | grep -i powerconf && FOUND=1

if [ "$FOUND" -eq 0 ]; then
    echo "⚠️ PowerConf NOT found in PulseAudio"
else
    echo "✅ PowerConf detected above"
fi

echo
echo "=============================="
