{% extends 'generic/object.html' %}
{% load render_table from django_tables2 %}

{% block extra_controls %}
    {% if perms.netbox_acls.change_policy %}
        {% if object.type == 'extended' %}
            <a href="{% url 'plugins:netbox_acls:aclextendedrule_add' %}?access_list={{ object.pk }}" class="btn btn-sm btn-primary">
        {% elif object.type == 'standard' %}
            <a href="{% url 'plugins:netbox_acls:aclstandardrule_add' %}?access_list={{ object.pk }}" class="btn btn-sm btn-primary">
        {% endif %}
    <span class="mdi mdi-plus-thick" aria-hidden="true"></span> Rule
    </a>
    {% endif %}
{% endblock extra_controls %}

{% block content %}
    <div class="row mb-3">
        <div class="col col-md-6">
            <div class="card">
                <h5 class="card-header">Access List</h5>
                <div class="card-body">
                    <table class="table table-hover attr-table">
                        <caption>Access List</caption>
                        <tr>
                            <th scope="row">Type</th>
                            <td>{% badge object.get_type_display bg_color=object.get_type_color %}</td>
                        </tr>
                        <tr>
                            <th scope="row">Default Action</th>
                            <td>{% badge object.get_default_action_display bg_color=object.get_default_action_color %}</td>
                        </tr>
                        <tr>
                            <th scope="row">Rules</th>
                            {% if object.type == 'standard' %}
                                <td><a href="{% url 'plugins:netbox_acls:aclstandardrule_list' %}?access_list={{ object.pk }}">{{ object.aclstandardrules.count|placeholder }}</a></td>
                            {% elif object.type == 'extended' %}
                                <td><a href="{% url 'plugins:netbox_acls:aclextendedrule_list' %}?access_list={{ object.pk }}">{{ object.aclextendedrules.count|placeholder }}</a></td>
                            {% endif %}
                        </tr>
                        <tr>
                            <th scope="row">Assigned Host</th>
                            <td>{{ object.assigned_object|linkify }}</td>
                        </tr>
                    </table>
                </div>
            </div>
            {% include 'inc/panels/custom_fields.html' %}
        </div>
        <div class="col col-md-6">
            {% include 'inc/panels/tags.html' %}
            {% include 'inc/panels/comments.html' %}
        </div>
    </div>
    <div class="row">
        <div class="col col-md-12">
            <div class="card">
                <h5 class="card-header">{{ object.get_type_display }} Rules</h5>
                <div class="card-body table-responsive">
                    {% render_table rules_table %}
                </div>
            </div>
        </div>
    </div>
{% endblock content %}
