# shellcheck shell=dash

___x_cmd_ping___run___busybox_raw_inner(){
    local host="$1";    shift
    [ -n "$host" ] || N=ping M="Not found host" log:ret:1
    [ "$count" -eq 0 ] || set -- -c "$count"

    (
        while printf "%s\n" "MOCK_SEND" && sleep "$wait"; do
            :
        done 2>/dev/null
    ) 2>/dev/null &

    if [ -z "$USE_BUSYBOX_BIN" ]; then
        # TODO: use sudo
        LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_cmds ping "$@" -W "${wait}" "$host"
    else
        ping:info "ping command not found, use the busybox's ping command"
        # TODO: use sudo
        LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd busybox ping "$@" -W "${wait}" "$host"
    fi
}

___x_cmd_ping___run___busybox_raw(){
    ___x_cmd_ping___run___busybox_raw_inner "$@" | ___x_cmd_cmds cat
}

___x_cmd_ping___run___busybox_raw_warn(){
    ping:warn "Because the busybox version of ping doesn't print any output when packets are lost, the current statistics are inaccurate and can't show the number of dropped packets."
}

___x_cmd_ping___run___busybox(){
    local x_=""; ___x_cmd term color_ || x_=8

    ___x_cmd_ping___run___busybox_raw_inner "$@" |    \
        ___x_cmd_ping___run___awk               \
            -v mode="$MODE"                     \
            -v sytle_color="$x_"                \
            -f "${___X_CMD_ROOT_MOD}/ping/lib/awk/sample.awk"       \
            -f "${___X_CMD_ROOT_MOD}/ping/lib/awk/share.awk"        \
            -f "${___X_CMD_ROOT_MOD}/ping/lib/awk/vis.awk"          \
            -f "${___X_CMD_ROOT_MOD}/ping/lib/awk/busybox.awk"
}
