# shellcheck shell=dash

___x_cmd_hok_search(){
    local X_help_cmd=; X_help_cmd='___x_cmd help -m hok search' help:arg:parse

    local query="$1"
    [ -n "$query" ] || query='*'

    if ___x_cmd_is_stdout2tty && ___x_cmd_runmode_allow_chatty ; then
        ___x_cmd_hok___prepare || return

        local x_=;
        ___X_CMD_SCOOP_FZF_MOD=hok \
        ___x_cmd_scoop___fzf_ ___x_cmd_hok___bin search "$query" || return
        [ -n "$x_" ] || return
        x_="${x_%% *}"
        local software="${x_%/*}"
        local bucket="${x_#*/}"
        local _id; local _cmd;
        ___x_cmd ui select _id,_cmd NEXT \
            "x hok info     ${bucket}/^${software}$" \
            "x hok install  ${bucket}/${software}" \
            "return" || return

        case "$_id" in
            1)  hok:info "cmd -> $_cmd"; ___x_cmd hok info "${bucket}/^${software}$" ;;
            2)  hok:info "cmd -> $_cmd"; ___x_cmd hok install "${bucket}/${software}" ;;
            *)  return ;;
        esac
    else
        ___x_cmd_hok___bin search "$query"
    fi
}
