@echo off
echo Installing PhpSpreadsheet library for Reports System...
echo.

REM Check if Composer is installed
composer --version >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo ERROR: Composer is not installed or not in PATH
    echo.
    echo Please install Composer first:
    echo 1. Download from: https://getcomposer.org/download/
    echo 2. Run the installer
    echo 3. Restart your command prompt
    echo 4. Run this script again
    echo.
    pause
    exit /b 1
)

echo Composer found! Installing dependencies...
echo.

REM Install PhpSpreadsheet
composer install --no-dev --optimize-autoloader

if %ERRORLEVEL% EQU 0 (
    echo.
    echo ✅ SUCCESS! PhpSpreadsheet installed successfully.
    echo.
    echo Next steps:
    echo 1. Go to your Reports & Printouts page
    echo 2. Try generating a report
    echo 3. If you still have issues, run test_reports_debug.php
    echo.
) else (
    echo.
    echo ❌ ERROR: Installation failed.
    echo.
    echo Troubleshooting:
    echo 1. Make sure you're in the correct directory
    echo 2. Check your internet connection
    echo 3. Try running: composer install --verbose
    echo.
)

pause