#!/bin/bash
export PYTHONUTF8=1
DIR="$(cd "$(dirname "$0")/../Resources" && pwd)"
PY=""
for p in /opt/homebrew/bin/python3 /usr/local/bin/python3 /Library/Frameworks/Python.framework/Versions/Current/bin/python3 /usr/bin/python3; do
  [ -x "$p" ] || continue
  if [ "$p" = "/usr/bin/python3" ]; then
    xcode-select -p >/dev/null 2>&1 || continue
  fi
  if "$p" -c "import sys; sys.exit(0 if sys.version_info>=(3,7) else 1)" >/dev/null 2>&1; then PY="$p"; break; fi
done
if [ -z "$PY" ]; then
  osascript -e 'display dialog "מיוזי-כיף צריך Python 3 כדי לעבוד.\n\nהדרך הקלה: פתחו את הטרמינל והריצו:\nxcode-select --install\n\n(או הורידו Python מהאתר python.org)" with title "מיוזי-כיף" buttons {"פתח את python.org","ביטול"} default button 1' >/dev/null 2>&1 && open "https://www.python.org/downloads/macos/"
  exit 1
fi
exec "$PY" "$DIR/muzikef_server.py"
