# -*- coding: utf-8 -*-
from __future__ import annotations

from django.http import HttpRequest

from hotpocket_backend._meta import version as backend_version
from hotpocket_backend.apps.core.conf import settings
from hotpocket_backend.apps.core.context import get_request_id


def site_title(request: HttpRequest) -> dict:
    return {
        'SITE_TITLE': settings.SITE_TITLE,
    }


def image_tag(request: HttpRequest) -> dict:
    return {
        'IMAGE_ID': settings.IMAGE_ID,
    }


def request_id(request: HttpRequest) -> dict:
    return {
        'REQUEST_ID': get_request_id(),
    }


def htmx(request: HttpRequest) -> dict:
    return {
        'HTMX': (
            request.htmx
            if hasattr(request, 'htmx')
            else False
        ),
    }


def debug(request: HttpRequest) -> dict:
    return {
        'DEBUG': settings.DEBUG,
    }


def version(request: HttpRequest) -> dict:
    return {
        'VERSION': backend_version,
    }


def appearance_settings(request: HttpRequest) -> dict:
    theme = 'hotpocket'
    result = {
        'theme': theme,
        'light_mode': False,
        'theme_css': 'ui/css/bootstrap-hotpocket.min.css',
    }

    if request.user.is_anonymous is False:
        theme = request.user.settings.get('theme', 'hotpocket')
        result.update({
            'theme': theme,
            'light_mode': request.user.settings['light_mode'],
        })

    match theme:
        case 'bootstrap':
            result['theme_css'] = 'ui/css/bootstrap.min.css'

        case 'cosmo':
            result['theme_css'] = 'ui/css/cosmo.min.css'

        case 'solar':
            result['theme_css'] = 'ui/css/solar.min.css'

        case 'sandstone':
            result['theme_css'] = 'ui/css/sandstone.min.css'

        case 'sketchy':
            result['theme_css'] = 'ui/css/sketchy.min.css'

    return {
        'APPEARANCE_SETTINGS': result,
    }


def base_includes(request: HttpRequest) -> dict:
    return {
        'BASE_INCLUDES': {
            'head': settings.UI_BASE_HEAD_INCLUDES,
            'script': settings.UI_BASE_SCRIPT_INCLUDES,
        },
    }


def page_includes(request: HttpRequest) -> dict:
    return {
        'PAGE_INCLUDES': {
            'head': settings.UI_PAGE_HEAD_INCLUDES,
            'script': settings.UI_PAGE_SCRIPT_INCLUDES,
        },
    }


def operator_email(request: HttpRequest) -> dict:
    return {
        'OPERATOR_EMAIL': settings.OPERATOR_EMAIL,
    }
