{% extends "admin/login.html" %}
{% load static %}
{% load sso_tags %}
{% load show_form %}
{% load i18n %}

{% block extrastyle %}
    {{ block.super }}
    {% with sso_providers|default:None as sso_providers %}
        {% if sso_providers is None %}
            {% define_sso_providers as sso_providers %}
        {% endif %}
        {% for provider in sso_providers %}
            <link rel="stylesheet" href="{{ provider.css_url }}">
        {% endfor %}
    {% endwith %}
{% endblock %}

{# Default Django Admin Block #}
{% block content %}
    <!--
        You can pass a custom Show Form to this
        template using the `show_admin_form` context variable.
        If not provided, the template will use the default
        `define_show_form` defined in the sso tags.
    -->
    {% with show_admin_form|default:None as show_form %}
        {% if show_form is None %}
            {% define_show_form as show_form %}
        {% endif %}
        {% if show_form %}
            {{ block.super }}
        {% endif %}
        {% include 'microsoft_sso/login_sso.html' %}
    {% endwith %}
{% endblock %}

{# Django Unfold Admin Block #}
{% block base %}
    <style>
        .microsoft-login-btn, .google-login-btn, .github-login-btn {
            height: 100%;
        }
    </style>
    {{ block.super }}  {# Process HTML login elements from Django Unfold #}
    <script>
        {% with show_admin_form|default:None as show_form %}
            {% if show_form is None %}
                {% define_show_form as show_form %}
            {% endif %}
            {% if show_form %}
                $(document).ready(function() {
                    $(".login-box").insertAfter("#login-form");
                });
            {% else %}
                $("#login-form").remove();
                $(document).ready(function() {
                    $(".login-box").insertAfter(".font-semibold.mb-10");
                });
            {% endif %}
        {% endwith %}
    </script>
{% endblock %}
