{% if documents[0].directory is not defined %}{% set nodirectorylink = true %}{% endif %}
{% set slicelimit = (limit is defined)? limit : null %}  
{% set counter = 0 %}

{% if documents|length > 0 %}
<div class="table-responsive">
  <table class="table table-dark table-striped table-hover align-middle">
    <thead>
      <tr>
        
        {% if noicon is not defined and notype is not defined %}
        <th scope="col">          
          {% if notype is not defined %}
            {% trans %}title_type{% endtrans %}
          {% endif %}
        </th>
        {% endif %}
        <th scope="col">{% trans %}title_title{% endtrans %}</th>        
        <th scope="col">{% if noauthor is not defined %}{% trans %}title_author{% endtrans %} / {% endif %}{% trans %}title_date{% endtrans %}</th>
        {% if noaction is not defined %}
        <th scope="col">{% trans %}title_actions{% endtrans %}</th>
        {% endif %}
      </tr>
    </thead>
    <tbody>      
      {% for i in documents |slice(0, slicelimit) %} 
      {% set counter = counter + 1 %}
          <tr>
            {% if noicon is not defined and notype is not defined %}
              <td>
                {% if noicon is not defined %}
                  {% set groupLogo = 'img/nologo.png' %}
                  {% if i.mainGroup %}
                      {% if i.mainGroup.imageSize != 0 %}
                          {% set groupLogo = 'uploads/groups/' ~ i.mainGroup.imageName %}
                      {% endif %}
                  {% endif %}
                  <img src="{{ asset(groupLogo) }}" alt="{{  i.mainGroup.name }} " class="img-icon">
                {% endif %}
                {% if notype is not defined %}
                  {{ ('documentType_' ~ i.classShort)|trans }}<br /><small>N°: #{{i.id}}</small>
                {% endif %} 
              </td>
            {% endif %}

            <td>              
              <a href="{{ path('document_view', {'id': i.id}) }}" class="text-{{ (i.archive)? 'danger' : 'primary' }}" {% if i.archive %} data-bs-toggle="tooltip" data-placement="top"  title="{% trans %}tooltip_archived{% endtrans %}" {% endif %} >{{i.title | u.truncate(50, '...')}}</a>
              {% if notype is defined %}
                <br /><small>N°: #{{i.id}}</small>
              {% endif %}
              {% if i.status is defined %} 
                <br /><small>{% trans %}title_status{% endtrans %}:</small>
                <small>{{ i.status|trans }}</small>
              {% endif %}
              {% if i.removingDate is defined %} 
                <br /><small>{% trans %}title_can_be_removed_at{% endtrans %}:</small>
                <small class="text-{% if date(i.removingDate) < date() %}danger{% endif %}{% if date(i.removingDate) == date() %}warning{% endif %}{% if date(i.removingDate) > date() %}success{% endif %}">{{ i.removingDate|date('_datetime.format'|trans) }}</small>
              {% endif %}              
              {% if i.type is defined and i.type is not null %}
                <br /><small>{% trans %}title_type{% endtrans %}:</small>
                <small>{{ i.type|trans }}</small>
              {% endif %}
              {% if i.until is defined %} 
                <br /><small>{% trans %}title_until{% endtrans %}:</small>
                <small class="text-{% if date(i.until) < date() %}danger{% endif %}{% if date(i.until) == date() %}warning{% endif %}{% if date(i.until) > date() %}success{% endif %}">{{ i.until|date('_datetime.format'|trans) }}</small>
              {% endif %}
              {% if i.numberplate is defined and i.numberplate is not null %}
                <br /><small>{% trans %}title_numberplate{% endtrans %}:</small>
                <small>{{ i.numberplate }}</small>
              {% endif %}
              {% if i.directory is defined and nodirectoryinfo is not defined %}            
                <br /><small>{% trans %}title_directory{% endtrans %}:</small>
                <small><a href="{{ path('directory_view', {'id': i.directory.id}) }}" >{{ i.directory.firstname  | u.truncate(2, '.')}} {{ i.directory.lastname }} {% if i.directory.dead %}, {% trans %}title_dead{% endtrans %}{% endif %}</a></small>
              {% endif %}
              {% if i.user is defined %}            
                <br /><small>{% trans %}title_user{% endtrans %}:</small>
                <small><a href="{{ path('user_view', {'id': i.user.id}) }}" >{{ i.user.firstname  | u.truncate(2, '.')}} {{ i.user.lastname }}</a></small>
              {% endif %}              
              {% if i.amountMoney is defined %}            
                <br /><small>{% trans %}title_amount{% endtrans %}:</small>
                <small>{{ i.amountMoney ? i.amountMoney ~ ' ' ~'currency_symbol'|trans :'value_no_value'|trans }}</small>
              {% endif %}
              {% if i.amountTime is defined %}            
                <br /><small>{% trans %}title_hours{% endtrans %}:</small>
                <small>{{ i.amountTime ? i.amountTime ~ ' h' :'value_no_value'|trans}}</small>
              {% endif %}
              {% if i.amountCommunityWork is defined %}
                <br /><small>{% trans %}title_community_work{% endtrans %}:</small>
                <small>{{ i.amountCommunityWork ? i.amountCommunityWork ~ ' h' :'value_no_value'|trans}}</small>
              {% endif %}
              {% if i.accessorySentence is defined and i.accessorySentence is not null %}            
                <br /><small data-bs-toggle="tooltip" data-placement="top"  title="{{ i.accessorySentence|striptags }}">{% trans %}title_accessorySentence{% endtrans %} : {{ 'value_yes'|trans}}</small>
              {% endif %}
            </td>
            <td>
              {% if noauthor is not defined %}
                <a href="{{ path('user_view', {'id': i.creator.id }) }}" >{{i.creator.firstname | u.truncate(2, '.')}} {{i.creator.lastname}}, {{i.creator.mainGroup ? i.creator.mainGroup.shortname : 'value_no_group'|trans}}</a><br />
              {% endif %}            
              {{i.createdAt |date('_datetime.format'|trans)}}
            </td>
            {% if noaction is not defined %}
              <td>
                {% include '_cells/documentActions.html.twig' with {'document': i} %}
              </td>
            {% endif %}
          </tr>      
    {% endfor %} 
    </tbody>
  </table>
</div>

{% if slicelimit is not null and documents|length > slicelimit %}
  <div class="row my-2">
    <div class="col">
      {% if nodirectorylink is not defined %}
        <a class="btn btn-primary btn-sm" href="{{ path('document_list', {'type': documents[0].classShort, 'directory': documents[0].directory.id}) }}">{% trans %}button_view_more{% endtrans %}</a>
      {% else %}
        <a class="btn btn-primary btn-sm" href="{{ path('document_list', {'type': documents[0].classShort}) }}">{% trans %}button_view_more{% endtrans %}</a>
      {% endif %}
    </div>
  </div>
{% endif %}

{% else %}
  <p>{% trans %}no_data{% endtrans %}</p>
{% endif %}