#compdef nvimx
# ----------------------------------------
# Installation:
# mkdir -p ~/.zsh/completions
# nvimx completions zsh > ~/.zsh/completions/_nvimx
#
# Then add to your .zshrc:
# fpath=(~/.zsh/completions $fpath)
# autoload -Uz compinit && compinit
# ----------------------------------------

_nvimx_profiles() {
  local -a profiles
  profiles=($(nvimx list --plain 2>/dev/null))
  (( ${#profiles} )) || return 1
  _describe -t profiles 'profiles' profiles
}

_nvimx_commands() {
  local -a commands
  commands=(
    'list:List profiles'
    'install:Install a profile'
    'clean:Remove profile data'
    'doctor:Check system health'
    'sandbox:Run isolated environment'
    'registry:Manage registries'
    'update:Update nvimx'
    'completions:Generate completions'
    'help:Show help'
  )
  _describe 'command' commands
}

_nvimx() {
  local context state line
  _arguments -C \
    '(-h --help)'{-h,--help}'[Show help]' \
    '(-V --version)'{-V,--version}'[Show version]' \
    '1: :->first' \
    '*::arg:->args'

  case $state in
    first)
      _alternative \
        'commands:command:_nvimx_commands' \
        'profiles:profile:_nvimx_profiles'
      ;;
    args)
      case $words[2] in
        install|clean|sandbox)
          _nvimx_profiles
          ;;
        registry)
          _describe 'subcommand' \
            'list:List registries' \
            'check:Check registry health' \
            'update:Force registry update' \
            'clear:Clear registry cache'
          ;;
        help)
          _nvimx_commands
          ;;
      esac
      ;;
  esac
}

compdef _nvimx nvimx
