# shellcheck shell=dash disable=SC1091

. "$___X_CMD_ROOT_MOD/theme/lib/theme/el/_index"

xrc:theme:widget pl
___x_cmd_theme_elfull(){
    local x_;

    ___x_cmd_theme_headline_print

    {
        if [ -n "$___X_CMD_THEME_COLUMN2" ]; then
            ___x_cmd_theme_el_left
            ___x_cmd_theme_el_right left
            ___x_cmd_theme_widget_pl_horn "$XT_ELPL_cwd_style_trunk" "" "right"
            X_left="${X_left}${X_pl_horn}"
            ___x_cmd_theme_widget_pl_horn "" "$XT_ELPL_username_style_name" "left"
            X_right="${X_pl_horn}${X_right}"
            theme:col2_  "${X_left}" "${X_right}"
            printf "%s"   "$x_"
        else
            ___x_cmd_theme_el_left
            ___x_cmd_theme_el_right right
            ___x_cmd_theme_widget_pl_horn "$XT_ELPL_cwd_style_trunk" "$XT_ELPL_username_style_name" "right"
            _prompt="${X_left}${X_pl_horn}${X_right}"
            ______x_cmd_theme_prompt_remove_escapes_ "$_prompt"
            if [ -n "$COLUMNS" ] && [ "${#x_}" -gt "$((  COLUMNS - COLUMNS / 3 ))" ]; then
                printf "%s\n"   "$X_right"
                ___x_cmd_theme_widget_pl_horn "$XT_ELPL_cwd_style_trunk" "" "right"
                X_left="${X_left}${X_pl_horn}"
                printf "%s"     "$X_left"
            else
                printf "%s"     "$_prompt"
            fi
        fi
    }

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

# TODO: el powerline
___x_cmd_theme_el_left(){
    X_left=

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

    XTW_vcm_style_clean="bg-${XT_ELPL_vcm_style_clean} fg-black"
    XTW_vcm_style_dirty="bg-${XT_ELPL_vcm_style_dirty} fg-black"
    ___x_cmd_theme_widget_vcm
    [ -z "$X_vcm" ] || {
        if [ -n "$x_git_changed" ]; then
            horn_leftstyle="$XT_ELPL_vcm_style_dirty"
        else
            horn_leftstyle="$XT_ELPL_vcm_style_clean"
        fi

        X_left="${X_left}${X_vcm}"
    }
    XTW_cwd_style_trunk="bg-${XT_ELPL_cwd_style_trunk}"
    XTW_cwd_style_root="$XTW_cwd_style_trunk"
    XTW_cwd_style_rootfolder="$XTW_cwd_style_trunk"
    XTW_cwd_style_sep="$XTW_cwd_style_trunk"
    XTW_cwd_style_tail="${XTW_cwd_style_trunk} fg-${XT_ELPL_cwd_style_tail}"
    ___x_cmd_theme_widget_cwd
    [ -z "$X_cwd" ] || {
        ___x_cmd_theme_widget_pl_horn "$horn_leftstyle" "$XT_ELPL_cwd_style_trunk"
        X_left="${X_left}${X_pl_horn}${X_cwd}"
        horn_leftstyle="$XT_ELPL_cwd_style_trunk"
    }

}

___x_cmd_theme_el_right(){
    local direction="${1:-right}"
    local last_style="$horn_leftstyle"
    X_right=""

    XTW_username_style_name="bg-${XT_ELPL_username_style_name}"
    XTW_username_style_at="${XTW_username_style_name} fg-${XT_ELPL_username_style_at}"
    XTW_username_style_ip="${XTW_username_style_name} fg-${XT_ELPL_username_style_ip}"

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

    if [ -n "${x_docker}${x_ssh}${x_htag_server}" ] && [ -z "$x_tmux" ]; then
        XT_ELPL_hosttag_style_bg="bg-${XT_ELPL_hosttag_style}"
        XTW_hosttag_style_sep="white dim ${XT_ELPL_hosttag_style_bg}"
        XTW_hosttag_style_host_docker="fg-white bg-magenta ${XT_ELPL_hosttag_style_bg}"
        XTW_hosttag_style_host_normal="white dim ${XT_ELPL_hosttag_style_bg}"

        XTW_hosttag_style_server_dev="cyan ${XT_ELPL_hosttag_style_bg}"
        XTW_hosttag_style_server_test="yellow ${XT_ELPL_hosttag_style_bg}"
        XTW_hosttag_style_server_prod="bold red ${XT_ELPL_hosttag_style_bg}"
        XTW_hosttag_style_server_default="dim white ${XT_ELPL_hosttag_style_bg}"

        XTW_hosttag_style_other="dim white ${XT_ELPL_hosttag_style_bg}"

        ___x_cmd_theme_widget_hosttag
        [ -z "$X_hosttag" ] || {
            ___x_cmd_theme_widget_pl_horn "$horn_leftstyle" "${XT_ELPL_hosttag_style}" "$direction"
            X_right="${X_right}${X_pl_horn}${X_hosttag}"
            horn_leftstyle="${XT_ELPL_hosttag_style}"
        }
    fi

    ___x_cmd_theme_widget_subsys
    [ -z "$X_subsys" ] || {
        ___x_cmd_theme_widget_pl_horn "$horn_leftstyle" "${XT_ELPL_subsys_style}" "$direction"
        X_right="${X_right}${X_pl_horn}${X_subsys}"
        horn_leftstyle="$XT_ELPL_subsys_style"
    }

    XTW_exitcode_style="bg-${XT_ELPL_exitcode_style}"
    ___x_cmd_theme_widget_exitcode
    [ -z "$X_exitcode" ] || {
        ___x_cmd_theme_widget_pl_horn "$horn_leftstyle" "${XT_ELPL_exitcode_style}" "$direction"
        X_right="${X_right}${X_pl_horn}${X_exitcode}"
        horn_leftstyle="$XT_ELPL_exitcode_style"
    }

    XTW_hms_style_true="bg-${XT_ELPL_hms_style_true}"
    XTW_hms_style_false="bg-${XT_ELPL_hms_style_false}"
    ___x_cmd_theme_widget_hms
    [ -z "$X_hms" ] || {
        if [ -n "$x_exitok" ]; then
            ___x_cmd_theme_widget_pl_horn "$horn_leftstyle" "$XT_ELPL_hms_style_true" "$direction"
            horn_leftstyle="$XT_ELPL_hms_style_true"
        else
            ___x_cmd_theme_widget_pl_horn "$horn_leftstyle" "$XT_ELPL_hms_style_false" "$direction"
            horn_leftstyle="$XT_ELPL_hms_style_false"
        fi
        X_right="${X_right}${X_pl_horn}${X_hms}"
    }

    if [ "$direction" = right ]; then
        ___x_cmd_theme_widget_pl_horn "$horn_leftstyle" "" right
        X_right="${X_right}${X_pl_horn}"
    fi

}

___x_cmd_theme_elpl_init(){
    # Subsys
    local x_=
    theme:style_ "bg-${XT_ELPL_subsys_style}" ' WSL '
    XTW_subsys_wsl_default="$x_"

    theme:style_ "bg-${XT_ELPL_subsys_style}" ' MSYS '
    XTW_subsys_msys_default="$x_"

}

XTW_vcm_ref_prefix=" ("
XTW_vcm_ref_suffix=") "
XTW_cwd_text_prefix=" "
XTW_cwd_text_suffix=" "
XTW_username_name_prefix=" "
XTW_username_ip_suffix=" "
XTW_exitcode_text_prefix=" exit="
XTW_exitcode_text_suffix=" "
XTW_hms_text_prefix=" "
XTW_hms_text_suffix=" "

case "$___X_CMD_THEME_TERM_COLORTYPE" in
    *)
        XT_ELPL_vcm_style_dirty="226"
        XT_ELPL_vcm_style_clean="15"

        XT_ELPL_cwd_style_trunk="26"
        XT_ELPL_cwd_style_tail="172"

        XT_ELPL_username_style_name="75"
        XT_ELPL_username_style_at="247"
        XT_ELPL_username_style_ip="31"

        XT_ELPL_hosttag_style="247"
        XT_ELPL_subsys_style="243"

        XT_ELPL_exitcode_style="124"

        XT_ELPL_hms_style_true="28"
        XT_ELPL_hms_style_false="203"
        ;;
esac

___x_cmd_theme_elpl_init
