#!/bin/bash
set -euo pipefail
choice=$(printf '%s\n' 'Network' 'Sound' 'Bluetooth' 'Displays' 'Wallpaper' 'Idle timers' \
    'Lock and power' 'Files' 'Desktop configuration' 'Getting started' | \
    fuzzel --dmenu --prompt 'Settings > ') || exit 0
case "$choice" in
    Network) exec /usr/bin/nm-connection-editor ;;
    Sound) exec /usr/bin/pavucontrol ;;
    Bluetooth) exec /usr/bin/blueman-manager ;;
    Displays) exec /usr/bin/wdisplays ;;
    Wallpaper)
        config="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/hyprpaper.conf"
        if [ ! -e "$config" ]; then
            template=/usr/lib/parrot-skel/etc/skel/.config/hypr/hyprpaper.conf
            if [ -f "$template" ]; then
                /usr/bin/install -Dm644 "$template" "$config"
            else
                /usr/bin/install -d "$(dirname "$config")"
                printf '%s\n' 'source = /etc/xdg/hypr/hyprpaper.conf' >"$config"
            fi
        fi
        if /usr/bin/kitty /usr/bin/nano "$config"; then
            /usr/bin/systemctl --user stop hyprpaper.service >/dev/null 2>&1 || true
            /usr/bin/pkill -x hyprpaper >/dev/null 2>&1 || true
            /usr/bin/setsid /usr/bin/hyprpaper >/dev/null 2>&1 &
        fi
        ;;
    'Idle timers')
        config="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/hypridle.settings"
        if [ ! -e "$config" ]; then
            /usr/bin/install -Dm644 /etc/xdg/hypr/hypridle.settings "$config"
        fi
        if /usr/bin/kitty /usr/bin/nano "$config"; then
            /usr/bin/systemctl --user stop hypridle.service >/dev/null 2>&1 || true
            /usr/bin/pkill -x hypridle >/dev/null 2>&1 || true
            /usr/bin/setsid /usr/lib/cyberpunk/autostart idle >/dev/null 2>&1 &
        fi
        ;;
    'Lock and power') exec /usr/bin/cyberpunk-power ;;
    Files) exec /usr/bin/thunar ;;
    'Desktop configuration') exec /usr/bin/kitty /usr/bin/nano "${XDG_CONFIG_HOME:-$HOME/.config}/hypr/local.lua" ;;
    'Getting started') exec cyberpunk-welcome ;;
esac
