# PowerShell Script zum Ausführen von Git-Befehlen
$ErrorActionPreference = "Stop"

# Git-Pfade zum Durchsuchen
$gitPaths = @(
    "git",  # Falls im PATH
    "C:\Program Files\Git\bin\git.exe",
    "C:\Program Files (x86)\Git\bin\git.exe",
    "$env:LOCALAPPDATA\Programs\Git\bin\git.exe",
    "$env:ProgramFiles\Git\cmd\git.exe",
    "$env:ProgramFiles(x86)\Git\cmd\git.exe"
)

$gitExe = $null
foreach ($path in $gitPaths) {
    try {
        if ($path -eq "git") {
            $gitExe = Get-Command git -ErrorAction SilentlyContinue
            if ($gitExe) {
                $gitExe = $gitExe.Source
                break
            }
        } else {
            if (Test-Path $path) {
                $gitExe = $path
                break
            }
        }
    } catch {
        continue
    }
}

if (-not $gitExe) {
    Write-Host "Git wurde nicht gefunden. Bitte installiere Git oder fuege es zum PATH hinzu." -ForegroundColor Red
    Write-Host ""
    Write-Host "Alternativ führe diese Befehle manuell in Git Bash aus:" -ForegroundColor Yellow
    Write-Host "cd c:\Users\User\Documents\GitHub\ANDJJJJJJ" -ForegroundColor Cyan
    Write-Host "git add ." -ForegroundColor Cyan
    Write-Host "git commit -m `"feat: Control Panel v2.0 - Cards, Side Panels, Dark Mode, volle Breite`"" -ForegroundColor Cyan
    Write-Host "git push" -ForegroundColor Cyan
    exit 1
}

Write-Host "Git gefunden: $gitExe" -ForegroundColor Green
Write-Host ""

# Zum Projektverzeichnis wechseln
Set-Location "c:\Users\User\Documents\GitHub\ANDJJJJJJ"

# Git-Befehle ausführen
Write-Host "Staging aller Aenderungen..." -ForegroundColor Yellow
& $gitExe add .

if ($LASTEXITCODE -ne 0) {
    Write-Host "❌ Fehler beim Staging" -ForegroundColor Red
    exit 1
}

Write-Host "Erstelle Commit..." -ForegroundColor Yellow
& $gitExe commit -m "feat: Control Panel v2.0 - Cards, Side Panels, Dark Mode, volle Breite"

if ($LASTEXITCODE -ne 0) {
    Write-Host "❌ Fehler beim Commit" -ForegroundColor Red
    exit 1
}

Write-Host "Pushe Aenderungen..." -ForegroundColor Yellow
& $gitExe push

if ($LASTEXITCODE -ne 0) {
    Write-Host "❌ Fehler beim Push" -ForegroundColor Red
    exit 1
}

Write-Host ""
Write-Host "Erfolgreich committed und gepusht!" -ForegroundColor Green
