{% extends 'multimail/page.html' %}

{% block content %}
    <div class="pt-3">
    {% if domain_list %}
        <div class="card-columns">
            {% for domain in domain_list %}
                <div class="card">
                    <h5 class="card-header"><a
                            href="{% url 'multimail:edit_domain' domain.id %}">{{ domain.domain }}</a></h5>
                    <table class="table table-striped btn-table mb-0">
                        {% if domain.mailboxes %}
                            <thead>
                            <tr class="bg-dark">
                                <th scope="col">Mailboxes</th>
                                <th scope="col"></th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for mailbox in domain.mailboxes %}
                                <tr>
                                    <th scope="row"><a
                                            href="{% url 'multimail:edit_mailbox' mailbox.id %}">{{ mailbox.username }}@{{ mailbox.domain }}</a>
                                    </th>
                                    <td><a href="{% url 'multimail:delete_mailbox' mailbox.id %}"
                                           class="btn btn-outline-danger btn-sm m-0"><i
                                            class="fas fa-trash"></i></a></td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        {% else %}
                            <tbody>
                            <tr>
                                <td colspan="2" class="text-muted"><small>You dont't have any mailboxes for this domain yet.</small></td>
                            </tr>
                            </tbody>
                        {% endif %}
                        {% if domain.aliases %}
                            <tbody>
                            <tr class="bg-dark">
                                <th scope="col">Aliases</th>
                                <th scope="col"></th>
                            </tr>
                            </tbody>
                            <tbody>

                            {% for alias in domain.aliases %}
                                <tr>
                                    <th scope="row"><a
                                            href="{% url 'multimail:edit_alias' alias.id %}">{{ alias.source_username }}@{{ alias.source_domain }}</a>
                                        {{ alias.destination_username }}@{{ alias.destination_domain }}
                                    </th>
                                    <td><a href="{% url 'multimail:delete_alias' alias.id %}"
                                           class="btn btn-outline-danger btn-sm m-0"><i
                                            class="fas fa-trash"></i></a></td>
                                </tr>
                            {% endfor %}

                            </tbody>
                        {% else %}
                            <tbody>
                            <tr>
                                <td colspan="2" class="text-muted"><small>You dont't have any aliases for this domain yet.</small></td>
                            </tr>
                            </tbody>
                        {% endif %}
                    </table>
                    <div class="card-footer">
                        <div class="btn-group btn-block" data-toggle="buttons">
                            <a href="{% url 'multimail:new_mailbox' %}"
                               class="btn btn-primary btn-sm">Add Mailbox</a>
                            <a href="{% url 'multimail:new_alias' %}"
                               class="btn btn-primary btn-sm">Add Alias</a>
                            <a href="{% url 'multimail:delete_domain' domain.id %}"
                               class="btn btn-outline-danger btn-sm">Delete Domain</a>
                        </div>
                    </div>
                </div>
            {% endfor %}
            <div class="card">
                <div class="card-body">
                    <h5 class="card-title">New Domain</h5>
                    <a href="{% url 'multimail:new_domain' %}" class="btn btn-primary btn-sm m-0">Add Domain</a>
                </div>
            </div>
        </div>
    {% else %}
        <p>You haven't set up any domains yet.</p>
        <a href="{% url 'multimail:new_domain' %}" class="btn btn-primary btn-sm m-0">Add Domain</a>
    {% endif %}
</div>
{% endblock %}