# shellcheck shell=sh disable=SC2034,SC2154,SC3043

# Section: ls zip file
# TODO: Figure out whether it can be normalized to be <file> <size>

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

    while [ $# -gt 0 ]; do
        case "$1" in
            # -1)         ___X_CMD_ZUZ_ONEMODE=1; shift   ;;
            -h|--help)  ___x_cmd_zuz -h ls; return       ;;
            *)          break                           ;;
        esac
    done
    local ___X_CMD_ZUZ_NOT_UI=1
    local target_file="${1:-filename}"; shift
    case "$target_file" in
        *.tar)      LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_zuz_run tar -t <"$target_file"     ;; # bsdtar

        *.tar.bz2)  ___x_cmd_zuz_run ___x_cmd 7z l -ba "$target_file" | ___x_cmd_cmds_awk '{ print $NF }' ;;
        *.tar.gz)   LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_zuz_run tar -zt <"$target_file"    ;; # bsdtar
        *.tar.xz)   ___x_cmd_zuz_run ___x_cmd 7z l -ba "$target_file" | ___x_cmd_cmds_awk '{ print $NF }' ;;
        *.tar.Z)    LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_zuz_run tar -zt <"$target_file"    ;; # bsdtar

        *.tgz)      LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_zuz_run tar -zt <"$target_file"    ;; # bsdtar

        *.bz2|*.gz|*.xz|*.zst|.Z|*.rar)
                    zuz:error "Listing archive contents is not supported.">&2
                    return 1
                    ;;

        *.zip)      ___x_cmd_zuz_run ___x_cmd 7z l -ba "$target_file" | ___x_cmd_cmds_awk '{ print $NF }' ;;
        *.7z)       ___x_cmd_zuz_run ___x_cmd 7z l -ba "$target_file" | ___x_cmd_cmds_awk '{ print $NF }' ;;
        *)          ___x_cmd_zuz --help
                    zuz:warn "Unsupported to resolve as $target_file format."
                    return 1
                    ;;
    esac
}

### EndSection
