#!/usr/bin/env bash

ui=""
extra_args=()
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

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

while [[ $# -gt 0 ]]; do
    case $1 in
        --gui|--tui)
            ui="${1#--}"
            shift
            ;;
        --simple)
            ui="tui"
            extra_args+=("--simple")
            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" "${extra_args[@]}"
    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: No UI specified."
    exit 1
fi
