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

{% block title %}{% trans "Permission" %} {{ object.name }}{% endblock %}

{% block subtitle %}{% endblock %}

{% block content %}
  <div class="row mb-3">
    <div class="col-md-6">
      <div class="card">
        <h2 class="card-header">{% trans "Permission" %}</h2>
        <table class="table table-hover attr-table">
          <tr>
            <th scope="row">{% trans "Name" %}</th>
            <td>{{ object.name }}</td>
          </tr>
          <tr>
            <th scope="row">{% trans "Description" %}</th>
            <td>{{ object.description|placeholder }}</td>
          </tr>
          <tr>
            <th scope="row">{% trans "Enabled" %}</th>
            <td>{% checkmark object.enabled %}</td>
          </tr>
        </table>
      </div>
      <div class="card">
        <h2 class="card-header">{% trans "Actions" %}</h2>
        <table class="table table-hover attr-table">
          <tr>
            <th scope="row">{% trans "View" %}</th>
            <td>{% checkmark object.can_view %}</td>
          </tr>
          <tr>
            <th scope="row">{% trans "Add" %}</th>
            <td>{% checkmark object.can_add %}</td>
          </tr>
          <tr>
            <th scope="row">{% trans "Change" %}</th>
            <td>{% checkmark object.can_change %}</td>
          </tr>
          <tr>
            <th scope="row">{% trans "Delete" %}</th>
            <td>{% checkmark object.can_delete %}</td>
          </tr>
        </table>
      </div>
      <div class="card">
        <h2 class="card-header">{% trans "Constraints" %}</h2>
        <div class="card-body">
          {% if object.constraints %}
            <pre>{{ object.constraints|json }}</pre>
          {% else %}
            <span class="text-muted">None</span>
          {% endif %}
        </div>
      </div>
    </div>
    <div class="col-md-6">
      <div class="card">
        <h2 class="card-header">{% trans "Object Types" %}</h2>
        <ul class="list-group list-group-flush">
          {% for user in object.object_types.all %}
            <li class="list-group-item">{{ user }}</li>
          {% endfor %}
        </ul>
      </div>
      <div class="card">
        <h2 class="card-header">{% trans "Assigned Users" %}</h2>
        <div class="list-group list-group-flush">
          {% for user in object.users.all %}
            <a href="{% url 'users:user' pk=user.pk %}" class="list-group-item list-group-item-action">{{ user }}</a>
          {% empty %}
            <div class="list-group-item text-muted">{% trans "None" %}</div>
          {% endfor %}
        </div>
      </div>
      <div class="card">
        <h2 class="card-header">{% trans "Assigned Groups" %}</h2>
        <div class="list-group list-group-flush">
          {% for group in object.groups.all %}
            <a href="{% url 'users:group' pk=group.pk %}" class="list-group-item list-group-item-action">{{ group }}</a>
          {% empty %}
            <div class="list-group-item text-muted">{% trans "None" %}</div>
          {% endfor %}
        </div>
      </div>
    </div>
  </div>
{% endblock %}
