#!/bin/bash
# Simple local server for explorer (fallback option)
# Usage: ./serve-explorer-local.sh [port]

PORT=${1:-8080}
FRONTEND_DIR="$(cd "$(dirname "$0")/../frontend/public" && pwd)"

if [ ! -f "$FRONTEND_DIR/index.html" ]; then
    echo "❌ Frontend not found at: $FRONTEND_DIR/index.html"
    exit 1
fi

echo "Serving explorer on http://localhost:$PORT"
echo "Frontend: $FRONTEND_DIR"

cd "$FRONTEND_DIR"

# Try Python 3 first, then Python 2
if command -v python3 >/dev/null 2>&1; then
    python3 -m http.server "$PORT"
elif command -v python >/dev/null 2>&1; then
    python -m SimpleHTTPServer "$PORT"
else
    echo "❌ Python not found. Install Python to use this script."
    exit 1
fi
