#!/usr/bin/env bash
# ============================================================================
# BLACKROAD OS, INC. - PROPRIETARY AND CONFIDENTIAL
# Copyright (c) 2025-2026 BlackRoad OS, Inc. All Rights Reserved.
# ============================================================================
# BLACKROAD OS - Terminal Interface Launcher
# Usage: bros [tui|curses|web|status|help]
set -eo pipefail

source "$HOME/.blackroad/config/nodes.sh" 2>/dev/null || true

CMD="${1:-status}"
DIR="$HOME/blackroad-command-center"

case "$CMD" in
    tui|t)
        if [[ -f "$DIR/blackroad-tui.py" ]]; then
            python3 "$DIR/blackroad-tui.py"
        else
            printf '%bTUI not found at %s%b\n' "$RED" "$DIR/blackroad-tui.py" "$RESET"
            printf 'Install: pip3 install textual && mkdir -p %s\n' "$DIR"
            exit 1
        fi
        ;;
    curses|c)
        if [[ -f "$DIR/blackroad-curses.py" ]]; then
            python3 "$DIR/blackroad-curses.py"
        else
            printf '%bCurses TUI not found.%b Falling back to status view.\n' "$AMBER" "$RESET"
            exec "$HOME/bin/br-status"
        fi
        ;;
    web|w)
        if [[ -f "$DIR/blackroad-os-dashboard.html" ]]; then
            open "$DIR/blackroad-os-dashboard.html"
        else
            printf '%bDashboard HTML not found.%b\n' "$RED" "$RESET"
            exit 1
        fi
        ;;
    status|s)
        # Default: show quick status via br-status
        exec "$HOME/bin/br-status"
        ;;
    stats)
        exec "$HOME/bin/br-stats"
        ;;
    help|h|-h|--help)
        printf '%bBLACKROAD OS%b\n\n' "$PINK" "$RESET"
        echo "Usage: bros [mode]"
        echo ""
        echo "Modes:"
        echo "  status, s   Quick infrastructure status (default)"
        echo "  stats       Full portfolio statistics"
        echo "  curses, c   Pure curses TUI (no deps)"
        echo "  tui, t      Rich TUI with textual"
        echo "  web, w      Open web dashboard"
        echo "  help, h     This help"
        echo ""
        echo "See also: br-help, brctl status, br-stats"
        ;;
    *)
        echo "Unknown mode: $CMD"
        exec "$0" help
        ;;
esac
