{% import 'macro/accordion.html' as accordion %}
{% import 'macro/form.html' as form %}

{% if g.login.is_authenticated() %}
  {{ accordion.header('Management', 'accordion-management-' ~ item.fields.id, 'individual-minifigure-details-' ~ item.fields.id, icon='settings-4-line', class='p-0') }}
    {{ accordion.header('Owners', 'accordion-owners-' ~ item.fields.id, 'accordion-management-' ~ item.fields.id, icon='group-line', class='p-0') }}
      <ul class="list-group list-group-flush">
      {% if brickset_owners | length %}
        {% for owner in brickset_owners %}
          <li class="d-flex list-group-item list-group-item-action text-nowrap">{{ form.checkbox(owner.fields.name, item.fields.id, owner.as_dataset(), owner.url_for_individual_minifigure_state(item.fields.id), item.fields[owner.as_column()], delete=management_read_only) }}</li>
        {% endfor %}
      {% else %}
        <li class="list-group-item list-group-item-action text-center"><i class="ri-error-warning-line"></i> No owner found.</li>
        {% endif %}
      </ul>
      <div class="list-group list-group-flush border-top">
        <a class="list-group-item list-group-item-action" href="{{ url_for('admin.admin', open_owner=true) }}"><i class="ri-settings-4-line"></i> Manage the minifigure owners</a>
      </div>
    {{ accordion.footer() }}
    {{ accordion.header('Purchase', 'accordion-purchase-' ~ item.fields.id, 'accordion-management-' ~ item.fields.id, icon='wallet-3-line') }}
      <div class="alert alert-info" role="alert">The expected date format here is <code>yyyy/mm/dd</code> (year/month/day), but you can configured how it is displayed in the minifigure card with the <code>PURCHASE_DATE_FORMAT</code> variable.</div>
      <div class="row row-cols-lg-auto g-1 justify-content-start align-items-center pb-2">
        <div class="col-12">
          {% if management_read_only %}
            <div class="input-group">
              <span class="input-group-text px-1"><i class="ri-calendar-line me-1"></i><span class="ms-1 d-none d-md-inline"> Date</span></span>
              <input class="form-control form-control-sm flex-shrink-1 px-1" type="text" value="{{ item.fields.purchase_date or '' }}" disabled autocomplete="off">
              <span class="input-group-text ri-prohibited-line px-1"></span>
            </div>
          {% else %}
            {{ form.input('Date', item.fields.id, 'purchase_date', url_for('individual_minifigure.update_purchase_date', id=item.fields.id), item.fields.purchase_date or '', date=true, icon='calendar-line') }}
          {% endif %}
        </div>
        <div class="col-12 flex-grow-1">
          {% if management_read_only %}
            <div class="input-group">
              <span class="input-group-text px-1"><i class="ri-wallet-3-line me-1"></i><span class="ms-1 d-none d-md-inline"> Price</span></span>
              <input class="form-control form-control-sm flex-shrink-1 px-1" type="text" value="{{ item.fields.purchase_price or '' }}" disabled autocomplete="off">
              <span class="input-group-text d-none d-md-inline px-1">{{ config['PURCHASE_CURRENCY'] }}</span>
              <span class="input-group-text ri-prohibited-line px-1"></span>
            </div>
          {% else %}
            {{ form.input('Price', item.fields.id, 'purchase_price', url_for('individual_minifigure.update_purchase_price', id=item.fields.id), item.fields.purchase_price or '', suffix=config['PURCHASE_CURRENCY'], icon='wallet-3-line') }}
          {% endif %}
        </div>
        <div class="col-12 flex-grow-1">
          {% if brickset_purchase_locations | length %}
            {{ form.select('Location', item.fields.id, brickset_purchase_locations.as_prefix(), brickset_purchase_locations.url_for_individual_minifigure_value(item.fields.id), item.fields.purchase_location, brickset_purchase_locations, icon='building-line', delete=management_read_only) }}
          {% else %}
            <i class="ri-error-warning-line"></i> No purchase location found.
          {% endif %}
        </div>
      </div>
      <hr>
      <a href="{{ url_for('admin.admin', open_purchase_location=true) }}" class="btn btn-primary" role="button"><i class="ri-settings-4-line"></i> Manage the minifigure purchase locations</a>
    {{ accordion.footer() }}
    {{ accordion.header('Notes', 'accordion-notes-' ~ item.fields.id, 'accordion-management-' ~ item.fields.id, icon='sticky-note-line') }}
      {{ form.textarea('Notes', item.fields.id, 'description', url_for('individual_minifigure.update_description', id=item.fields.id), item.fields.description, rows=4, delete=management_read_only) }}
    {{ accordion.footer() }}
    {{ accordion.header('Storage', 'accordion-storage-' ~ item.fields.id, 'accordion-management-' ~ item.fields.id, icon='archive-2-line') }}
      {% if brickset_storages | length %}
      {{ form.select('Storage', item.fields.id, brickset_storages.as_prefix(), brickset_storages.url_for_individual_minifigure_value(item.fields.id), item.fields.storage, brickset_storages, icon='building-line', delete=management_read_only) }}
      {% else %}
        <p class="text-center"><i class="ri-error-warning-line"></i> No storage found.</p>
      {% endif %}
      <hr>
      <a href="{{ url_for('admin.admin', open_storage=true) }}" class="btn btn-primary" role="button"><i class="ri-settings-4-line"></i> Manage the minifigure storages</a>
    {{ accordion.footer() }}
    {{ accordion.header('Tags', 'accordion-tags-' ~ item.fields.id, 'accordion-management-' ~ item.fields.id, icon='price-tag-2-line', class='p-0') }}
      <ul class="list-group list-group-flush">
      {% if brickset_tags | length %}
        {% for tag in brickset_tags %}
          <li class="d-flex list-group-item list-group-item-action text-nowrap">{{ form.checkbox(tag.fields.name, item.fields.id, tag.as_dataset(), tag.url_for_individual_minifigure_state(item.fields.id), item.fields[tag.as_column()], delete=management_read_only) }}</li>
        {% endfor %}
      {% else %}
        <li class="list-group-item list-group-item-action text-center"><i class="ri-error-warning-line"></i> No tag found.</li>
        {% endif %}
      </ul>
      <div class="list-group list-group-flush border-top">
        <a class="list-group-item list-group-item-action" href="{{ url_for('admin.admin', open_tag=true) }}"><i class="ri-settings-4-line"></i> Manage the minifigure tags</a>
      </div>
    {{ accordion.footer() }}
  {{ accordion.footer() }}
{% endif %}
