{% load widget_tweaks %}
<div class="card mb-2">
  <div class="card-header">
    Collection Details
  </div>
  <div class="card-body">
    {% if create or edit or duplicate %}
    <div class="form-group" id="parent-group">
      <label for="selectpicker">Set Parent</label>
      <select name="parent" id="parent_id" class="selectpicker" data-live-search="true" data-sourceurl="{% url 'api_secure' model='asset' %}?fields=asset_id,description">
        {% if object.parent %}
        <option value="{{object.parent.pk}}" selected>{{object.parent.description}}</option>
        {% endif %}
      </select>
    </div>
    {% else %}
    <dl>
      <dt>Parent</dt>
      <dd>
        {% if object.parent %}
        <a href="{% url 'asset_detail' object.parent.asset_id %}">
        {{ object.parent.asset_id }} - {{ object.parent.description }}
        </a>
        {% else %}
        <span>-</span>
        {% endif %}
      </dd>

      <dt>Children</dt>
      {% if object.asset_parent.all %}
      <div style="max-height: 200px; overflow-y: auto; -webkit-overflow-scrolling: touch; ">
      {% for child in object.asset_parent.all %}
      <dd>
        <a href="{% url 'asset_detail' child.asset_id %}">{{ child }}</a>
      </dd>
      {% endfor %}
      </div>
      {% else %}
      <dd><span>-</span></dd>
      {% endif %}
    </dl>
    {% endif%}
  </div>
</div>
