#!/bin/bash

# Get percentage and remove the % sign cleanly
perc=$(upower -i /org/freedesktop/UPower/devices/battery_BAT1 | awk '/percentage/ {gsub("%",""); print $2}')
state=$(upower -i /org/freedesktop/UPower/devices/battery_BAT1 | awk '/state/ {print $2}')

# Check if values are not empty
if [ -z "$perc" ] || [ -z "$state" ]; then
    echo "Battery info unavailable"
    exit 1
fi

# Convert to integer
num=${perc%%.*}  # In case perc is float

if [ "$state" == "charging" ]; then
    echo "󰂄 ${perc}%"
else
    if [ "$num" -gt 95 ]; then
        echo "󰁹 ${perc}%"
    elif [ "$num" -gt 90 ]; then
        echo "󰂂 ${perc}%"
    elif [ "$num" -gt 80 ]; then
        echo "󰂁 ${perc}%"
    elif [ "$num" -gt 70 ]; then
        echo "󰂀 ${perc}%"
    elif [ "$num" -gt 60 ]; then
        echo "󰁿 ${perc}%"
    elif [ "$num" -gt 50 ]; then
        echo "󰁾 ${perc}%"
    elif [ "$num" -gt 40 ]; then
        echo "󰁽 ${perc}%"
    elif [ "$num" -gt 30 ]; then
        echo "󰁼 ${perc}%"
    elif [ "$num" -gt 20 ]; then
        echo "󰁻 ${perc}%"
    elif [ "$num" -gt 10 ]; then
        echo "󰁺 ${perc}%"
    else
        notify-send --urgency=critical -t 2000 "󱃍 low battery, please charge"
        echo "󰂎 ${perc}%"
    fi
fi

