#!/usr/bin/env sh

# Power menu options with icons
OPTIONS="󰤄  Suspend\n󰍃  Logout\n󰜉  Restart\n󰐥  Shutdown"

# Get selection from argument or rofi menu
if [ -n "$1" ]; then
    CHOICE="$1"
else
    CHOICE=$(echo -e "$OPTIONS" | rofi -dmenu -p "Power Menu:" -theme-str 'window {width: 250px; height: 250px;}')
    # Strip icon from selection (remove everything before and including the first space)
    CHOICE=$(echo "$CHOICE" | sed 's/^[^ ]* *//')
fi

# Execute based on selection
case "$CHOICE" in
    "Suspend")
        systemctl suspend
        ;;
    "Logout")
        swaymsg exit
        ;;
    "Restart")
        systemctl reboot
        ;;
    "Shutdown")
        systemctl poweroff
        ;;
    *)
        # User cancelled or invalid selection
        exit 0
        ;;
esac
