{% extends "base.html" %}
{% block title %}List{% endblock %}

{% block styles %}
{{super()}}
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css">
{% endblock %}

{% block content %}
<div class="container">
  <h1>{{ title }}</h1>
  <table class="table table-hover">
      {% for item in items %}
      {% if loop.index == 1 and item._data_headers is defined %}
      <thead style="position: sticky; top: 0; background-color: white">
      <tr>
          <th scope="col">#</th>
          {% for h in item._data_headers %}
          <th>{{ h }}</th>
          {% endfor %}
          {% if item._actions is defined %}
          <th></th>
          {% endif %}
          {% if item._admin_actions is defined and current_user.role == 'admin' %}
          <th></th>
          {% endif %}
      </tr>
      </thead>
      <tbody>
      {% endif %}
      <tr>
          <th scope="row">{{ loop.index }}</th>
          {% if item._data_columns is defined %}
          {% for c in item._data_columns %}
	    <td>
	    {% if c._self_reference_url is defined %}
	      <a href="{{ c._self_reference_url }}"
		 style="color: black">
	      {{ c | string | truncate(50, True, '...') }}
	      </a>
	    {% else %}
	      {{ c | string | truncate(50, True, '...') }}
	    {% endif %}
	    {% if c._add_action is defined %}
	      <a href="{{ c._add_action }}">
	      <i class="bi bi-clipboard-plus"></i>
	      </a>
	    {% endif %}
            </td>
          {% endfor %}
          {% else %}
          <td>{{ item }}</td>
          {% endif %}
          {% if item._actions is defined %}
          <td>
              {% for action in item._actions %}
              <a href="{{ action[0] }}">
              <i class="{{ action[1] }}"></i>
              </a>
              {% endfor %}
          </td>
          {% endif %}
          {% if item._admin_actions is defined and current_user.role == 'admin' %}
          <td>
              {% for action in item._admin_actions %}
              <a href="{{ action[0] }}">
              <i class="{{ action[1] }}"></i>
              </a>
              {% endfor %}
          </td>
          {% endif %}
      </tr>
      {% if loop.last and item._data_headers is defined %}
      </tbody>
      {% endif %}
      {% endfor %}
  </table>
</div>
{% endblock %}
