#!/usr/bin/env bash
# Step 02: Install Volta (JavaScript toolchain manager).

step_name="Install Volta"

run() {
  log_info "Downloading Volta installer..."
  # Volta's official install uses PowerShell on Windows
  vm_exec ps "irm https://get.volta.sh | iex" --timeout 120

  # Volta installs to %LOCALAPPDATA%\Volta and adds to PATH.
  # Refresh PATH in current session by reading it from registry.
  log_info "Refreshing PATH..."
  vm_exec ps "[System.Environment]::GetEnvironmentVariable('PATH', 'User')" --timeout 30
}

verify() {
  local ver
  ver=$(vm_exec cmd "volta --version" 2>/dev/null || echo "")
  if [[ -n "$ver" ]]; then
    log_pass "Volta $ver"
    return 0
  fi
  log_fail "Volta not found after install"
  return 1
}
