from django.views import View
from django.shortcuts import render, redirect
from django.contrib.auth.mixins import LoginRequiredMixin 
from django.http import HttpResponseNotAllowed, HttpResponse


# from apps.core.utils import check_user

# Create your views here.

class DashboardView(LoginRequiredMixin, View):
    login_url = "/auth/login"  # Specify the login URL

    def get(self, request, *args, **kwargs):
        # Handle GET request logic here, such as displaying dashboard data.
        return render(request, "core/dashboard.html")  # Assuming you have a template named "dashboard.html"

    def post(self, request, *args, **kwargs):
        # Handle POST request logic here, such as processing form data.
        # For demonstration, let"s just redirect to the dashboard after processing the POST request.
        return redirect("core:dashboard")

    def dispatch(self, request, *args, **kwargs):
        # Handle other HTTP methods using dispatch method
        if request.method not in ["GET", "POST"]:
            return HttpResponseNotAllowed(["GET", "POST"])
        return super().dispatch(request, *args, **kwargs)


def theme_mode(request):
    # Retrieve the value of 'current_mode' from GET parameters
    current_mode = request.GET.get('current_mode')
    # Set 'theme_mode' in the session based on the value of 'current_mode'
    request.session['theme_mode'] = '' if current_mode == 'light' else 'dark-mode'
    # Return an empty HTTP response
    return HttpResponse('')