@echo off
setlocal EnableExtensions

REM Always run inside a persistent console so it cannot “flash and close”
if /i not "%~1"=="__RUN" (
  start "MY.TOWN Blogger Installer" cmd /k ""%~f0" __RUN"
  exit /b
)

cd /d "%~dp0"

echo ==========================================
echo  MY.TOWN Blogger Kit - Windows Installer
echo ==========================================
echo.

REM Open the instructions page (optional)
if exist "%~dp0START_HERE.html" (
  start "" "%~dp0START_HERE.html"
)

set "LOG=%~dp0install-windows.log"
echo Logging to: %LOG%
echo.

echo Running installer...
echo.

REM Use PowerShell with no profile and bypass policy, capture output to a log
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0bootstrap_kit\install.ps1" 1>>"%LOG%" 2>>&1
set "EXITCODE=%ERRORLEVEL%"

echo.
if "%EXITCODE%"=="0" (
  echo Install complete.
  echo Next: Open START_HERE.html and continue to Step B.
) else (
  echo Install failed (code %EXITCODE%).
  echo.
  echo Last 30 lines of log:
  echo ------------------------------------------
  powershell -NoProfile -Command "Get-Content -LiteralPath '%LOG%' -Tail 30"
  echo ------------------------------------------
  echo Full log: %LOG%
)

echo.
echo Press any key to close this window...
pause >nul
exit /b %EXITCODE%
