# txt2tex quick installer for Windows
# Run this in PowerShell as Administrator:
#   iex (curl -useb https://github.com/whynotdeep7/txt2tex/releases/download/v0.2.0/install-windows.ps1)

$ErrorActionPreference = "Stop"
$RepoUrl = "https://github.com/whynotdeep7/txt2tex"

Write-Host ""
Write-Host "  txt2tex installer - plain text to professional PDF" -ForegroundColor Cyan
Write-Host "  ---------------------------------------------------"
Write-Host ""

# Check if Rust is installed
if (!(Get-Command cargo -ErrorAction SilentlyContinue)) {
    Write-Host "[!] Rust not found. Installing..." -ForegroundColor Yellow
    $installer = "$env:TEMP\rustup-init.exe"
    Invoke-WebRequest "https://win.rustup.rs/x86_64" -OutFile $installer -UseBasicParsing
    & $installer -y --no-modify-path
    $env:PATH = "$env:USERPROFILE\.cargo\bin;$env:PATH"
} else {
    Write-Host "[OK] Rust: $(rustc --version)" -ForegroundColor Green
}

# Check if tectonic is installed
if (!(Get-Command tectonic -ErrorAction SilentlyContinue)) {
    Write-Host "[!] tectonic not found. Installing via cargo (this takes a few minutes)..." -ForegroundColor Yellow
    & cargo install tectonic
} else {
    Write-Host "[OK] tectonic installed" -ForegroundColor Green
}

# Install txt2tex
Write-Host "[->] Installing txt2tex via cargo..." -ForegroundColor Cyan
& cargo install txt2tex

Write-Host ""
Write-Host "[OK] Installation complete!" -ForegroundColor Green
Write-Host ""
Write-Host "Commands:" -ForegroundColor White
Write-Host "  txt2tex          - edit resume, generate PDF"
Write-Host "  txt2tex new      - create fresh resume.txt"
Write-Host "  txt2tex analyze  - check resume for weak spots"
Write-Host "  txt2tex --help   - show all options"
Write-Host ""
Write-Host "For more info: $RepoUrl" -ForegroundColor Gray
Write-Host ""
