# (c) cavaliba.com - home - context_processor.py


from django.conf import settings

from app_data.aaa import get_aaa
from app_home.configuration import get_configuration
from app_home.home import get_sidebar


def get_info(request):

    context = {}

    aaa = get_aaa(request)

    for k, v in aaa.items():
        if not k.startswith("p_"):
            continue
        context[k] = v

    # version
    context["CAVALIBA_VERSION"] = settings.CAVALIBA_VERSION
    context["CAVALIBA_VERSION_DATE"] = settings.CAVALIBA_VERSION_DATE

    # SIDEBAR
    context["sidebar"] = get_sidebar(aaa)
    if "p_task_view" in aaa["perms"]:
        context["ui_perm_task"] = True

    # ipam
    context["IPAM_APPNAME"] = get_configuration("ipam", "IPAM_APPNAME")

    # status
    context["STATUS_APPNAME"] = get_configuration("status", "STATUS_APPNAME")

    # notif app
    context["SIRENE_APPNAME"] = get_configuration("sirene", "SIRENE_APPNAME")

    # global
    context["GLOBAL_APPNAME"] = get_configuration("home", "GLOBAL_APPNAME")

    # navbar logo or Home icon
    context["LOGO_SIZE"] = int(get_configuration("home", "LOGO_SIZE"))

    # env & sidebar color - 3.21.0
    context["SIDEBAR_ENV"] = get_configuration("home", "SIDEBAR_ENV")
    context["SIDEBAR_COLOR"] = get_configuration("home", "SIDEBAR_COLOR")

    context["ui_change_password"] = getattr(settings, "CAVALIBA_AUTH_MODE", "local") == "local"

    return context
