from django.shortcuts import render
from django.urls import reverse_lazy
from django.views.generic import TemplateView

from registration.backends.default import views as registration_views

from newsreader.news.collection.reddit import (
    get_reddit_access_token,
    get_reddit_authorization_url,
)


# RegistrationView shows a registration form and sends the email
# RegistrationCompleteView shows after filling in the registration form
# ActivationView is send within the activation email and activates the account
# ActivationCompleteView shows the success screen when activation was succesful
# ActivationResendView can be used when activation links are expired
# RegistrationClosedView shows when registration is disabled
class RegistrationView(registration_views.RegistrationView):
    disallowed_url = reverse_lazy("accounts:register-closed")
    template_name = "registration/registration_form.html"
    success_url = reverse_lazy("accounts:register-complete")


class RegistrationCompleteView(TemplateView):
    template_name = "registration/registration_complete.html"


class RegistrationClosedView(TemplateView):
    template_name = "registration/registration_closed.html"


# Redirects or renders failed activation template
class ActivationView(registration_views.ActivationView):
    template_name = "registration/activation_failure.html"

    def get_success_url(self, user):
        return ("accounts:activate-complete", (), {})


class ActivationCompleteView(TemplateView):
    template_name = "registration/activation_complete.html"


# Renders activation form resend or resend_activation_complete
class ActivationResendView(registration_views.ResendActivationView):
    template_name = "registration/activation_resend_form.html"

    def render_form_submitted_template(self, form):
        """
        Renders resend activation complete template with the submitted email.

        """
        email = form.cleaned_data["email"]
        context = {"email": email}

        return render(
            self.request, "registration/activation_resend_complete.html", context
        )
