#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"

if command -v python3 >/dev/null 2>&1; then
  PY=python3
elif command -v python >/dev/null 2>&1; then
  PY=python
else
  echo "Python not found."
  exit 1
fi

echo "Calculator: http://localhost:8888"
(
  sleep 1
  command -v xdg-open >/dev/null 2>&1 && xdg-open "http://localhost:8888" 2>/dev/null || true
  command -v open >/dev/null 2>&1 && open "http://localhost:8888" 2>/dev/null || true
) &

exec "$PY" -m http.server 8888 --bind 127.0.0.1
