@echo off
title AQIS Bonafide Certificate Manager
cd /d %~dp0

echo Detecting Google Chrome...
set CHROME_PATH=""

if exist "C:\Program Files\Google\Chrome\Application\chrome.exe" (
    set CHROME_PATH="C:\Program Files\Google\Chrome\Application\chrome.exe"
) else if exist "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" (
    set CHROME_PATH="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
) else if exist "%LocalAppData%\Google\Chrome\Application\chrome.exe" (
    set CHROME_PATH="%LocalAppData%\Google\Chrome\Application\chrome.exe"
)

echo.
echo =========================================================
echo  AQIS Bonafide Certificate Manager Local Server
echo =========================================================
echo  * The server is starting.
echo  * Google Chrome will launch in a few seconds.
echo  * Leave this window open while using the application.
echo  * To stop the server, close this window or press Ctrl+C.
echo =========================================================
echo.

if not %CHROME_PATH%=="" (
    :: Start a background cmd thread that waits 2 seconds, then launches Chrome
    start /b cmd /c "timeout /t 2 >nul && start "" %CHROME_PATH% --app=http://localhost:3000 --window-size=1280,800"
) else (
    :: Fallback to default browser after 2 seconds
    start /b cmd /c "timeout /t 2 >nul && start http://localhost:3000"
)

:: Run node server in the foreground to keep the terminal window open and server running
node server.js

