#compdef slpkg

# Zsh completion for slpkg package manager
# This script calls the Python helper for actual completion logic.

_slpkg() {
  local -a opts           # Array for completion options

  # Zsh's $CURRENT is 1-indexed, while the Python script expects a 0-indexed cword.
  local python_cword=$((CURRENT - 1))

  # Call the Python helper script to get the completions.
  local completions
  completions=$(python3 /usr/libexec/slpkg/shell_completion.py "$python_cword" "${words[@]}")

  # Convert the Python script's output (which is newline-separated) into a Zsh array.
  if [[ -n "$completions" ]]; then
    opts=("${(f)completions}") # The (f) flag splits by newline
    _describe 'commands' opts
  fi

  return 0
}

# This registers the '_slpkg' completion function for the 'slpkg' command.
# It ensures that when you type 'slpkg' and press Tab, the _slpkg function is called.
_slpkg "$@"
