#!/bin/bash

# JJManager Installer for Linux
# Usage: ./JJManager-Linux-Installer.sh
# Cross-platform: Works on x64 and ARM64

set -e

# Colors
BLUE='\033[0;36m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'

# ============================================================================
# i18n - Internationalization
# ============================================================================

# Detect system language
SYS_LANG="${LANG:-en_US.UTF-8}"
RECOMMENDED_LANG="en-US"

if [[ "$SYS_LANG" == pt_* ]] || [[ "$SYS_LANG" == pt-* ]]; then
    RECOMMENDED_LANG="pt-BR"
elif [[ "$SYS_LANG" == es_* ]] || [[ "$SYS_LANG" == es-* ]]; then
    RECOMMENDED_LANG="es-ES"
fi

# Ask user for language preference if not specified
if [[ -z "$LANG_OVERRIDE" ]]; then
    echo ""
    echo -e "${BLUE}╔════════════════════════════════════════════════════════════════╗${NC}"
    echo -e "${BLUE}║               SELECT LANGUAGE / SELECIONE IDIOMA               ║${NC}"
    echo -e "${BLUE}╚════════════════════════════════════════════════════════════════╝${NC}"
    echo ""

    if [[ "$RECOMMENDED_LANG" == "pt-BR" ]]; then
        echo -e "  ${GREEN}1. Português (Brasil) [RECOMENDADO]${NC}"
    else
        echo "  1. Português (Brasil)"
    fi

    if [[ "$RECOMMENDED_LANG" == "en-US" ]]; then
        echo -e "  ${GREEN}2. English (United States) [RECOMMENDED]${NC}"
    else
        echo "  2. English (United States)"
    fi

    if [[ "$RECOMMENDED_LANG" == "es-ES" ]]; then
        echo -e "  ${GREEN}3. Español (España) [RECOMENDADO]${NC}"
    else
        echo "  3. Español (España)"
    fi

    echo ""
    read -p "Enter your choice (1-3) [Press Enter for recommended]: " choice

    case "$choice" in
        1) LANGUAGE="pt-BR" ;;
        2) LANGUAGE="en-US" ;;
        3) LANGUAGE="es-ES" ;;
        "") LANGUAGE="$RECOMMENDED_LANG" ;;
        *) LANGUAGE="$RECOMMENDED_LANG" ;;
    esac
else
    LANGUAGE="$LANG_OVERRIDE"
fi

# Translation function
t() {
    local key="$1"
    shift
    local text=""

    case "$LANGUAGE" in
        "pt-BR")
            case "$key" in
                "title") text="JJManager Installer para Linux" ;;
                "subtitle") text="Gerenciador de Dispositivos JohnJohn 3D" ;;
                "starting") text="Iniciando instalação..." ;;
                "target") text="Destino da instalação: %s (sem sudo)" ;;
                "dirs_created") text="Diretórios de instalação criados" ;;
                "downloading_meta") text="Baixando metadados da release..." ;;
                "meta_downloaded") text="Metadados baixados (Versão: %s)" ;;
                "meta_failed") text="Falha ao baixar metadados" ;;
                "parse_failed") text="Falha ao processar metadados" ;;
                "downloading") text="Baixando JJManager %s..." ;;
                "download_url") text="URL de download: %s" ;;
                "downloaded") text="Download concluído (%s)" ;;
                "download_failed") text="Falha ao baixar JJManager" ;;
                "detecting") text="Detectando arquitetura..." ;;
                "arch_detected") text="Arquitetura detectada: %s" ;;
                "extracting") text="Extraindo arquivos..." ;;
                "extracting_platform") text="Extraindo binários %s..." ;;
                "extracted") text="Binários extraídos" ;;
                "extract_failed") text="Falha ao extrair arquivos" ;;
                "platform_not_found") text="Binários da plataforma não encontrados no arquivo" ;;
                "creating_launcher") text="Criando script launcher..." ;;
                "launcher_created") text="Launcher criado: %s" ;;
                "creating_desktop") text="Criando entrada desktop..." ;;
                "desktop_created") text="Entrada desktop criada" ;;
                "configuring_env") text="Configurando ambiente..." ;;
                "path_exists") text="Já está no PATH" ;;
                "path_instructions") text="Adicione ao PATH manualmente:" ;;
                "checking_deps") text="Verificando dependências..." ;;
                "xdotool_found") text="xdotool encontrado (macros habilitados)" ;;
                "xdotool_missing") text="xdotool não encontrado - instalando (necessário para macros)..." ;;
                "xdotool_installed") text="xdotool instalado com sucesso" ;;
                "xdotool_manual") text="Instale xdotool manualmente para suporte a macros: sudo apt install xdotool" ;;
                "creating_uninstaller") text="Criando desinstalador..." ;;
                "uninstaller_created") text="Desinstalador criado" ;;
                "success") text="JJManager %s instalado com sucesso!" ;;
                "details") text="Detalhes da instalação:" ;;
                "location") text="Localização: %s" ;;
                "version") text="Versão: %s" ;;
                "launcher") text="Launcher: %s" ;;
                "next_steps") text="Próximos passos:" ;;
                "step1") text="1. Reinicie seu terminal ou execute: source ~/.bashrc" ;;
                "step2") text="2. Execute: jjmanager" ;;
                "step3") text="3. Ou: %s" ;;
                "uninstall") text="Para desinstalar:" ;;
                "help_usage") text="USO:" ;;
                "help_desc") text="Instala JJManager automaticamente em ~/.local/share/jjmanager" ;;
                "help_no_sudo") text="Sem necessidade de sudo" ;;
                *) text="$key" ;;
            esac
            ;;
        "es-ES")
            case "$key" in
                "title") text="Instalador de JJManager para Linux" ;;
                "subtitle") text="Administrador de Dispositivos JohnJohn 3D" ;;
                "starting") text="Iniciando instalación..." ;;
                "target") text="Destino de instalación: %s (sin sudo)" ;;
                "dirs_created") text="Directorios de instalación creados" ;;
                "downloading_meta") text="Descargando metadatos de la versión..." ;;
                "meta_downloaded") text="Metadatos descargados (Versión: %s)" ;;
                "meta_failed") text="Error al descargar metadatos" ;;
                "parse_failed") text="Error al procesar metadatos" ;;
                "downloading") text="Descargando JJManager %s..." ;;
                "download_url") text="URL de descarga: %s" ;;
                "downloaded") text="Descarga completada (%s)" ;;
                "download_failed") text="Error al descargar JJManager" ;;
                "detecting") text="Detectando arquitectura..." ;;
                "arch_detected") text="Arquitectura detectada: %s" ;;
                "extracting") text="Extrayendo archivos..." ;;
                "extracting_platform") text="Extrayendo binarios %s..." ;;
                "extracted") text="Binarios extraídos" ;;
                "extract_failed") text="Error al extrair archivos" ;;
                "platform_not_found") text="Binarios de la plataforma no encontrados en el archivo" ;;
                "creating_launcher") text="Creando script launcher..." ;;
                "launcher_created") text="Launcher creado: %s" ;;
                "creating_desktop") text="Creando entrada desktop..." ;;
                "desktop_created") text="Entrada desktop creada" ;;
                "configuring_env") text="Configurando entorno..." ;;
                "path_exists") text="Ya está en el PATH" ;;
                "path_instructions") text="Añada al PATH manualmente:" ;;
                "checking_deps") text="Verificando dependencias..." ;;
                "xdotool_found") text="xdotool encontrado (macros habilitados)" ;;
                "xdotool_missing") text="xdotool no encontrado - instalando (necesario para macros)..." ;;
                "xdotool_installed") text="xdotool instalado con éxito" ;;
                "xdotool_manual") text="Instale xdotool manualmente para soporte de macros: sudo apt install xdotool" ;;
                "creating_uninstaller") text="Creando desinstalador..." ;;
                "uninstaller_created") text="Desinstalador creado" ;;
                "success") text="¡JJManager %s instalado con éxito!" ;;
                "details") text="Detalles de la instalación:" ;;
                "location") text="Ubicación: %s" ;;
                "version") text="Versión: %s" ;;
                "launcher") text="Launcher: %s" ;;
                "next_steps") text="Próximos pasos:" ;;
                "step1") text="1. Reinicie su terminal o ejecute: source ~/.bashrc" ;;
                "step2") text="2. Ejecute: jjmanager" ;;
                "step3") text="3. O: %s" ;;
                "uninstall") text="Para desinstalar:" ;;
                "help_usage") text="USO:" ;;
                "help_desc") text="Instala JJManager automáticamente en ~/.local/share/jjmanager" ;;
                "help_no_sudo") text="Sin necesidad de sudo" ;;
                *) text="$key" ;;
            esac
            ;;
        "en-US"|*)
            case "$key" in
                "title") text="JJManager Installer for Linux" ;;
                "subtitle") text="JohnJohn 3D Device Manager" ;;
                "starting") text="Starting installation..." ;;
                "target") text="Installation target: %s (no sudo required)" ;;
                "dirs_created") text="Installation directories created" ;;
                "downloading_meta") text="Downloading release metadata..." ;;
                "meta_downloaded") text="Metadata downloaded (Version: %s)" ;;
                "meta_failed") text="Failed to download metadata" ;;
                "parse_failed") text="Failed to parse metadata" ;;
                "downloading") text="Downloading JJManager %s..." ;;
                "download_url") text="Download URL: %s" ;;
                "downloaded") text="Downloaded (%s)" ;;
                "download_failed") text="Failed to download JJManager" ;;
                "detecting") text="Detecting architecture..." ;;
                "arch_detected") text="Architecture detected: %s" ;;
                "extracting") text="Extracting files..." ;;
                "extracting_platform") text="Extracting %s binaries..." ;;
                "extracted") text="Binaries extracted" ;;
                "extract_failed") text="Failed to extract files" ;;
                "platform_not_found") text="Platform binaries not found in archive" ;;
                "creating_launcher") text="Creating launcher script..." ;;
                "launcher_created") text="Launcher created: %s" ;;
                "creating_desktop") text="Creating desktop entry..." ;;
                "desktop_created") text="Desktop entry created" ;;
                "configuring_env") text="Configuring environment..." ;;
                "path_exists") text="Already in PATH" ;;
                "path_instructions") text="Add to PATH manually:" ;;
                "checking_deps") text="Checking dependencies..." ;;
                "xdotool_found") text="xdotool found (macro support enabled)" ;;
                "xdotool_missing") text="xdotool not found - installing (required for macros)..." ;;
                "xdotool_installed") text="xdotool installed successfully" ;;
                "xdotool_manual") text="Install xdotool manually for macro support: sudo apt install xdotool" ;;
                "creating_uninstaller") text="Creating uninstaller..." ;;
                "uninstaller_created") text="Uninstaller created" ;;
                "success") text="JJManager %s installed successfully!" ;;
                "details") text="Installation details:" ;;
                "location") text="Location: %s" ;;
                "version") text="Version: %s" ;;
                "launcher") text="Launcher: %s" ;;
                "next_steps") text="Next steps:" ;;
                "step1") text="1. Restart your terminal or run: source ~/.bashrc" ;;
                "step2") text="2. Run: jjmanager" ;;
                "step3") text="3. Or: %s" ;;
                "uninstall") text="To uninstall:" ;;
                "help_usage") text="USAGE:" ;;
                "help_desc") text="Installs JJManager automatically to ~/.local/share/jjmanager" ;;
                "help_no_sudo") text="No sudo required" ;;
                *) text="$key" ;;
            esac
            ;;
    esac

    # Apply format string arguments if provided
    if [[ $# -gt 0 ]]; then
        printf "$text" "$@"
    else
        echo "$text"
    fi
}

# Functions
write_status() {
    local timestamp=$(date '+%H:%M:%S')
    echo -n -e "[${BLUE}${timestamp}${NC}] $1"
}

write_success() {
    echo -e " ${GREEN}OK${NC}"
    local timestamp=$(date '+%H:%M:%S')
    echo -e "[${BLUE}${timestamp}${NC}] $1"
}

write_info() {
    local timestamp=$(date '+%H:%M:%S')
    echo -e "[${BLUE}${timestamp}${NC}] ${BLUE}INFO${NC} - $1"
}

write_error() {
    local timestamp=$(date '+%H:%M:%S')
    echo -e "[${BLUE}${timestamp}${NC}] ${RED}ERROR${NC} - $1"
}

# Install xdotool (required for JJSD-01 macros on Linux)
install_xdotool() {
    if command -v xdotool &>/dev/null; then
        write_success "$(t 'xdotool_found')"
        return 0
    fi

    write_info "$(t 'xdotool_missing')"

    if ! command -v sudo &>/dev/null; then
        write_info "$(t 'xdotool_manual')"
        return 0
    fi

    if command -v apt-get &>/dev/null; then
        sudo apt-get install -y xdotool 2>/dev/null && write_success "$(t 'xdotool_installed')" || write_info "$(t 'xdotool_manual')"
    elif command -v dnf &>/dev/null; then
        sudo dnf install -y xdotool 2>/dev/null && write_success "$(t 'xdotool_installed')" || write_info "$(t 'xdotool_manual')"
    elif command -v pacman &>/dev/null; then
        sudo pacman -S --noconfirm xdotool 2>/dev/null && write_success "$(t 'xdotool_installed')" || write_info "$(t 'xdotool_manual')"
    elif command -v zypper &>/dev/null; then
        sudo zypper install -y xdotool 2>/dev/null && write_success "$(t 'xdotool_installed')" || write_info "$(t 'xdotool_manual')"
    else
        write_info "$(t 'xdotool_manual')"
    fi
}

# Download helper: uses curl if available, falls back to wget
http_get() {
    local url="$1" output="$2" progress="${3:-false}"
    if command -v curl &>/dev/null; then
        if [[ "$progress" == "true" ]]; then
            curl -L --fail "$url" -o "$output" -#
        else
            local ef; ef=$(mktemp)
            if ! curl -s --fail "$url" -o "$output" 2>"$ef"; then
                [[ -s "$ef" ]] && write_error "curl: $(cat "$ef")"
                rm -f "$ef"; return 1
            fi
            rm -f "$ef"
        fi
    elif command -v wget &>/dev/null; then
        if [[ "$progress" == "true" ]]; then
            wget --show-progress -O "$output" "$url"
        else
            wget -q -O "$output" "$url" || return 1
        fi
    else
        write_error "curl ou wget não encontrado. Instale com: sudo apt install curl"
        return 1
    fi
}

# Show help
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
    t "title"
    echo ""
    t "help_usage"
    echo "    ./JJManager-Linux-Installer.sh"
    echo ""
    t "help_desc"
    t "help_no_sudo"
    exit 0
fi

TITLE_TEXT=$(t "title")
SUBTITLE_TEXT=$(t "subtitle")

echo -e "${BLUE}╔════════════════════════════════════════════════════════════════╗${NC}"
printf "${BLUE}║%-64s║${NC}\n" "        $TITLE_TEXT"
printf "${BLUE}║%-64s║${NC}\n" "        $SUBTITLE_TEXT"
echo -e "${BLUE}╚════════════════════════════════════════════════════════════════╝${NC}"
echo ""

write_status "$(t 'starting')"
echo ""

# Setup installation directories following XDG Base Directory spec
INSTALL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/jjmanager"
BIN_DIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
DESKTOP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/applications"

write_info "$(t 'target' "$INSTALL_DIR")"

# Create directories
mkdir -p "$INSTALL_DIR"
mkdir -p "$BIN_DIR"
mkdir -p "$DESKTOP_DIR"

write_success "$(t 'dirs_created')"

# Check/install dependencies
echo ""
write_status "$(t 'checking_deps')"
echo ""
install_xdotool

# Download metadata
echo ""
write_status "$(t 'downloading_meta')"
echo ""

METADATA_URL="https://johnjohn3d.com.br/common/versioncontrol/softwares/apps/jjmanager_v2.json"
TEMP_METADATA=$(mktemp)

if ! http_get "$METADATA_URL" "$TEMP_METADATA"; then
    write_error "$(t 'meta_failed')"
    rm -f "$TEMP_METADATA"
    exit 1
fi

# Parse JSON with improved regex patterns
LATEST_VERSION=$(grep -Po '"last_version"\s*:\s*"\K[^"]+' "$TEMP_METADATA" | head -1)
# Extract linux-x64 update URL (python3/python preferred; fallback to grep)
_PYEXE=$(command -v python3 2>/dev/null || command -v python 2>/dev/null || true)
DOWNLOAD_URL=$([[ -n "$_PYEXE" ]] && "$_PYEXE" -c "
import json, sys
data = json.load(open('$TEMP_METADATA'))
sw = data['items']['software'][0]
print(sw['platforms']['linux-x64']['update'])
" 2>/dev/null || grep -A2 '"linux-x64"' "$TEMP_METADATA" | grep -Po '"update"\s*:\s*"\K[^"]+')
FILE_NAME=$(basename "$DOWNLOAD_URL")

if [[ -z "$LATEST_VERSION" ]] || [[ -z "$DOWNLOAD_URL" ]] || [[ -z "$FILE_NAME" ]]; then
    write_error "$(t 'parse_failed')"
    rm -f "$TEMP_METADATA"
    exit 1
fi

write_success "$(t 'meta_downloaded' "$LATEST_VERSION")"
rm -f "$TEMP_METADATA"

# Detect architecture
echo ""
write_status "$(t 'detecting')"
echo ""

ARCH=$(uname -m)
case $ARCH in
    x86_64)
        PLATFORM="linux-x64"
        ;;
    aarch64)
        PLATFORM="linux-arm64"
        DOWNLOAD_URL=$(echo "$DOWNLOAD_URL" | sed 's/linux-x64/linux-arm64/g')
        FILE_NAME=$(basename "$DOWNLOAD_URL")
        ;;
    armv7l)
        PLATFORM="linux-arm64"
        DOWNLOAD_URL=$(echo "$DOWNLOAD_URL" | sed 's/linux-x64/linux-arm64/g')
        FILE_NAME=$(basename "$DOWNLOAD_URL")
        write_info "Detected ARMv7 - using ARM64 binaries"
        ;;
    *)
        write_error "Unsupported architecture: $ARCH"
        exit 1
        ;;
esac

write_success "Architecture: $ARCH ($PLATFORM)"

# Download TAR.GZ
echo ""
write_status "Downloading JJManager $LATEST_VERSION..."
echo ""

ARCHIVE_PATH="/tmp/$FILE_NAME"

if [[ -f "$ARCHIVE_PATH" ]]; then
    rm -f "$ARCHIVE_PATH"
fi

write_info "Download URL: $DOWNLOAD_URL"
echo ""

if ! http_get "$DOWNLOAD_URL" "$ARCHIVE_PATH" true; then
    write_error "Failed to download JJManager"
    exit 1
fi

echo ""

ARCHIVE_SIZE=$(du -h "$ARCHIVE_PATH" | cut -f1)
write_success "Downloaded ($ARCHIVE_SIZE)"

# Extract TAR.GZ
echo ""
write_status "Extracting files..."
echo ""

# Use gunzip + tar separately so "trailing garbage" warnings from gzip
# (common with Windows-generated archives) don't abort the extraction.
if ! { gzip -dc "$ARCHIVE_PATH" 2>/dev/null | tar x -C "$INSTALL_DIR"; }; then
    write_error "Failed to extract archive"
    rm -f "$ARCHIVE_PATH"
    exit 1
fi

rm -f "$ARCHIVE_PATH"

# Make executables
chmod +x "$INSTALL_DIR/JJManager" "$INSTALL_DIR/JJManager.Launcher" 2>/dev/null || true

write_success "Files extracted"

# Try to setup udev rules now if sudo is available; otherwise the launcher handles it on first run
UDEV_RULE_FILE="/etc/udev/rules.d/99-jjmanager-hid.rules"
UDEV_RULE_CONTENT='# JJManager - JohnJohn3D HID device access
SUBSYSTEM=="hidraw", GROUP="plugdev", MODE="0660", TAG+="uaccess"'

if command -v sudo &>/dev/null && sudo -n true 2>/dev/null; then
    echo "$UDEV_RULE_CONTENT" | sudo tee "$UDEV_RULE_FILE" > /dev/null 2>&1 && \
        sudo udevadm control --reload-rules 2>/dev/null && \
        sudo udevadm trigger --subsystem-match=hidraw 2>/dev/null && \
        sudo usermod -aG plugdev "$USER" 2>/dev/null || true
    sudo usermod -aG dialout "$USER" 2>/dev/null || true
fi

# Create launcher script
echo ""
write_status "Creating launcher script..."
echo ""

cat > "$BIN_DIR/jjmanager" << 'EOF'
#!/bin/bash
# JJManager Launcher
INSTALL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/jjmanager"
UDEV_RULE="/etc/udev/rules.d/99-jjmanager-hid.rules"

# Auto-setup USB HID/serial permissions on first run (requires password once)
if ([[ ! -f "$UDEV_RULE" ]] || ! groups | grep -qw dialout) && command -v pkexec &>/dev/null; then
    CURRENT_USER="$USER"
    pkexec bash -c "
        echo 'SUBSYSTEM==\"hidraw\", GROUP=\"plugdev\", MODE=\"0660\", TAG+=\"uaccess\"' > '$UDEV_RULE'
        udevadm control --reload-rules 2>/dev/null || true
        udevadm trigger --subsystem-match=hidraw 2>/dev/null || true
        usermod -aG plugdev '$CURRENT_USER' 2>/dev/null || true
        usermod -aG dialout '$CURRENT_USER' 2>/dev/null || true
    " 2>/dev/null || true
fi

if [[ -x "$INSTALL_DIR/JJManager.Launcher" ]]; then
    exec "$INSTALL_DIR/JJManager.Launcher" "$@"
else
    exec "$INSTALL_DIR/JJManager" "$@"
fi
EOF

chmod +x "$BIN_DIR/jjmanager"
write_success "Launcher created: $BIN_DIR/jjmanager"

# Create desktop entry
echo ""
write_status "Creating desktop entry..."
echo ""

cat > "$DESKTOP_DIR/jjmanager.desktop" << EOF
[Desktop Entry]
Type=Application
Name=JJManager
Comment=Gerenciador de Dispositivos JohnJohn 3D
Exec=$BIN_DIR/jjmanager
Icon=$INSTALL_DIR/jjmanager.ico
Categories=Utility;
Terminal=false
EOF

chmod +x "$DESKTOP_DIR/jjmanager.desktop"
write_success "Desktop entry created"

# Add to PATH if needed
echo ""
write_status "Configuring environment..."
echo ""

# Check if ~/.local/bin is in PATH
if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then
    write_info "Adding $BIN_DIR to PATH"

    # Add to shell profile
    for PROFILE in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do
        if [[ -f "$PROFILE" ]] && ! grep -q "export PATH.*\.local/bin" "$PROFILE"; then
            echo "" >> "$PROFILE"
            echo "# Added by JJManager installer" >> "$PROFILE"
            echo "export PATH=\"\$HOME/.local/bin:\$PATH\"" >> "$PROFILE"
        fi
    done

    write_success "Added to PATH (restart terminal or run: source ~/.bashrc)"
else
    write_success "Already in PATH"
fi

# Create uninstaller
echo ""
write_status "Creating uninstaller..."
echo ""

cat > "$INSTALL_DIR/uninstall.sh" << EOF
#!/bin/bash
echo "Uninstalling JJManager..."
rm -rf "$INSTALL_DIR"
rm -f "$BIN_DIR/jjmanager"
rm -f "$DESKTOP_DIR/jjmanager.desktop"
if [[ -f "/etc/udev/rules.d/99-jjmanager-hid.rules" ]]; then
    sudo rm -f "/etc/udev/rules.d/99-jjmanager-hid.rules" 2>/dev/null || true
    sudo udevadm control --reload-rules 2>/dev/null || true
fi
echo "JJManager uninstalled successfully"
EOF

chmod +x "$INSTALL_DIR/uninstall.sh"
write_success "Uninstaller created"

# Summary
echo ""
echo -e "${GREEN}═══════════════════════════════════════════════════════════════${NC}"
write_success "JJManager $LATEST_VERSION installed successfully!"
echo -e "${GREEN}═══════════════════════════════════════════════════════════════${NC}"

echo ""
echo -e "${BLUE}Installation details:${NC}"
echo "  Location: $INSTALL_DIR"
echo "  Version: $LATEST_VERSION"
echo "  Platform: $PLATFORM"
echo "  Launcher: $BIN_DIR/jjmanager"

echo ""
echo -e "${BLUE}Next steps:${NC}"
echo "  1. Restart your terminal or run: source ~/.bashrc"
echo "  2. Run: jjmanager"
echo "  3. Or: $INSTALL_DIR/JJManager"

echo ""
echo -e "${BLUE}To uninstall:${NC}"
echo "  $INSTALL_DIR/uninstall.sh"

echo ""
