#!/bin/bash

icon_dir="$HOME/.config/bspwm/assets/icons"
steps=5

send_notification () {
  brightness=$(brightnessctl i | grep -oP '\(\K[^%\)]+')

    if [ $brightness -lt "15" ]; then
        icon="$icon_dir/brightness-1.svg"
    elif [ $brightness -lt "30" ]; then
        icon="$icon_dir/brightness-2.svg"
    elif [ $brightness -lt "45" ]; then
        icon="$icon_dir/brightness-3.svg"
    elif [ $brightness -lt "60" ]; then
        icon="$icon_dir/brightness-4.svg"
    elif [ $brightness -lt "75" ]; then
        icon="$icon_dir/brightness-5.svg"
    elif [ $brightness -lt "90" ]; then
        icon="$icon_dir/brightness-6.svg"
    else
        icon="$icon_dir/brightness-7.svg"
    fi

    notify-send -a Brightness -i $icon -t 2000 -r 969696 "Brightness : $brightness"
}

docs () {
	echo "
Usage:	brightness [Options]
    
Options:
    up      -   Increase the brightness
    down    -   Decrease the brightness
	"
}

case $1 in
    up)
        brightnessctl set "${steps:-5}%+" -q
        send_notification
    ;;
    down)
        brightnessctl set "${steps:-5}%-" -q
        send_notification
    ;;
    *)
        docs
    ;;
esac
