# shellcheck shell=dash

___x_cmd log init uninstall

xrc:mod:lib uninstall     ls    rm

___x_cmd_uninstall___main(){
    [ "$#" -gt 0 ] ||       set -- ls

    local op="$1";          shift
    case "$op" in
        ls)                 ___x_cmd_uninstall_ls               "$@" ;;

        --fzdata)           ___x_cmd_uninstall_ls___fz_data     "$@" ;;
        --fzfpreview)       ___x_cmd_uninstall_ls___fz_preview  "$@" ;;

        x|self)             ___x_cmd_uninstall___x                   ;;
        -h|--help)          ___x_cmd help -m uninstall          "$@" ;;

        --|rm)              ___x_cmd_uninstall_rm               "$@" ;;
        *)                  ___x_cmd_uninstall_rm   "$op"       "$@" ;;
    esac
}

___x_cmd_uninstall___x(){
    uninstall:info "From now on, x-cmd won't start during shell boot"

    local id
    ___x_cmd ui select id \
        "Do you want to remove x-cmd's code, softwares installed and userdata created by x-cmd -> x boot clear && x rmrf ~/.x-cmd.root" \
        "Later, I will do it by myself (RECOMMENDED)"       \
        "Just Remove ~/.x-cmd.root (NOTICE: the x-cmd in the current shell won't function well)" \
        "Remove ~/.x-cmd.root and EXIT the current shell"

    case "$id" in
        1)      return 0 ;;
        2)      ___x_cmd boot clear && ___x_cmd rmrf ~/.x-cmd.root ;;
        3)      ___x_cmd boot clear && ___x_cmd rmrf ~/.x-cmd.root; exit 0  ;;
    esac
}
