@echo off
echo CONVERT NAVIGATOR IMAGES
echo.
echo Drag and drop the navigator images (Images or Folder) on this droplet to convert
echo them automatically to compressed PNGs for later Strapi upload.

node -v >nul 2>&1

if %errorlevel% neq 0 (
    echo Node.js is not installed or not added to PATH.
    pause
    goto end
)

:: Change directory to actual path of this batch file if not yet the case
cd /d "%~dp0"

if not exist "%~dp0\node_modules\" (
    :: Check if package.json exists in the directory
    if not exist "package.json" (
        echo.
        echo package.json not found. Please place the correct package.json file in the folder of this droplet.
        pause
        goto end
    )

    echo.
    echo Installing dependencies...
    npm install
    if %errorlevel% neq 0 (
        echo Failed to install dependencies.
        pause
        goto end
    )
    echo Dependencies successfully installed.
    echo.
    pause
)

IF "%~1" == "" GOTO NOINPUT
IF NOT EXIST "%~1" GOTO DOESNOTEXIST

SET /P projectNumber=Enter the project number: 
SET /P projectName=Enter the project name: 

echo.
echo Starting Conversion...
node "%~dp0/Navigator Image WEBP Conversion/NodeImageCompressionStrapi.js" %* "%projectNumber%" "%projectName%"
if %errorlevel% neq 0 (
        echo There was an error while converting the images.
        pause
        goto end
    )
GOTO DONE

:NOINPUT
echo.
echo ERROR
echo No Input provided, please drag and drop the images or a folder onto this droplet
pause
goto end

:DOESNOTEXIST
echo.
echo ERROR
echo The input %~1 does not exist
pause
goto end

:DONE
echo You can close this window now...
echo.
echo Have a good one!
echo Cheers Sven
echo.
pause

:end