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

from django.http import HttpRequest, JsonResponse
from django.templatetags.static import static
from django.urls import reverse

from hotpocket_backend.apps.core.conf import settings


def manifest_json(request: HttpRequest) -> JsonResponse:
    light_theme = False
    if request.user.is_anonymous is False:
        light_theme = request.user.settings.get('light_theme', None) or False

    result = {
        'name': settings.SITE_TITLE,
        'short_name': settings.SITE_SHORT_TITLE,
        'start_url': request.build_absolute_uri(
            reverse('ui.associations.browse'),
        ),
        'display': 'standalone',
        'background_color': (
            '#212529'
            if light_theme is False
            else '#ffffff'
        ),
        'theme_color': (
            '#2b3035'
            if light_theme is False
            else
            '#f8f9fa'
        ),
        'icons': [
            {
                'src': request.build_absolute_uri(
                    static('ui/img/icon-192.png'),
                ),
                'sizes': '192x192',
                'type': 'image/png',
            },
            {
                'src': request.build_absolute_uri(
                    static('ui/img/icon-512.png'),
                ),
                'sizes': '512x512',
                'type': 'image/png',
            },
        ],
        'scope': '/',
        'share_target': {
            'action': request.build_absolute_uri(
                reverse('ui.integrations.pwa.share_sheet'),
            ),
            'method': 'POST',
            'enctype': 'multipart/form-data',
            'params': {
                'title': 'title',
                'text': 'text',
                'url': 'url',
                'files': [],
            },
        },
    }

    return JsonResponse(result)
