# Generate all 8 lightweight vehicle SVGs for iOS compatibility
# Replaces the old 85-120KB SVGs (embedded PNGs) with clean 1-2KB vector SVGs

$iconDir = "c:\laragon\www\moiko\tracker\mobile_app\assets\icons"

# Color configs: [name, bodyGrad1, bodyGrad2, stroke, cabin1, cabin2, glass, mirror]
$carColors = @{
  "green"  = @("#34D399", "#059669", "#047857", "#A7F3D0", "#6EE7B7", "#D1FAE5", "#059669")
  "red"    = @("#F87171", "#DC2626", "#991B1B", "#FECACA", "#FCA5A5", "#FEE2E2", "#DC2626")
  "orange" = @("#FBBF24", "#D97706", "#92400E", "#FDE68A", "#FCD34D", "#FEF3C7", "#D97706")
  "grey"   = @("#9CA3AF", "#6B7280", "#4B5563", "#D1D5DB", "#9CA3AF", "#E5E7EB", "#6B7280")
}

$motorColors = @{
  "green"  = @("#34D399", "#059669", "#047857", "#A7F3D0", "#6EE7B7", "#D1FAE5", "#059669")
  "red"    = @("#F87171", "#DC2626", "#991B1B", "#FECACA", "#FCA5A5", "#FEE2E2", "#DC2626")
  "orange" = @("#FBBF24", "#D97706", "#92400E", "#FDE68A", "#FCD34D", "#FEF3C7", "#D97706")
  "grey"   = @("#9CA3AF", "#6B7280", "#4B5563", "#D1D5DB", "#9CA3AF", "#E5E7EB", "#6B7280")
}

function MakeCarSvg($c) {
  $g1=$c[0]; $g2=$c[1]; $st=$c[2]; $c1=$c[3]; $c2=$c[4]; $gl=$c[5]; $mi=$c[6]
  return @"
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="100" viewBox="0 0 50 100">
  <defs>
    <linearGradient id="bg" x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stop-color="$g1"/><stop offset="100%" stop-color="$g2"/></linearGradient>
    <linearGradient id="wg" x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stop-color="$c1"/><stop offset="100%" stop-color="$c2"/></linearGradient>
  </defs>
  <ellipse cx="25" cy="88" rx="18" ry="4" fill="rgba(0,0,0,0.12)"/>
  <rect x="8" y="12" width="34" height="72" rx="10" fill="url(#bg)" stroke="$st" stroke-width="1.5"/>
  <rect x="12" y="28" width="26" height="30" rx="6" fill="url(#wg)" opacity="0.7"/>
  <rect x="14" y="30" width="22" height="12" rx="4" fill="$gl" opacity="0.9"/>
  <rect x="14" y="50" width="22" height="6" rx="3" fill="$gl" opacity="0.9"/>
  <rect x="12" y="13" width="8" height="4" rx="2" fill="#FEF3C7"/>
  <rect x="30" y="13" width="8" height="4" rx="2" fill="#FEF3C7"/>
  <rect x="12" y="79" width="8" height="4" rx="2" fill="#FCA5A5" opacity="0.8"/>
  <rect x="30" y="79" width="8" height="4" rx="2" fill="#FCA5A5" opacity="0.8"/>
  <ellipse cx="6" cy="34" rx="3" ry="2" fill="$mi"/>
  <ellipse cx="44" cy="34" rx="3" ry="2" fill="$mi"/>
  <rect x="5" y="18" width="5" height="14" rx="2.5" fill="#1F2937"/>
  <rect x="40" y="18" width="5" height="14" rx="2.5" fill="#1F2937"/>
  <rect x="5" y="62" width="5" height="14" rx="2.5" fill="#1F2937"/>
  <rect x="40" y="62" width="5" height="14" rx="2.5" fill="#1F2937"/>
</svg>
"@
}

function MakeMotorSvg($c) {
  $g1=$c[0]; $g2=$c[1]; $st=$c[2]; $c1=$c[3]; $c2=$c[4]; $gl=$c[5]; $mi=$c[6]
  return @"
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="100" viewBox="0 0 50 100">
  <defs>
    <linearGradient id="bg" x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stop-color="$g1"/><stop offset="100%" stop-color="$g2"/></linearGradient>
  </defs>
  <ellipse cx="25" cy="90" rx="14" ry="3" fill="rgba(0,0,0,0.12)"/>
  <ellipse cx="25" cy="13" rx="7" ry="7" fill="#1F2937" stroke="$st" stroke-width="1"/>
  <ellipse cx="25" cy="13" rx="4" ry="4" fill="#374151"/>
  <circle cx="25" cy="13" r="2" fill="#FEF3C7" opacity="0.8"/>
  <rect x="18" y="18" width="14" height="10" rx="4" fill="$gl" opacity="0.8"/>
  <rect x="16" y="26" width="18" height="38" rx="5" fill="url(#bg)" stroke="$st" stroke-width="1.5"/>
  <rect x="19" y="30" width="12" height="8" rx="3" fill="$c1" opacity="0.7"/>
  <rect x="20" y="42" width="10" height="4" rx="2" fill="$c2" opacity="0.5"/>
  <rect x="14" y="64" width="22" height="16" rx="4" fill="$g2" stroke="$st" stroke-width="1"/>
  <ellipse cx="25" cy="82" rx="8" ry="8" fill="#1F2937" stroke="$st" stroke-width="1"/>
  <ellipse cx="25" cy="82" rx="5" ry="5" fill="#374151"/>
  <circle cx="25" cy="82" r="2.5" fill="#FCA5A5" opacity="0.7"/>
  <rect x="11" y="38" width="4" height="12" rx="2" fill="$mi"/>
  <rect x="35" y="38" width="4" height="12" rx="2" fill="$mi"/>
  <line x1="14" y1="44" x2="11" y2="44" stroke="$st" stroke-width="1.5"/>
  <line x1="36" y1="44" x2="39" y2="44" stroke="$st" stroke-width="1.5"/>
</svg>
"@
}

# Generate all car SVGs
foreach ($color in $carColors.Keys) {
  $svg = MakeCarSvg $carColors[$color]
  $path = "$iconDir\car_$color.svg.svg"
  [System.IO.File]::WriteAllText($path, $svg, [System.Text.UTF8Encoding]::new($false))
  $size = (Get-Item $path).Length
  Write-Host "Created car_$color.svg.svg ($size bytes)"
}

# Generate all motor SVGs
foreach ($color in $motorColors.Keys) {
  $svg = MakeMotorSvg $motorColors[$color]
  $path = "$iconDir\motor_$color.svg.svg"
  [System.IO.File]::WriteAllText($path, $svg, [System.Text.UTF8Encoding]::new($false))
  $size = (Get-Item $path).Length
  Write-Host "Created motor_$color.svg.svg ($size bytes)"
}

Write-Host "`nDone! All 8 icons regenerated as clean vectors."
