{% extends 'core/page.html' %}
{% load i18n %}

{% block page %}

    <h1>{% trans "Account connections" %}</h1>

    <h2>{% trans 'Current connections' %}</h2>

    {% if form.accounts %}

    <p>
        {% blocktrans trimmed %}
        You can sign in to your account using any of the following third party accounts:
        {% endblocktrans %}
    </p>

    <form class="mb-5" method="post" action="{% url 'socialaccount_connections' %}">
        {% csrf_token %}

        {% for base_account in form.accounts %}
        {% with base_account.get_provider_account as account %}

        <div class="d-flex gap-1 align-items-center pt-2 pb-2 border-top {% if forloop.last %}border-bottom{% endif %}">
            <div class="form-radio">
                <input class="form-radio-input" id="id_account_{{ base_account.id }}"
                       type="radio" name="account" value="{{ base_account.id }}"/>
                <label class="form-radio-label ms-1" for="id_account_{{ base_account.id }}">
                    <span>{{account.get_brand.name}}</span>
                    <span>({{ account }})</span>
                </label>
            </div>
        </div>
        {% endwith %}
        {% endfor %}

        {% if form.non_field_errors %}
        <ul class="list-unstyled text-danger mt-3">
        {% for error in form.non_field_errors %}
            <li>{{ error }}</li>
        {% endfor %}
        </ul>
        {% endif %}

        <div class="mt-3">
            <button class="btn btn-outline-danger" type="button" data-bs-toggle="modal" data-bs-target="#remove-account-modal">
                {% trans 'Remove selected account' %}
            </button>
        </div>

        <div class="modal" id="remove-account-modal" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">{% trans 'Remove account' %}</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>

                    <div class="modal-body">
                        {% trans 'Do you really want to remove the selected account?' %}
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
                            {% trans 'Close' %}
                        </button>
                        <button type="submit" class="btn btn-danger">
                            {% trans 'Remove' %}
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </form>

    {% else %}

    <p>
        {% trans 'You currently have no social network accounts connected to this account.' %}
    </p>

    {% endif %}

    <h2>{% trans 'Add an additional account' %}</h2>

    <ul class="list-inline">
    {% include "socialaccount/snippets/provider_list.html" with process="connect" %}
    </ul>

    {% include "socialaccount/snippets/login_extra.html" %}

{% endblock %}
