# shellcheck shell=dash disable=2016

___x_cmd_scoop_search(){
    local X_help_cmd=; X_help_cmd='___x_cmd help -m scoop search' help:arg:parse
    if ___x_cmd_is_stdout2tty && ___x_cmd_runmode_allow_chatty ; then
        ___x_cmd_scoop_search___fz "$@"
    else
        ___x_cmd_scoop___bin search "$@"
    fi
}

___x_cmd_scoop_search___fz(){
    local x_=;
    ___x_cmd_scoop___fzf_  ___x_cmd_scoop___parse_scoop_list ___x_cmd_scoop___bin search "$@" || return $?
    [ -n "$x_" ] || return $?
    x_="${x_% *}"
    eval "set -- $x_"
    local software="$1"
    local bucket="$2"
    local _id; local _cmd
    ___x_cmd ui select _id,_cmd NEXT    \
        "x scoop info       ${bucket}/${software}"    \
        "x scoop install    ${bucket}/${software}"    \
        "return"    || return $?
    case "$_id" in
        1)  scoop:info "cmd -> $_cmd"; ___x_cmd scoop info "${bucket}/${software}" ;;
        2)  scoop:info "cmd -> $_cmd"; ___x_cmd scoop install "${bucket}/${software}" ;;
        *)  return ;;
    esac
}
