# shellcheck shell=dash

___x_cmd_webtop_container_pause(){
    local x_=""
    while [ $# -gt 0 ]; do
        case "$1" in
            -h|--help)  ___x_cmd help -m webtop pause         ; return ;;
            -a|--all)   ___x_cmd_webtop_container_pause___all ; return ;;
            --id)       x_="$2";     shift 2 ;;
            *)          break ;;
        esac
    done

    [ -n "$x_" ] || ___x_cmd_webtop_container_id_ "$1" || N=webtop M="Not found any container" log:ret:1

    ___x_cmd docker -- pause "$x_"

    ! ___x_cmd_runmode_allow_chatty || ___x_cmd webtop ps
}

___x_cmd_webtop_container_pause___all(){
    {
        local id
        local name
        while read -r id && read -r name; do
            ___x_cmd docker -- pause "$id"
        done
    } <<A
$(___x_cmd_webtop_container_foreach running)
A

    ! ___x_cmd_runmode_allow_chatty || ___x_cmd webtop ps
}

___x_cmd_webtop_container_unpause(){
    local x_=""
    while [ $# -gt 0 ]; do
        case "$1" in
            -h|--help)  ___x_cmd help -m webtop unpause         ; return ;;
            -a|--all)   ___x_cmd_webtop_container_unpause___all ; return ;;
            --id)       x_="$2";        shift 2 ;;
            *)          break ;;
        esac
    done

    [ -n "$x_" ] || ___x_cmd_webtop_container_id_ "$@" || N=webtop M="Not found any container to restart" log:ret:1

    ___x_cmd docker -- unpause "$x_"
    ! ___x_cmd_runmode_allow_chatty || ___x_cmd_webtop_container_start___ui "$x_"
}

___x_cmd_webtop_container_unpause___all(){
    {
        local id
        local name
        while read -r id && read -r name; do
            webtop:info "Unpausing container [name=$name] [id=$id]"
            ___x_cmd docker -- unpause "$id"
        done
    } <<A
$(___x_cmd_webtop_container_foreach paused)
A

    [ -n "$id" ] || webtop:info "No contaniner to unpause."
    ! ___x_cmd_runmode_allow_chatty || ___x_cmd webtop ps
}


