#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"

if pgrep -x wofi >/dev/null; then
    pkill -x wofi
    exit 0
fi

choice="$(
    printf '%s\n' \
        "󰀻  Apps" \
        "󰅩  Dev Menue" \
        "󰒓  Einstellungen" \
        "  Terminal" \
        "  Dateien" \
        "󰑓  Hyprland neu laden" \
        "󰍃  Session beenden" |
        wofi --dmenu --prompt "󰣇  Hauptmenue" --insensitive
)"

case "$choice" in
    *"Apps"*)
        wofi --show drun
        ;;
    *"Dev Menue"*)
        "$SCRIPT_DIR/dev-menu.sh"
        ;;
    *"Einstellungen"*)
        "$SCRIPT_DIR/settings-menu.sh"
        ;;
    *"Terminal"*)
        kitty
        ;;
    *"Dateien"*)
        nautilus
        ;;
    *"Hyprland neu laden"*)
        hyprctl reload
        ;;
    *"Session beenden"*)
        if command -v hyprshutdown >/dev/null 2>&1; then
            hyprshutdown
        else
            hyprctl dispatch exit
        fi
        ;;
esac
