# shellcheck shell=dash
___x_cmd_scoop_la(){
    local X_help_cmd=; X_help_cmd='___x_cmd help -m scoop la' help:arg:parse
    if ___x_cmd_is_stdout2tty && ___x_cmd_runmode_allow_chatty ; then
        ___x_cmd_scoop_la___fz
    else
        ___x_cmd_scoop_la___raw
    fi
}

___x_cmd_scoop_la___raw(){
    # TODO:
    # find the file in the scoop home / buckets
    # list all of the json data and parse ...

    local x_=; ___x_cmd_scoop___home_
    [ -d "$x_" ] || N=scoop M="Not found scoop root path" log:ret:1
    local l; local b
    ___x_cmd_cmds find "${x_}/buckets" -path '*/bucket/*.json' -type f | while read -r l; do
        l="${l#"${x_}/buckets/"}"
        b="${l%%/*}"
        l="${l##*/}"
        printf "%-29s \033[32m%s\033[0m\n" "${l%.json}" "${b}"
    done
}

___x_cmd_scoop_la___fz(){
    local x_=;
    ___x_cmd_scoop___fzf_ ___x_cmd_scoop_la___raw || return $?
    [ -n "$x_" ] || return $?


    local software="${x_%% *}"
    local bucket="${x_##* }"
    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
}
