@echo off
setlocal EnableExtensions
cd /d "%~dp0"
set "ROOT=%CD%"
set "LOGDIR=%ROOT%\Logs"
if not exist "%LOGDIR%" mkdir "%LOGDIR%" >nul 2>nul
set "LOG=%LOGDIR%\phuckit-launch.log"

set "AHK=%ROOT%\Runtime\AutoHotkey\v2\AutoHotkey64.exe"
if not exist "%AHK%" (
  for /r "%ROOT%\Runtime\AutoHotkey" %%F in (AutoHotkey64.exe) do if not defined FOUND_AHK set "FOUND_AHK=%%~fF"
  if defined FOUND_AHK set "AHK=%FOUND_AHK%"
)

if not exist "%AHK%" (
  echo [%date% %time%] AutoHotkey64.exe not found.>>"%LOG%"
  echo.
  echo PhUCKIT could not find AutoHotkey64.exe.
  echo Expected or searched under:
  echo   %ROOT%\Runtime\AutoHotkey
  echo.
  echo Run Repair from the Control Center, or place AutoHotkey64.exe in:
  echo   Runtime\AutoHotkey\v2\
  echo.
  pause
  exit /b 1
)

echo [%date% %time%] Launching "%AHK%" "%ROOT%\App\PhUCKIT.ahk">>"%LOG%"
start "PhUCKIT" "%AHK%" "%ROOT%\App\PhUCKIT.ahk"
timeout /t 2 /nobreak >nul
echo PhUCKIT started. Middle-click and Ctrl+Space are active.
exit /b 0
