@echo off
chcp 65001 >nul
setlocal EnableDelayedExpansion

set "VCVARS=C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\Build\vcvars64.bat"

if not exist "!VCVARS!" (
    echo [ERROR] MSVC Build Tools not found at !VCVARS!
    echo Please change the VCVARS path to match your VS installation.
    exit /b 1
)

call "!VCVARS!"

set SOURCE=menu_demo.c
set PROGRAM=menu_demo_debug.exe

if not exist "%SOURCE%" (
    echo [ERROR] %SOURCE% not found.
    exit /b 1
)

echo [BUILD] Compiling %SOURCE% (DEBUG mode)...
rc /nologo app.rc
cl /nologo /Zi /Od /utf-8 /std:c17 /I..\..\eduwin\include /c "%SOURCE%"
set ERR=%errorlevel%
if %ERR% neq 0 (
    echo [ERROR] Compile failed
    exit /b 1
)
link /nologo /DEBUG "%SOURCE:.c=.obj%" app.res ..\..\eduwin\lib\eduwin.lib user32.lib gdi32.lib gdiplus.lib comctl32.lib comdlg32.lib shell32.lib winmm.lib /out:"%PROGRAM%" /subsystem:windows /entry:mainCRTStartup
set ERR=%errorlevel%
if %ERR% neq 0 (
    echo [ERROR] Link failed
    exit /b 1
)
echo [OK] Debug build success: %PROGRAM%
echo.
echo You can now debug with:
echo   VS Code: F5 (with C/C++ extension)
echo   Visual Studio: Debug - Attach to Process
echo   WinDbg: windbg %PROGRAM%
