@echo off
cd /d "%~dp0"
set PORT=8767

rem Python : on essaie le lanceur "py", puis l'installation utilisateur, puis le PATH.
set PY=
where py >nul 2>&1 && set PY=py -3
if not defined PY if exist "%LOCALAPPDATA%\Programs\Python\Python313\python.exe" set PY="%LOCALAPPDATA%\Programs\Python\Python313\python.exe"
if not defined PY where python >nul 2>&1 && set PY=python
if not defined PY (
  echo Python 3 est introuvable sur ce poste.
  echo Installer avec :  winget install --id Python.Python.3.13 --scope user
  pause
  exit /b 1
)

netstat -ano | findstr /r /c:":%PORT% .*LISTENING" >nul 2>&1
if errorlevel 1 (
  start "PLANNING TEAM - serveur - NE PAS FERMER" /min %PY% "%~dp0serveur.py" %PORT%
  ping -n 3 127.0.0.1 >nul
)
start "" "http://127.0.0.1:%PORT%/Planning-Team.html?v=%RANDOM%%TIME:~6,2%"
exit /b 0
