#!/usr/bin/env bash

# TODO extremely unfinished

. common

if ! grep -qi "Ubuntu" /proc/version ; then
    $DIALOG --title "WARNING" --msgbox "The script has detected that you are not using Ubuntu.\n\
While cathook can work on most distros, most helper scripts can work incorrectly or not work at all and you may also have trouble with compiling cathook here.\n\n\
If you have trouble, you can visit cathook's official telegram channel and ask for help from other users of your distro there." 15 50
fi

USER=$($DIALOG --title "Main Menu (WIP)" --menu "What do you want to do?" 20 60 12 \
    "DEP" "| Check requirements (Ubuntu)" \
    "CAT" "| Install libglez and libxoverlay" \
    "INS" "| Install libraries (Ubuntu)" \
    "BLD" "| Build" \
    "INJ" "| Inject" \
    "FIX" "| Troubleshoot (WIP)" \
    "BUG" "| Suggestion or bug report" \
    "TGA" "| Join announcements channel in Telegram" \
    "TGB" "| Join community channel in Telegram" \
    "PAT" "| Support the creator" \
    "FMT" "| Format sources" \
    "UPD" "| Update" 3>&1 1>&2 2>&3)
    
case "$USER" in
    "DEP")
        . depcheck
        exit
        ;;
    "CAT")
        . catlibs
        exit
        ;;
    "INS")
        . depinstall
        exit
        ;;
    "BLD")
        . build
        exit
        ;;
    "INJ")
        . inject
        exit
        ;;
    "FIX")
        . troubleshoot
        exit
        ;;
    "BUG")
        xdg-open https://github.com/nullifiedcat/cathook/issues >/dev/null 2>&1 &
        exit
        ;;
    "TGA")
        xdg-open tg://resolve?domain=cathook_cheat >/dev/null 2>&1 &
        exit
        ;;
    "TGB")
        xdg-open tg://resolve?domain=nullifiedcat >/dev/null 2>&1 &
        exit
        ;;
    "PAT")
        xdg-open https://patreon.com/nullifiedcat >/dev/null 2>&1 &
        exit
        ;;
    "FMT")
        . format
        exit
        ;;
    "UPD")
        . update
        exit
        ;;
esac