# shellcheck shell=dash
###
 # @description: set theme hightlight color
 # @param $1:color => black | red | green | yellow | blue | magenta | cyan | white | colour${0~255} | #rrggbb
###
___x_cmd_theme_set_theme_color() {
    local color_code
    local main_color_code
    local minor_color_code
    _______x_cmd_theme_get_color_code "$1"
    main_color_code="$color_code"
    [ -z "$2" ] || _______x_cmd_theme_get_color_code "$2"
    minor_color_code="$color_code"

    export ___X_CMD_THEME_COLOR_KEY="$1"
    export ___X_CMD_THEME_MINOR_COLOR_KEY="${2:-$1}"
    export ___X_CMD_THEME_COLOR_CODE="$main_color_code"
    export ___X_CMD_THEME_MINOR_COLOR_CODE="$minor_color_code"
    _______x_cmd_theme_set_ls_color "$main_color_code"
    _______x_cmd_theme_set_log_color "$main_color_code"
    _______x_cmd_theme_set_complete_color "$main_color_code"
}

_______x_cmd_theme_get_color_code() {
    if [ "${1#\#}" != "${1:?Please provide correct primary color}" ];then
        ___x_cmd_theme_set___rgb_color_code "$1"
        color_code="38;2;$color_code"
    else
        ___x_cmd_theme_set___color_code "$1"
        if [ "${1#colour}" != "$1" ];then
            color_code="38;5;$color_code"
        else
            if [ "$1" = "gray" ]; then  color_code="90";
            else                        color_code="3$color_code";
            fi
        fi
    fi
}


_______x_cmd_theme_set_log_color() { ___X_CMD_LOG_C_INFO="\\033[${1:?"Provide Color code e.g 32"}"m; }

_______x_cmd_theme_set_ls_color() {
    local color_code="${1:?"Provide Color code e.g 32"}"
    # MacOS or FreeBSD
    # if [ "$(uname)" = "Darwin" ] || command -v freebsd-version >/dev/null; then
    local x_=""
    ___x_cmd __osname_
    if [ "$x_" = "darwin" ] || command -v freebsd-version >/dev/null; then
        export CLICOLOR=1
        export LSCOLORS=ExFxCxDxBxegedabagacad
    else
        alias ls='ls --color=auto'
    fi

    local _base="di=${color_code}:ln=1;35:so=1;32:pi=1;33:ex=1;31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43:"
    local _enter="*README.md=01;04;33:*Makefile=01;04;33:*Cargo.toml=01;04;33:*package.json=01;04;33:*Dockerfile=01;04;33:*pom.xml=01;04;33:*Gemfile=01;04;33:*Pipfile=01;04;33:*tsconfig.json=01;04;33:"
    local _static_source="*.jpg=01;35:*.png=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.ico=01;35:"
    local _compressed_source="*.tar=01;31:*.tgz=01;31:*.tar.Z=01;31:*.tar.gz=01;31:*.xz=01;31:*.zip=01;31:*.7z=01;31:*.bz2=01;31:*.rar=01;31:*.tar.xz=01;31:*.lzma=01;31:"
    # LS_COLORS zsh before evaluation, bash after evaluation
    export LS_COLORS="${_base}${_enter}${_static_source}${_compressed_source}"
}
