{% set can_edit = g.user.admin or (overlay and overlay.type == 'workshop' and overlay.user_id == g.user.id) %}
<table class="table">
  <thead>
    <tr>
      <th></th>
      <th>Steam ID</th>
      <th>Title</th>
      <th>Filename</th>
      <th>Size</th>
      <th>Updated</th>
      <th>Status</th>
      {% if can_edit %}<th></th>{% endif %}
    </tr>
  </thead>
  <tbody>
    {% for item in workshop_items %}
    <tr>
      <td>
        {% if item.preview_url %}
        <img src="{{ item.preview_url }}" alt="" width="48" height="48" loading="lazy">
        {% endif %}
      </td>
      <td><a href="https://steamcommunity.com/sharedfiles/filedetails/?id={{ item.steam_id }}" target="_blank" rel="noopener">{{ item.steam_id }}</a></td>
      <td>{{ item.title }}</td>
      <td class="muted">{{ item.filename }}</td>
      <td class="muted">{{ item.file_size }}</td>
      <td class="muted">{{ item.time_updated }}</td>
      <td>
        {% if item.last_error %}
        <span class="warning">{{ item.last_error }}</span>
        {% elif item.last_downloaded_at %}
        cached
        {% else %}
        <span class="muted">pending</span>
        {% endif %}
      </td>
      {% if can_edit %}
      <td>
        <form method="post" action="/overlays/{{ overlay.id }}/items/{{ item.id }}/delete" class="inline-form">
          <input type="hidden" name="csrf_token" value="{{ session.get('csrf_token', '') }}">
          <button type="submit" class="button-secondary">Remove</button>
        </form>
      </td>
      {% endif %}
    </tr>
    {% else %}
    <tr><td colspan="{% if can_edit %}8{% else %}7{% endif %}" class="muted">No workshop items yet.</td></tr>
    {% endfor %}
  </tbody>
</table>
