@echo off
setlocal
title Remote Access Platform - Setup
echo ============================================
echo   Remote Access Platform - Setup
echo ============================================
echo.

REM --- Check Node.js ---
where node >nul 2>nul
if errorlevel 1 (
  echo [X] Node.js is not installed.
  echo     Please install Node.js 22.5 or newer from https://nodejs.org
  echo     Then run this SETUP.bat again.
  echo.
  pause
  exit /b 1
)
for /f "tokens=*" %%v in ('node -v') do set NODEV=%%v
echo [OK] Node.js found: %NODEV%
echo.

REM --- Install server dependencies ---
echo Installing SERVER dependencies...
pushd "%~dp0server"
call npm install --no-audit --no-fund
if errorlevel 1 ( echo [X] Server install failed. & popd & pause & exit /b 1 )
popd
echo [OK] Server ready.
echo.

REM --- Install agent dependencies (Electron + input injection) ---
echo Installing AGENT dependencies (Electron download may take a few minutes)...
pushd "%~dp0agent"
call npm install --no-audit --no-fund
if errorlevel 1 ( echo [!] Agent install had issues. Input injection may be limited, but the agent will still run. )
popd
echo [OK] Agent ready.
echo.

echo ============================================
echo   Setup complete!
echo ============================================
echo.
echo Next steps:
echo   1. Double-click  Start-Server.bat
echo   2. Open http://localhost:8090 in your browser
echo   3. Register a team, set up 2FA, enroll a machine (copy the token)
echo   4. Double-click  Start-Agent.bat  and paste the token
echo.
pause
