#!/data/data/com.termux/files/usr/bin/bash
# ClaudeAll - Termux/Android Installer
# One-line install for Android devices

set -e

echo "╔════════════════════════════════════════════════════════════╗"
echo "║  🤖 ClaudeAll - Termux/Android Installer                   ║"
echo "║  MONSTER ENGINEER + Raja Terakhir Mode                     ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""

# Check/install dependencies
echo "📦 Checking dependencies..."

if ! command -v node &> /dev/null; then
    echo "📥 Installing Node.js..."
    pkg install -y nodejs
fi

if ! command -v npm &> /dev/null; then
    echo "📥 Installing npm..."
    pkg install -y npm
fi

echo "✅ Node.js $(node --version)"
echo "✅ npm $(npm --version)"
echo ""

# Install Claude CLI if not present
# NOTE: Termux/Android does not support the native installer (https://claude.ai/install.sh)
# because the native binary is built for Linux x86_64 / macOS / Windows only.
# So on Termux we still use npm install. Once Anthropic ships ARM/Android builds,
# this should be migrated to: curl -fsSL https://claude.ai/install.sh | bash
if ! command -v claude &> /dev/null; then
    echo "📥 Installing Claude CLI (npm — Termux fallback)..."
    npm install -g @anthropic-ai/claude-code
fi
echo "✅ Claude CLI installed at: $(command -v claude)"

# Install Gemini CLI if not present (optional)
if ! command -v gemini &> /dev/null; then
    echo "📥 Installing Gemini CLI..."
    npm install -g @anthropic-ai/gemini-cli 2>/dev/null || echo "⚠️  Gemini CLI not available (optional)"
fi

echo ""
echo "📦 Installing ClaudeAll config..."
npm install -g claude-all-config@latest

echo ""
echo "╔════════════════════════════════════════════════════════════╗"
echo "║  ✅ Installation Complete!                                  ║"
echo "╠════════════════════════════════════════════════════════════╣"
echo "║  Installed:                                                 ║"
echo "║  • Claude CLI with @proactive-mode                         ║"
echo "║  • 14 Agents (MONSTER ENGINEER)                            ║"
echo "║  • 63 Skills                                                ║"
echo "║  • 7 MCP Servers                                           ║"
echo "║  • Raja Terakhir Authority                                 ║"
echo "╠════════════════════════════════════════════════════════════╣"
echo "║  Usage:                                                     ║"
echo "║  $ claude           # Start Claude CLI                     ║"
echo "║  $ gemini -y        # Start Gemini (YOLO mode)             ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
