#compdef nordvpn

_cli_zsh_autocomplete() {
  local -a opts
  local cur
  cur=${words[-1]}
  if [[ "$cur" == "-"* ]]; then
    opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
  else
    opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}")
  fi

  # Special value hardcoded in cli_fileshare.go to indicate that filepath completions are wanted
  if [[ "${opts[1]}" == "nordvpn_autocomplete_filepaths" ]]; then
      _files
  else
    # Case-insensitive prefix matching: fold case both ways so e.g. "ger" or
    # "GER" both match "Germany". The match spec is passed straight to the
    # underlying compadd via _describe, so it applies only to this completion
    # and does not mutate the user's global zstyle configuration.
    _describe 'values' opts -M 'm:{a-zA-Z}={A-Za-z}'
  fi
}

compdef _cli_zsh_autocomplete nordvpn
