#!/bin/bash
# Setup script for socktop documentation tools

set -e

echo "🚀 Setting up socktop documentation tools..."
echo ""

# Check if cargo is installed
if ! command -v cargo &> /dev/null; then
    echo "❌ Error: cargo is not installed"
    echo "   Please install Rust first: https://rustup.rs/"
    exit 1
fi

echo "✓ Cargo found"

# Install mdbook
echo ""
echo "📚 Installing mdbook..."
if command -v mdbook &> /dev/null; then
    echo "✓ mdbook is already installed ($(mdbook --version))"
else
    cargo install mdbook
    echo "✓ mdbook installed successfully"
fi

# Download Catppuccin theme CSS
echo ""
echo "🎨 Downloading Catppuccin theme CSS..."
cd "$(dirname "$0")"
mkdir -p theme

# Download the CSS file
curl -fsSL https://github.com/catppuccin/mdBook/releases/latest/download/catppuccin.css \
    -o theme/catppuccin.css

echo "✓ Catppuccin theme CSS downloaded"

# Build documentation
echo ""
echo "🔨 Building documentation..."
mdbook build
echo "✓ Documentation built successfully"

echo ""
echo "✅ Setup complete!"
echo ""
echo "Next steps:"
echo "  • View docs: mdbook serve --open"
echo "  • Build docs: mdbook build"
echo "  • Clean docs: rm -rf book/"
echo ""
echo "The documentation will also be built automatically when you run 'cargo build'."
echo "It will be served at http://localhost:8082/assets/docs/ when running the webterm server."
echo ""
echo "Note: Using default mdBook themes with Catppuccin CSS overlay."
