@echo off

REM ================================================================
REM DOCU_BUILD - Umgebungsvariablen Setup
REM ================================================================

echo Setting up environment variables for DOCU_BUILD ...

REM Basis-Projektpfad (aktueller Ordner)
set "PROJECT=%~dp0.."
if "%PROJECT:~-6%"=="bin\.." set "PROJECT=%PROJECT:~0,-6%"
if "%PROJECT:~-1%"=="\" set "PROJECT=%PROJECT:~0,-1%"

REM Pfade fuer verschiedene Komponenten
set "PV_BIN=%PROJECT%\bin"
set "PV_LIB=%PROJECT%\lib"
set "PV_DATA=%PROJECT%\data"
set "PV_CFG=%PROJECT%\cfg"
set "PV_LOG=%PROJECT%\log"
set "PV_TESTS=%PROJECT%\tests"
set "PV_RESULTS=%PROJECT%\results"
set "PV_EXAMPLES=%PROJECT%\examples"

REM Base-Repo spezifische Pfade
set "PV_EXT=%PROJECT%\_ext"
set "PV_TEMPLATES=%PROJECT%\_templates"
set "PV_ASSETS=%PROJECT%\assets"
set "PV_MODULES=%PROJECT%\modules"
set "PV_CHAPTERS=%PROJECT%\chapters"
set "PV_GLOSSARY=%PROJECT%\glossary"
set "PV_STYLES=%PROJECT%\styles"
set "PV_SCRIPTS=%PROJECT%\scripts"

REM Python-Pfad erweitern (nur wenn noch nicht vorhanden)
echo %PYTHONPATH% | find /i "%PV_LIB%" >nul
if errorlevel 1 (
    set "PYTHONPATH=%PV_LIB%;%PYTHONPATH%"
)

REM Ordner erstellen falls sie nicht existieren
if not exist "%PV_BIN%" mkdir "%PV_BIN%"
if not exist "%PV_CFG%" mkdir "%PV_CFG%"
if not exist "%PV_LIB%" mkdir "%PV_LIB%"
if not exist "%PV_DATA%" mkdir "%PV_DATA%"
if not exist "%PV_LOG%" mkdir "%PV_LOG%"
if not exist "%PV_RESULTS%" mkdir "%PV_RESULTS%"
if not exist "%PV_EXAMPLES%" mkdir "%PV_EXAMPLES%"
if not exist "%PV_EXT%" mkdir "%PV_EXT%"
if not exist "%PV_TEMPLATES%\latex" mkdir "%PV_TEMPLATES%\latex"
if not exist "%PV_TEMPLATES%\common" mkdir "%PV_TEMPLATES%\common"
if not exist "%PV_ASSETS%\shared\photos" mkdir "%PV_ASSETS%\shared\photos"
if not exist "%PV_ASSETS%\shared\drawings" mkdir "%PV_ASSETS%\shared\drawings"
if not exist "%PV_ASSETS%\shared\symbols" mkdir "%PV_ASSETS%\shared\symbols"
if not exist "%PV_ASSETS%\shared\diagrams" mkdir "%PV_ASSETS%\shared\diagrams"
if not exist "%PV_ASSETS%\localized\de" mkdir "%PV_ASSETS%\localized\de"
if not exist "%PV_ASSETS%\localized\en" mkdir "%PV_ASSETS%\localized\en"
if not exist "%PV_MODULES%" mkdir "%PV_MODULES%"
if not exist "%PV_CHAPTERS%" mkdir "%PV_CHAPTERS%"
if not exist "%PV_GLOSSARY%" mkdir "%PV_GLOSSARY%"
if not exist "%PV_STYLES%" mkdir "%PV_STYLES%"
if not exist "%PV_SCRIPTS%" mkdir "%PV_SCRIPTS%"

REM Umgebungsvariablen anzeigen
echo.
echo ================================================================
echo DOCU_BUILD ENVIRONMENT SETUP COMPLETE
echo ================================================================
echo PROJECT         = %PROJECT%
REM echo PV_BIN          = %PV_BIN%
REM echo PV_CFG          = %PV_CFG%
REM echo PV_LIB          = %PV_LIB%
REM echo PV_DATA         = %PV_DATA%
REM echo PV_RESULTS      = %PV_RESULTS%
REM echo PV_LOG          = %PV_LOG%
REM echo PV_EXAMPLES     = %PV_EXAMPLES%
REM echo PV_EXT          = %PV_EXT%
REM echo PV_TEMPLATES    = %PV_TEMPLATES%
REM echo PV_ASSETS       = %PV_ASSETS%
REM echo PV_MODULES      = %PV_MODULES%
REM echo PV_CHAPTERS     = %PV_CHAPTERS%
REM echo PV_GLOSSARY     = %PV_GLOSSARY%
REM echo PV_STYLES       = %PV_STYLES%
REM echo PV_SCRIPTS      = %PV_SCRIPTS%
echo PYTHONPATH      = %PYTHONPATH%
echo ================================================================
echo.

REM Optionally keep window open
if "%1"=="--keep-open" pause
