#!/usr/bin/env bash

menulist() {
    # Args: menu options.
    # returns: selected tag
    local i
    local menuList
    for i in $@ ; do
        menuList+=("$i" "$i")
    done
    dialog --backtitle "Select a Slay the Spire profile." \
        --clear \
        --no-tags \
        --menu "$(gettext "Please select one")" 0 0 0 "${menuList[@]}" --stdout
    if [[ $? -ne 1 ]]; then
        exit 0
    fi
}

# Create a list of profiles
profiles=($(jq -r '.lists | keys[]' "${HOME}/.config/ModTheSpire/mod_lists.json"))

if [[ "${#profiles[@]}" -ne 1 ]]; then
    currentProfile="$(menulist "${profiles[@]}")"
else
    currentProfile="Default"
fi

pushd "${HOME}/.local/games/SlayTheSpire"
./MTS.sh --profile "$currentProfile"
popd

exit 0