from django.urls import reverse
from django.views.generic.base import ContextMixin


# TODO: render menu in non-homepage pages
class NavListMixin(ContextMixin):
    def get_context_data(self, **kwargs: dict):
        context_data = super().get_context_data(**kwargs)

        authenticated_links = {
            "Home": reverse("index"),
            "Categories": reverse("news:core:categories"),
            "Sources": reverse("news:collection:rules"),
            "Settings": reverse("accounts:settings:home"),
        }

        if self.request.user.is_authenticated:
            authenticated_links["Admin"] = reverse("admin:index")

        authenticated_links["Logout"] = reverse("accounts:logout")

        unauthenticated_links = {
            "Login": reverse("accounts:login"),
        }

        if self.request.user.is_authenticated:
            return {**context_data, "sidebar_links": authenticated_links}

        return {**context_data, "sidebar_links": unauthenticated_links}
