{% extends 'base.html' %}

{% block title %} - {% if delete %}Delete a set{% else %}Set{% endif %} {{ item.fields.name}} ({{ item.fields.set }}){% endblock %}

{% block main %}
<div class="container">
  <div class="row">
    <div class="col-12">
      {% if all_instances and all_instances | length > 1 %}
        <!-- Multiple instances view with drawer-style header -->
        <div class="alert alert-info mb-3">
          <!-- Clickable drawer header -->
          <div class="d-flex justify-content-between align-items-center" style="cursor: pointer;" data-bs-toggle="collapse"
               data-bs-target="#all-instances" aria-expanded="false" aria-controls="all-instances">
            <div>
              <h4 class="mb-1">
                <i class="ri-stack-line me-2"></i>Multiple Copies Available
                <span class="badge bg-primary ms-2">{{ all_instances | length }}</span>
              </h4>
              <p class="mb-0">This set has {{ all_instances | length }} copies in your collection. Click to view all copies individually.</p>
            </div>
            <i class="ri-arrow-down-s-line fs-4" id="copies-toggle-icon"></i>
          </div>

          <!-- Collapsible instances section -->
          <div class="collapse mt-3" id="all-instances">
            <div class="border-top pt-3">
              <div class="row">
                {% set current_item_id = item.fields.id %}
                {% for instance in all_instances %}
                <div class="col-md-6 col-xl-4 d-flex align-items-stretch mb-3">
                  {% with item=instance, index=loop.index0, tiny=false, current_viewing=(instance.fields.id == current_item_id) %}
                    <div class="position-relative w-100">
                      {% include 'set/card.html' %}
                    </div>
                  {% endwith %}
                </div>
                {% endfor %}
              </div>
            </div>
          </div>
        </div>


        {% with solo=true, delete=delete %}
          {% include 'set/card.html' %}
        {% endwith %}
      {% else %}
        <!-- Single instance view -->
        {% with solo=true, delete=delete %}
          {% include 'set/card.html' %}
        {% endwith %}
      {% endif %}
    </div>
  </div>
</div>
{% endblock %}
