{% load i18n %}
<table class="table table-bordered table-condensed {% if collapse %}collapse" id="{{ collapse }}"{% endif %}">
  <tr>
    <th class="col-xs-2">Name</th>
    <th class="col-md-7">Clause</th>
    <th class="col-xs-1">Duration</th>
{% if show_edit %}
    <th class="col-xs-1">Toggle</th>
    <th class="col-xs-1">Delete</th>
{% endif %}
{% if show_overwrite %}
    <th class="col-xs-1">Overwrite</th>
{% endif %}
  </tr>
  {% for rule in rule_list %}
  <tr>
    <td>
      <a href="{% url 'rule-edit' rule.id %}">{{ rule.name }}</a>
      {% if rule.parent %}
      <a title="View Parent Rule" href="{% url 'rule-edit' rule.parent.id %}">
        <span class="pull-right glyphicon glyphicon-upload"></span>
      </a>
      {% endif %}
    </td>
    <td
      {% if not rule.enabled %}class="bg-disabled text-muted"{% endif %}
      {% if rule.description %}title="{{rule.description}}"{% endif %}
      style="word-break: break-word;"
      >
      {{ rule.clause }}
      {% if rule.description %}<span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span>{% endif %}
    </td>
    <td>{{ rule.duration }}</td>
{% if show_edit %}
    <td style="white-space: nowrap">
      <input
        type="checkbox"
        {% if rule.enabled %}checked{% endif %}
        data-size="mini"
        data-toggle="toggle"
        data-csrfmiddlewaretoken="{{csrf_token}}"
        data-action="{% url 'rule-toggle' rule.id %}"
        />
    </td>
    <td>
      <form method="post" action="{% url 'rule-delete' rule.id %}" onsubmit="return confirm('{% trans "Delete this Rule?" %}')" style="display: inline">
        {% csrf_token %}
        <button class="btn btn-danger btn-xs">{% trans "Delete" %}</button>
      </form>
    </td>
{% endif %}

{% if show_overwrite %}
<td>
  <form method="post" action="{% url 'rule-overwrite' rule.pk %}" style="display: inline">
    <input name="content_type" type="hidden" value="{{content_type}}" />
    <input name="object_id" type="hidden" value="{{show_overwrite}}" />
    {% csrf_token %}
    <button class="btn btn-warning btn-xs">{% trans "Overwrite" %}</button>
  </form>
</td>
{% endif %}
  </tr>
  {% endfor %}
</table>
