from django.shortcuts import render
from django.views.decorators.http import require_GET

from territories_dashboard_lib.website_lib.views.utils import (
    get_theme_and_sub_themes,
    get_themes,
)


@require_GET
def left_menu_view(request, theme_name):
    comparison = request.GET.get("comparison") == "true"
    theme, sub_themes = get_theme_and_sub_themes(request, theme_name)
    themes = get_themes(request)
    context = {
        "theme": theme,
        "themes": themes,
        "sub_themes": sub_themes,
        "comparison": comparison,
    }
    if request.user.is_authenticated and request.user.favorite_indicators.count() == 1:
        context["new_favorite"] = True
    return render(
        request,
        "territories_dashboard_lib/website/pages/indicators/components/themes-nav.html",
        context,
    )
