#!/usr/bin/env bash
# fws-dnd — Gestionnaire D&D 5e pour FWS (application GTK4)
set -u

case "${1:-}" in
    -h|--help)
        cat <<EOF
fws-dnd — Gestionnaire D&D 5e (FWS)

Usage : fws-dnd
Ouvre l'application (dés, personnages, grimoire, sessions, combat).

Données utilisateur : ~/.local/share/fws-dnd/data.json
Variable : FWS_DND_DIR (répertoire contenant le paquet Python fwsdnd,
           pour le mode développement)
EOF
        exit 0 ;;
esac

# Répertoire du module Python : installé, ou relatif au script (mode dev)
if [[ -n "${FWS_DND_DIR:-}" && -d "${FWS_DND_DIR}/fwsdnd" ]]; then
    MOD_DIR="$FWS_DND_DIR"
elif [[ -d /usr/share/fws-dnd/fwsdnd ]]; then
    MOD_DIR=/usr/share/fws-dnd
else
    SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"
    if [[ -d "$SCRIPT_DIR/../gui/fwsdnd" ]]; then
        MOD_DIR="$(readlink -f "$SCRIPT_DIR/../gui")"
    else
        echo "fws-dnd : application introuvable (/usr/share/fws-dnd manquant)." >&2
        exit 1
    fi
fi

export PYTHONPATH="${MOD_DIR}${PYTHONPATH:+:$PYTHONPATH}"
exec python3 -m fwsdnd "$@"
