@echo off
setlocal enabledelayedexpansion

if not "%1"=="run" (
    start "Stop - Juragan Kepiting" cmd /k ""%~f0" run"
    exit /b
)

cls
echo ============================================================
echo   JURAGAN KEPITING POS - Stop
echo ============================================================
echo.

echo Menutup jendela backend dan frontend...
taskkill /FI "WINDOWTITLE eq Backend - Juragan Kepiting" /F >nul 2>&1
taskkill /FI "WINDOWTITLE eq Frontend - Juragan Kepiting" /F >nul 2>&1

echo Membebaskan port 5000...
for /f "tokens=5" %%a in ('netstat -aon ^| findstr ":5000 " ^| findstr "LISTENING"') do (
    taskkill /PID %%a /F >nul 2>&1
)

echo Membebaskan port 3000...
for /f "tokens=5" %%a in ('netstat -aon ^| findstr ":3000 " ^| findstr "LISTENING"') do (
    taskkill /PID %%a /F >nul 2>&1
)

echo.
echo [OK] Semua proses dihentikan.
echo.
echo Tekan sembarang tombol untuk menutup...
pause >nul
