# shellcheck shell=dash

xrc:mod:lib     is      util coco

___x_cmd_is___main(){
    [ "$#" -gt 0 ] ||   set -- --help

    local op="$1";  shift
    case "$op" in
        int|float|positive|negative|eq|within|newest|ip|minmax)
                    ___x_cmd_is_"$op" "$@" ;;

        in)         S=, L="$2" ___x_cmd_is___in "$1" ;;
        in*)        S="${op#in}" L="$2" ___x_cmd_is___in "$1" ;;
        unset)      ___x_cmd_isunset "$@"       ;;

        -h|--help)  ___x_cmd help -m is 1>&2    ;;
        --|,,)      ___x_cmd_is_coco "$@"       ;;

        --app)      ___x_cmd_is___app "$@"      ;;

        *)          x:error "Unknown op -> $1"
                    ___x_cmd_is___app "$@"
                    ;;
    esac
}

___x_cmd_is___app(){
    local IFS=" "
    local msg="$*"

    local id

    ___x_cmd ui select id "Next:"       \
        "query ai for info about: $msg" \
        "x is --help    # Open help"    \
        "return 0"

    case "$id" in
        1)  ___x_cmd_is___coco "$@" ;;
        2)  ___x_cmd is --help  ;;
        *)  return 0 ;;
    esac
}

___x_cmd_is_minmax(){
    local min="$1"
    local max="$2"; shift 2

    while [ $# -gt 0 ]; do
        { [ "$1" -ge "$min" ] && [ "$1" -le "$max" ]; } || return 1
        shift
    done
}
