#!/bin/bash

_slpkg_completion()
{
    local cur prev words cword

    COMPREPLY=()
    _get_comp_words_by_ref -n ":" cur prev words cword

    local all_commands="update upgrade config repo-info clean-tmp self-check build install remove download list info search dependees tracking changelog version help"

    case "$cword" in
        1) # Completing the command itself (e.g., 'slpkg <TAB>')
            COMPREPLY=( $(compgen -W "${all_commands}" -- "$cur") )
            ;;
        *) # Completing arguments after the command
            # Call the separate, lightweight Python helper script
            # Pass cword and the entire COMP_WORDS array to it
            COMPREPLY=( $(python3 /usr/libexec/slpkg/shell_completion.py "$cword" "${words[@]}") )
            ;;
    esac

    return 0
}

complete -F _slpkg_completion slpkg