@echo off

:: Relaunch script minimized
if "%1"=="min" goto start
start /min "" "%~f0" min
exit

:start

set "SHORTCUT=%USERPROFILE%\Desktop\VervePOS.lnk"
set "ARGS=--app=https://subdomain.vervepos.net"
set "ICONURL=https://vervepos.net/verveicon.ico"
set "ICONFILE=%TEMP%\verveicon.ico"

:: Get Chrome path from registry
for /f "tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" /ve 2^>nul') do set "TARGET=%%B"

:: If not found, check user installation
if not defined TARGET (
    set "TARGET=%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe"
)

:: Download icon from URL
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"Invoke-WebRequest '%ICONURL%' -OutFile '%ICONFILE%' -UseBasicParsing"

:: Create shortcut
powershell -NoProfile -ExecutionPolicy Bypass ^
"$WshShell = New-Object -ComObject WScript.Shell; ^
$Shortcut = $WshShell.CreateShortcut('%SHORTCUT%'); ^
$Shortcut.TargetPath = '%TARGET%'; ^
$Shortcut.Arguments = '%ARGS%'; ^
$Shortcut.WindowStyle = 3; ^
$Shortcut.IconLocation = '%ICONFILE%'; ^
$Shortcut.Save()"

echo Shortcut created successfully.
exit
