#!/usr/bin/env bash

if [[ "$?" == 0 ]]; then
    sleep 0.25s
    if [[ "$1" == 'shutdown' ]]; then
        systemctl poweroff
    elif [[ "$1" == 'reboot' ]]; then
        systemctl reboot
    elif [[ "$1" == 'hibernate' ]]; then
        playerctl --all-players stop
        pkill wleave
        sleep 0.5s
        systemctl suspend-then-hibernate
    elif [[ "$1" == 'lock' ]]; then
        pkill wleave
        sleep 0.5s
        ~/.config/sway/lock.sh
    elif [[ "$1" == 'suspend' ]]; then
        playerctl --all-players stop
        pkill wleave
        sleep 0.5s
        systemctl suspend
    elif [[ "$1" == 'logout' ]]; then
        hyprctl dispatch exit none
    fi
else
    exit
fi
