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

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

{% block content %}
  <div class="row mb-3">
    <div class="col col-md-6">
      <div class="card">
        <h2 class="card-header">Access List</h2>
        <table class="table table-hover attr-table">
          <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_id={{ object.pk }}">{{ object.aclstandardrules.count|placeholder }}</a>
              </td>
            {% elif object.type == 'extended' %}
              <td>
                <a href="{% url 'plugins:netbox_acls:aclextendedrule_list' %}?access_list_id={{ 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>
      {% 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">
        <h2 class="card-header">{{ object.get_type_display }} Rules</h2>
        <div class="table-responsive">
          {% render_table rules_table %}
        </div>
      </div>
    </div>
  </div>
{% endblock content %}
