{% extends 'netbox_dns/object.html' %}
{% load helpers %}
{% load plugins %}
{% load render_table from django_tables2 %}
{% load view_helpers %}
{% load perms %}

{% block content %}
    <div class="row">
        <div class="col col-md-6">
            <div class="card">
                <h5 class="card-header">Name Server</h5>
                <div class="card-body">
                    <table class="table table-hover attr-table">
                        <tr>
                            <th scope="row">Name</th>
                            <td>{{ object.name }}</td>
                        </tr>
                    </table>
                </div>
            </div>
            {% include 'inc/custom_fields_panel.html' %}
        </div>
        <div class="col col-md-6">
            {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='plugins:netbox_dns:nameserver_list' %}
        </div>
    </div>

    <div class="row">
        <div class="col col-md-12">
            <div class="card">
                <h5 class="card-header">Zones</h5>
                <div class="card-body">

                    {# "Select all" form #}
                    {% if zone_table.paginator.num_pages > 1 %}
                        {% with bulk_edit_url="plugins:netbox_dns:zone_bulk_edit" bulk_delete_url="plugins:netbox_dns:zone_bulk_delete" %}
                        <div id="select-all-box" class="d-none card noprint">
                            <form method="post" class="form col-md-12">
                                {% csrf_token %}
                                <input type="hidden" name="return_url" value="{% if return_url %}{{ return_url }}{% else %}{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}{% endif %}" />
                                <div class="card-body">
                                    <div class="float-end">
                                        {% if bulk_edit_url and permissions.change %}
                                            <button type="submit" name="_edit" formaction="{% url bulk_edit_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-warning btn-sm" disabled>
                                                <span class="mdi mdi-pencil" aria-hidden="true"></span> Edit All
                                            </button>
                                        {% endif %}
                                        {% if bulk_delete_url and permissions.delete %}
                                            <button type="submit" name="_delete" formaction="{% url bulk_delete_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-danger btn-sm" disabled>
                                                <span class="mdi mdi-trash-can-outline" aria-hidden="true"></span> Delete All
                                            </button>
                                        {% endif %}
                                    </div>
                                        <div class="form-check">
                                           <input type="checkbox" id="select-all" name="_all" class="form-check-input" />
                                           <label for="select-all" class="form-check-label">
                                               Select <strong>all {{ zone_table.rows|length }} Zones</strong> matching query
                                           </label>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        {% endwith %}
                    {% endif %}

                    {# Object table controls #}
                    {% include 'inc/table_controls.html' with table_modal="ZoneTable_config" %}

                    <form method="post" class="form form-horizontal">
                        {% csrf_token %}
                        <input type="hidden" name="return_url" value="{% if return_url %}{{ return_url }}{% else %}{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}{% endif %}" />

                        {# Object table #}
                        <div class="table-responsive">
                            {% render_table zone_table 'inc/table.html' %}
                        </div>

                        {# Form buttons #}
                        {% if permissions.change or permissions.delete %}
                            {% with bulk_edit_url="plugins:netbox_dns:zone_bulk_edit" bulk_delete_url="plugins:netbox_dns:zone_bulk_delete" %}
                                <div class="noprint bulk-buttons">
                                    <div class="bulk-button-group">
                                        {% block bulk_buttons %}{% endblock %}
                                        {% if bulk_edit_url and permissions.change %}
                                            <button type="submit" name="_edit" formaction="{% url bulk_edit_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-warning btn-sm">
                                                <i class="mdi mdi-pencil" aria-hidden="true"></i> Edit Selected
                                            </button>
                                        {% endif %}
                                        {% if bulk_delete_url and permissions.delete %}
                                            <button type="submit" name="_delete" formaction="{% url bulk_delete_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-danger btn-sm">
                                                <i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> Delete Selected
                                           </button>
                                        {% endif %}
                                    </div>
                                </div>
                            {% endwith %}
                        {% endif %}
                    </form>

                    {# Paginator #}
                    {% include 'inc/paginator.html' with paginator=zone_table.paginator page=zone_table.page %}

                </div>
            </div>
        </div>
    </div>
    {# Table config form #}
    {% table_config_form zone_table table_name="ZoneTable" %}
{% endblock %}
