{% extends 'base.html' %}

{% block title %} - All sets{% endblock %}

{% block main %}
{% if collection | length %}
<div class="container-fluid">
  <div class="row row-cols-lg-auto g-1 justify-content-center align-items-center pb-2">
    <div class="col-12 flex-grow-1">
      <label class="visually-hidden" for="grid-search">Search</label>
      <div class="input-group">
        <span class="input-group-text"><i class="ri-search-line"></i><span class="ms-1 d-none d-xl-inline"> Search</span></span>
        <input id="grid-search" class="form-control form-control-sm" type="text" placeholder="Set name, set number, set theme or number of parts..." value="">
      </div>
    </div>
    <div class="col-12 flex-grow-1">
      <label class="visually-hidden" for="grid-filter">Filter</label>
      <div class="input-group">
        <span class="input-group-text"><i class="ri-dropdown-list"></i><span class="ms-1 d-none d-xl-inline"> Filter</span></span>
        <select id="grid-filter" class="form-select form-select-sm" autocomplete="off">
          <option value="" selected>All sets</option>
          <option value="-has-missing">Set is complete</option>
          <option value="has-missing">Set has missing pieces</option>
          <option value="has-missing-instructions">Set has missing instructions</option>
          {% for checkbox in brickset_checkboxes %}
            <option value="{{ checkbox.as_dataset() }}">{{ checkbox.fields.name }}</option>
            <option value="-{{ checkbox.as_dataset() }}">NOT: {{ checkbox.fields.name }}</option>
          {% endfor %}
        </select>
        <select id="grid-theme" class="form-select form-select-sm" autocomplete="off">
          <option value="" selected>All themes</option>
          {% for theme in collection.themes %}
          <option value="{{ theme | lower }}">{{ theme }}</option>
          {% endfor %}
        </select>
      </div>
    </div>
    <div class="col-12">
      <div id="grid-sort" class="input-group">
        <span class="input-group-text"><i class="ri-sort-asc"></i><span class="ms-1 d-none d-xxl-inline"> Sort</span></span>
        <button id="sort-number" type="button" class="btn btn-sm btn-outline-primary"
          data-sort-target="div#grid>div" data-sort-attribute="number" data-sort-natural="true"><i class="ri-hashtag"></i><span class="d-none d-xxl-inline"> Number</span></button>
        <button id="sort-name" type="button" class="btn btn-sm btn-outline-primary"
          data-sort-target="div#grid>div" data-sort-attribute="name"><i class="ri-pencil-line"></i><span class="d-none d-xxl-inline"> Name</span></button>
        <button id="sort-theme" type="button" class="btn btn-sm btn-outline-primary"
          data-sort-target="div#grid>div" data-sort-attribute="theme"><i class="ri-price-tag-3-line"></i><span class="d-none d-xxl-inline"> Theme</span></button>
        <button id="sort-year" type="button" class="btn btn-sm btn-outline-primary"
          data-sort-target="div#grid>div" data-sort-attribute="year"><i class="ri-calendar-line"></i><span class="d-none d-xxl-inline"> Year</span></button>
        <button id="sort-minifigure" type="button" class="btn btn-sm btn-outline-primary"
          data-sort-target="div#grid>div" data-sort-attribute="minifigures" data-sort-desc="true"><i class="ri-group-line"></i><span class="d-none d-xxl-inline"> Figures</span></button>
        <button id="sort-parts" type="button" class="btn btn-sm btn-outline-primary"
          data-sort-target="div#grid>div" data-sort-attribute="parts" data-sort-desc="true"><i class="ri-shapes-line"></i><span class="d-none d-xxl-inline"> Parts</span></button>
        <button id="sort-missing" type="button" class="btn btn-sm btn-outline-primary"
          data-sort-target="div#grid>div" data-sort-attribute="missing" data-sort-desc="true"><i class="ri-error-warning-line"></i><span class="d-none d-xxl-inline"> Missing</span></button>
        <button id="sort-clear" type="button" class="btn btn-sm btn-outline-dark"
          data-sort-target="div#grid>div" data-sort-clear="true"><i class="ri-filter-off-line"></i><span class="d-none d-xxl-inline"> Clear</span></button>
      </div>
    </div>
  </div>

  <div class="row" data-grid="true" id="grid">
  {% for item in collection %}
    <div class="col-md-6 col-xl-3 d-flex align-items-stretch">
      {% with index=loop.index0 %}
        {% include 'set/card.html' %}
      {% endwith %}
    </div>
  {% endfor %}
  </div>
</div>
{% else %}
  {% include 'set/empty.html' %}
{% endif %}
{% endblock %}
