@echo off
setlocal EnableExtensions
title Starhorizon ERP - Instalador de Atalho
set "APP_URL=https://erp.starhorizon.cloud/launch.php?source=windows-desktop"
set "SHORTCUT=%USERPROFILE%\Desktop\Starhorizon ERP.lnk"
set "BROWSER="

if exist "%ProgramFiles%\Google\Chrome\Application\chrome.exe" set "BROWSER=%ProgramFiles%\Google\Chrome\Application\chrome.exe"
if not defined BROWSER if exist "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" set "BROWSER=%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe"
if not defined BROWSER if exist "%LocalAppData%\Google\Chrome\Application\chrome.exe" set "BROWSER=%LocalAppData%\Google\Chrome\Application\chrome.exe"
if not defined BROWSER if exist "%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe" set "BROWSER=%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"
if not defined BROWSER if exist "%ProgramFiles%\Microsoft\Edge\Application\msedge.exe" set "BROWSER=%ProgramFiles%\Microsoft\Edge\Application\msedge.exe"

if not defined BROWSER (
  echo Nao foi possivel localizar Google Chrome ou Microsoft Edge.
  echo Abra https://erp.starhorizon.cloud no navegador e tente novamente.
  pause
  exit /b 1
)

echo Criando atalho Starhorizon ERP na Area de Trabalho...
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ws=New-Object -ComObject WScript.Shell; $s=$ws.CreateShortcut($env:USERPROFILE+'\Desktop\Starhorizon ERP.lnk'); $s.TargetPath=$env:BROWSER; $s.Arguments='--app=https://erp.starhorizon.cloud/launch.php?source=windows-desktop'; $s.WorkingDirectory=(Split-Path $env:BROWSER); $s.IconLocation=$env:BROWSER+',0'; $s.Description='Starhorizon ERP AI'; $s.Save()"

if exist "%SHORTCUT%" (
  echo Atalho criado com sucesso.
  start "" "%SHORTCUT%"
) else (
  echo Nao foi possivel criar o atalho.
  pause
  exit /b 1
)
endlocal