#!/usr/bin/env bash

# Launch DIR/gui.py or DIR/tui.py when --gui or --tui is passed

ui=""
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" # to be changed to future install dir

if [[ $script_dir == "/usr/bin" ]]; then
    script_dir="/usr/share/bakery"
fi

while [[ $# -gt 0 ]]; do
    case $1 in
        --gui|--tui)
            ui="${1#--}"
            shift
            ;;
        *)
            echo "Error: Unknown argument $1"
            exit 1
            ;;
    esac
done

if [[ $ui == "gui" || $ui == "tui" ]]; then
    script_name="bakery-$ui.py"
    if [[ -f "$script_dir/$script_name" ]]; then
        python "$script_dir/$script_name"
    else
        echo "Error: bakery-$ui is not installed"
        echo "Please install bakery-$ui with 'sudo pacman -S bakery-$ui'"
        exit 1
    fi
else
    echo "Error: Unknown UI $ui"
fi
