#!/bin/bash
# ═══════════════════════════════════════
# Somantix Beta — Local Dev Server
# ═══════════════════════════════════════
# Starts a local HTTP server and opens the test harness.
# Requires Python 3 (pre-installed on macOS and most Linux).

PORT=8000
DIR="$(cd "$(dirname "$0")" && pwd)"

echo ""
echo "  ╔═══════════════════════════════════════╗"
echo "  ║   Somantix Beta · Local Dev Server    ║"
echo "  ╚═══════════════════════════════════════╝"
echo ""
echo "  Serving from: $DIR"
echo "  Port: $PORT"
echo ""

# Check Python
if command -v python3 &>/dev/null; then
  PY=python3
elif command -v python &>/dev/null; then
  PY=python
else
  echo "  ⚠️  Python not found. Install Python 3 or run your own local server."
  echo "  e.g.:  npx serve .  or  php -S localhost:$PORT"
  exit 1
fi

echo "  Starting server..."
echo "  Open: http://localhost:$PORT/main/index.html"
echo ""
echo "  Press Ctrl+C to stop."
echo ""

# Open browser (macOS or Linux)
if command -v open &>/dev/null; then
  open "http://localhost:$PORT/main/index.html" &
elif command -v xdg-open &>/dev/null; then
  xdg-open "http://localhost:$PORT/main/index.html" &
fi

cd "$DIR"
$PY -m http.server $PORT --bind 127.0.0.1
