#compdef ual

# _ual_notes() {
#   local -a notes
#   notes=("${CHEATSHEET_PATH:-${XDG_DATA_HOME:-$HOME/.local/share}/ual}"/*(:t:r))
#   _describe "notes" notes
#   compadd "$@" $notes
# }

_ual() {
  local state
  _arguments \
    '1: :->subcmd' \
    '2: :->arg'

  local -a notes
  notes=("${CHEATSHEET_PATH:-${XDG_DATA_HOME:-$HOME/.local/share}/ual}"/*(:t:r))

  case $state in
    subcmd)
      local -a subcmds
      subcmds=(
        'edit:Create or edit the given note'
        'rm:Remove the given note'
        'ls:List all notes'
        'sync:Synchronize notes'
      )
      _describe 'command' subcmds
      compadd $notes
      ;;
    arg)
      case $line[1] in
        rm | edit) compadd $notes ;;
      esac
      ;;
  esac
}
_ual "$@"
