{#
  Partial : tableau de fichiers.
  Paramètres de contexte :
    entries   – liste de dicts (champs _entry ou _trash_list)
    mode      – "browse" | "trash"
    has_hits  – booléen (browse uniquement)
    humansize – filtre taille
    subpath   – chemin courant (browse uniquement, pour la ligne "..")
    breadcrumb – liste de crumbs (browse uniquement)
#}
<table class="file-table" id="file-table">
  <thead>
    <tr>
      {% if mode == 'trash' %}<th class="col-check"><input type="checkbox" id="select-all-cb" title="Tout sélectionner"></th>{% endif %}
      <th class="col-icon"></th>
      <th>Nom</th>
      {% if mode == 'trash' %}
        <th class="col-origin">Emplacement d'origine</th>
        <th class="col-date">Supprimé le</th>
        <th class="col-size">Taille</th>
      {% else %}
        <th class="col-size">Taille</th>
        <th class="col-date">Modifié le</th>
        {% if has_hits %}<th class="col-hits">Vues</th>{% endif %}
      {% endif %}
      <th class="col-actions"></th>
    </tr>
  </thead>
  <tbody>

    {% if mode == 'browse' and subpath %}
    <tr>
      <td class="col-icon">⬆</td>
      <td>
        {% if breadcrumb | length > 1 %}
          <a href="{{ url_for('browse', subpath=breadcrumb[-2].path) }}">.. (dossier parent)</a>
        {% else %}
          <a href="{{ url_for('browse') }}">.. (racine)</a>
        {% endif %}
      </td>
      <td></td><td></td>
      {% if has_hits %}<td></td>{% endif %}
      <td></td>
    </tr>
    {% endif %}

    {% for e in entries %}
    <tr data-name="{{ e.name|lower }}" data-size="{{ e.size or 0 }}" data-date="{{ e.deleted_at.isoformat() if mode == 'trash' and e.deleted_at else '' }}">
      {% if mode == 'trash' %}<td class="col-check"><input type="checkbox" class="row-cb" data-path="{{ e.path }}" data-name="{{ e.name }}"></td>{% endif %}
      <td class="col-icon">
        {%- if e.is_dir   -%}📁
        {%- elif e.is_image -%}🖼
        {%- elif e.is_pdf -%}📕
        {%- elif e.is_text -%}📄
        {%- else -%}📎
        {%- endif -%}
      </td>
      <td>
        <div class="col-name">
          {% if e.is_image %}
            <img class="thumb-sm"
                 src="{{ url_for('trash_raw' if mode == 'trash' else 'raw_file', subpath=e.path) }}"
                 alt="{{ e.name }}" loading="lazy">
          {% endif %}
          {% if mode == 'trash' %}
            <a href="{{ url_for('trash_preview', subpath=e.path) }}" class="trash-filename">{{ e.name }}</a>
          {% else %}
            <a href="{{ url_for('browse', subpath=e.path) }}">
              {{ e.name }}{% if e.is_dir %}/{% endif %}
            </a>
          {% endif %}
          {% if e.ext and not e.is_dir %}
            <span class="type-badge">{{ e.ext }}</span>
          {% endif %}
        </div>
      </td>

      {% if mode == 'trash' %}
        <td class="col-origin" title="{{ e.original_path }}">{{ e.original_path }}</td>
        <td class="col-date">{{ e.deleted_at.strftime('%d/%m/%Y %H:%M') }}</td>
        <td class="col-size">{{ humansize(e.size) }}</td>
      {% else %}
        <td class="col-size">{{ humansize(e.size) if e.size is not none else '—' }}</td>
        <td class="col-date">{{ e.mtime.strftime('%d/%m/%Y %H:%M') }}</td>
        {% if has_hits %}
        <td class="col-hits">
          {% if not e.is_dir %}
            {% if e.hits %}
              <span class="hits-badge hits-active" title="{{ e.hits }} requête(s) dans les stats">{{ e.hits }}</span>
            {% else %}
              <span class="hits-badge hits-zero" title="Aucune vue">0</span>
            {% endif %}
          {% endif %}
        </td>
        {% endif %}
      {% endif %}

      <td class="col-actions">
        {% if mode == 'browse' and not e.is_dir %}
        <div class="row-actions">
          <button type="button" class="btn-rename"
                  data-path="{{ e.path }}" data-name="{{ e.name }}"
                  title="Renommer">✏️</button>
          <form method="post" action="{{ url_for('delete_file') }}" style="display:contents">
            <input type="hidden" name="path" value="{{ e.path }}">
            <button type="submit" class="btn-del" title="Mettre à la corbeille">🗑</button>
          </form>
        </div>
        {% elif mode == 'trash' %}
        <div class="row-actions">
          <button type="button" class="btn-restore"
                  data-path="{{ e.path }}" title="Restaurer">♻️</button>
          <form method="post" action="{{ url_for('trash_delete') }}" style="display:contents">
            <input type="hidden" name="path" value="{{ e.path }}">
            <button type="submit" class="btn-del btn-del--perm"
                    title="Supprimer définitivement"
                    onclick="return confirm('Supprimer définitivement {{ e.name|replace("'","\\'")|replace('"','&quot;') }} ?')">🗑</button>
          </form>
        </div>
        {% endif %}
      </td>
    </tr>
    {% endfor %}

  </tbody>
</table>
