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

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
HYPR_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)"
MODE="${1:-wallpaper}"
export HYPR_DIR
export HYPR_SWITCHER_THEME_DIR="$HYPR_DIR/Themes"
export HYPR_SWITCHER_WALLPAPER_DIR="${WALLPAPER_DIR:-$HOME/Bilder/Wallpaper}"

notify() {
    notify-send "AGS Switcher" "$1" >/dev/null 2>&1 || true
}

if ! command -v ags >/dev/null 2>&1; then
    notify "ags ist nicht installiert."
    exit 1
fi

cd "$HYPR_DIR"
ags quit --instance hypr-switcher >/dev/null 2>&1 || true
exec ags run "$HYPR_DIR/ags/switcher.tsx" "$MODE"
