# shellcheck shell=sh disable=SC3043 disable=SC2034,SC2154
# ___x_cmd_theme_theme_render()

___x_cmd_theme_prompt_format(){
    local x_=;  theme:feature:get mini_enable

    case "$x_" in
        always) ___x_cmd_theme_el mini ;;
        *)      ___x_cmd_theme_el ;;
    esac
}

___x_cmd_theme_el(){
    case "$1" in
        mini)       ___x_cmd_theme_elmini "$@"  ;;
        *)          ___x_cmd_theme_elfull "$@"  ;;
    esac
}

# Section: mini layout
___x_cmd_theme_elmini(){
    XTW_cwd1_style_tail="${XTW_cwd_style_tail}"
    ___x_cmd_theme_mini
}
# EndSection

# Section: elfull layout
xrc:theme:widget msg symbol

___x_cmd_theme_elfull(){
    local x_;
    local space="  "

    ___x_cmd_theme_headline_print

    {
        ___x_cmd_theme_el_left
        ___x_cmd_theme_el_right
        _prompt="${X_left}${space}${X_right}"

        ______x_cmd_theme_prompt_remove_escapes_ "$_prompt"
        if [ -n "$COLUMNS" ] && [ "${#x_}" -gt "$((  COLUMNS - COLUMNS / 3 ))" ]; then
            printf "%s\n"   "$X_right"
            printf "%s"     "$X_left"
        elif [ -n "$___X_CMD_THEME_COLUMN2" ]; then
            theme:col2_  "${X_left}" "${X_right}"
            printf "%s"   "$x_"
        else
            printf "%s"     "$_prompt"
        fi
    }

    {
        ___x_cmd_theme_widget_symbol
        printf "\n%s "      "${X_symbol}"
    }

}

# EndSection

xrc:theme:widget cwd vcm emoji
___x_cmd_theme_el_left(){
    X_left=

    ___x_cmd_theme_widget_cwd
    [ -z "$X_cwd" ] || X_left="${X_left}${X_cwd}"

    ___x_cmd_theme_widget_vcm
    [ -z "$X_vcm" ] || X_left="${X_vcm}${space}${X_left}"

    ___x_cmd_theme_widget_emoji
    [ -z "$X_emoji" ] || X_left="${X_emoji}${space}${X_left}"
}

xrc:theme:widget username hosttag subsys exitcode hms
___x_cmd_theme_el_right(){
    X_right=""

    ___x_cmd_theme_widget_username
    [ -z "$X_username" ]    || X_right="${X_right}${space}${X_username}"

    if [ -n "${x_docker}${x_ssh}${x_htag_server}" ] && [ -z "$x_tmux" ]; then
        ___x_cmd_theme_widget_hosttag
        [ -z "$X_hosttag" ] || X_right="${X_right}${space}${X_hosttag}"
    fi

    ___x_cmd_theme_widget_subsys
    [ -z "$X_subsys" ]      || X_right="${X_right}${space}${X_subsys}"

    ___x_cmd_theme_widget_exitcode
    [ -z "$X_exitcode" ]    || X_right="${X_right}${space}${X_exitcode}"

    ___x_cmd_theme_widget_hms
    [ -z "$X_hms" ]         || X_right="${X_right}${space}${X_hms}"

    X_right="${X_right#"${space}"}"
}

___x_cmd_theme_el_init(){
    local x_=""
    theme:style_ "$XT_EL_subsys_style" WSL
    XTW_subsys_wsl_default="$x_"

    theme:style_ "$XT_EL_subsys_style" MSYS
    XTW_subsys_msys_default="$x_"
}

___x_cmd_theme_linecount_ps1=3
