{% load i18n %}
<div class="container px-md-3 py-3 column-gap-5">
  <div class="tw-text-3xl fw-bold font-monospace tw-w-full mb-3">
    {% spaceless %}
    <div>{% translate 'Rules' %}<span>
      <a class="text-decoration-none tw-text-2xl p-1 category-action"
                role="button"
                data-bs-toggle="tooltip"
                data-bs-title="{% translate "Add" %}"
                hx-get="{% url 'transaction_rule_add' %}"
                hx-target="#generic-offcanvas">
            <i class="fa-solid fa-circle-plus fa-fw"></i></a>
    </span></div>
    {% endspaceless %}
  </div>

  <div class="card">
    <div class="card-body table-responsive">
      {% if transaction_rules %}
      <c-config.search></c-config.search>
      <table class="table table-hover">
        <thead>
          <tr>
            <th scope="col" class="col-auto"></th>
            <th scope="col" class="col-auto"></th>
            <th scope="col" class="col">{% translate 'Name' %}</th>
          </tr>
        </thead>
        <tbody>
          {% for rule in transaction_rules %}
          <tr class="transaction_rule">
            <td class="col-auto">
              <div class="btn-group" role="group" aria-label="{% translate 'Actions' %}">
                <a class="btn btn-secondary btn-sm"
                      role="button"
                      data-bs-toggle="tooltip"
                      data-bs-title="{% translate "View" %}"
                      hx-get="{% url 'transaction_rule_view' transaction_rule_id=rule.id %}"
                      hx-target="#persistent-generic-offcanvas-left">
                  <i class="fa-solid fa-eye fa-fw"></i></a>
                <a class="btn btn-secondary btn-sm text-danger"
                        role="button"
                        data-bs-toggle="tooltip"
                        data-bs-title="{% translate "Delete" %}"
                        hx-delete="{% url 'transaction_rule_delete' transaction_rule_id=rule.id %}"
                        hx-trigger='confirmed'
                        data-bypass-on-ctrl="true"
                        data-title="{% translate "Are you sure?" %}"
                        data-text="{% translate "You won't be able to revert this!" %}"
                        data-confirm-text="{% translate "Yes, delete it!" %}"
                        _="install prompt_swal"><i class="fa-solid fa-trash fa-fw"></i></a>
              </div>
            </td>
            <td class="col-auto">
               <a class="text-decoration-none"
                    role="button"
                    data-bs-toggle="tooltip"
                    data-bs-title="{% if rule.active %}{% translate "Deactivate" %}{% else %}{% translate "Activate" %}{% endif %}"
                    hx-get="{% url 'transaction_rule_toggle_activity' transaction_rule_id=rule.id %}">
                 {% if rule.active %}<i class="fa-solid fa-toggle-on tw-text-green-400"></i>{% else %}<i class="fa-solid fa-toggle-off tw-text-red-400"></i>{% endif %}
               </a>
            </td>
            <td class="col">
              <div>{{ rule.name }}</div>
              <div class="tw-text-gray-400">{{ rule.description }}</div>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      {% else %}
      <c-msg.empty title="{% translate "No rules" %}" remove-padding></c-msg.empty>
      {% endif %}
    </div>
  </div>
</div>
