@echo off
setlocal EnableExtensions EnableDelayedExpansion

if exist "Custom Patches\" (
    echo Copying custom patches to Vencord plugins...
    for /d %%D in ("Custom Patches\*") do (
        xcopy /E /I /Y "%%D" "Vencord\src\plugins\%%~nxD\" >nul
    )
)

cd /d "%~dp0Vencord"

echo ==== Build started at %DATE% %TIME% ====

where pnpm >nul 2>&1
if errorlevel 1 (
    echo ERROR: pnpm not found on PATH.
    exit /b 1
)

if not exist ".git" (
    echo ERROR: This is not a git repository.
    exit /b 1
)

echo Installing dependencies...
call pnpm install || goto :fail

echo Building Vencord...
call pnpm build || goto :fail

echo Injecting into client...
call pnpm inject /Y || goto :fail

echo.
echo Build completed successfully.
echo ==== SUCCESS at %DATE% %TIME% ====
exit /b 0

:fail
echo.
echo ERROR: Build failed.
echo ==== FAILURE at %DATE% %TIME% ====
exit /b 1
