#!/usr/bin/env bash
# bin/serve — serve the web build locally
#
# Usage:
#   bin/serve          # serve on port 8080
#   bin/serve 9000     # serve on port 9000

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"

cd "$PROJECT_DIR"

BUILD_DIR="build-web"

if [ ! -f "$BUILD_DIR/index.html" ]; then
    echo "Error: Web build not found. Run 'bin/build-web' first." >&2
    exit 1
fi

PORT="${1:-8080}"

echo "Serving study-player at http://localhost:$PORT"
echo "Press Ctrl+C to stop."
python3 -m http.server "$PORT" -d "$BUILD_DIR"
