{% extends 'projectroles/project_base.html' %}

{% load rules %}

{% block title %}
  {% if batch_action == 'delete' %}
    Delete
  {% elif batch_action == 'move' %}
    Move
  {% endif %}
  Selected
{% endblock title %}

{% block projectroles_extend %}

<div class="row sodar-subtitle-container">
  <h3>
    {% if batch_action == 'delete' %}
      Delete
    {% elif batch_action == 'move' %}
      Move
    {% endif %}
    Selected
  </h3>
</div>

<div class="container-fluid sodar-page-container">
  {% if failed|length > 0 %}
    <div class="alert alert-danger" role="alert">
      <p><strong>Note!</strong> The following
          item{% if failed|length != 1 %}s{% endif %} can <strong>not</strong> be
        {% if batch_action == 'move' %}
          moved (insufficient permissions)
        {% elif batch_action == 'delete' %}
          deleted (insufficient permissions or non-empty folders)
        {% endif %}
      </p>
      <ul class="list-unstyled mb-0">
        {% for item in failed %}
          <li>{{ item.name }}</li>
        {% endfor %}
      </ul>
    </div>
  {% endif %}

  <form method="post"
    {% if folder %}
      action="{% url 'filesfolders:batch_edit' folder=folder %}">
    {% else %}
      action="{% url 'filesfolders:batch_edit' project=project.sodar_uuid %}">
    {% endif %}

    {% csrf_token %}

    {% if items|length > 0 %}
      <div class="alert alert-warning" role="alert">
        <p><strong>Warning!</strong>
          {% if batch_action == 'move' %}
            The following item{% if items|length != 1 %}s{% endif %} will be moved:
          {% elif batch_action == 'delete' %}
            Are you sure you want to <strong>permanently delete</strong> the
              following item{% if items|length != 1 %}s{% endif %}?
          {% endif %}
        </p>
        <ul class="list-unstyled mb-0">
          {% for item in items %}
          <li>{{ item.name }}</li>
         {% endfor %}
        </ul>
      </div>

      <input type="hidden" id="sodar-ff-user-confirmed" name="user-confirmed" value="1" />
      <input type="hidden" id="sodar-ff-batch-action" name="batch-action" value="{{ batch_action }}" />

      {% for name in item_names %}
        <input type="hidden" name="{{ name }}" value="1" />
      {% endfor %}

      {% if batch_action == 'move' and folder_check %}
        <div class="form-group">
          <label for="sodar-ff-older-select">Select folder:</label>
          <select class="form-control"
                  id="sodar-ff-folder-select" name="target-folder">
            {% if folder %}
              <option value="0">root</option>
            {% endif %}
            {% for choice in folder_choices %}
              <option value="{{ choice.sodar_uuid }}">{{ choice.get_path }}</option>
            {% endfor %}
          </select>
        </div>
      {% endif %}
    {% endif %}

    {% if items|length == 0 or not folder_check %}
      <div class="alert alert-danger" role="alert">
        <strong>Error:</strong>
        {% if items|length == 0 %}
          No items to edit!
        {% elif not folder_check %}
          No folders available for moving selected
            item{% if items|length != 1 %}s{% endif %}!
        {% endif %}
      </div>
    {% endif %}

    <div class="row">
      <div class="btn-group ml-auto">
        {% if folder %}
          <a role="button" class="btn btn-secondary"
             href="{% url 'filesfolders:list' folder=folder %}">
            <i class="iconify" data-icon="mdi:arrow-left-circle"></i> Cancel
          </a>
        {% else %}
          <a role="button" class="btn btn-secondary"
             href="{% url 'filesfolders:list' project=project.sodar_uuid %}">
            <i class="iconify" data-icon="mdi:arrow-left-circle"></i> Cancel
          </a>
        {% endif %}
        {% if items|length > 0 %}
          {% if batch_action == 'move' and folder_check %}
            <button type="submit" class="btn btn-primary">
              <i class="iconify" data-icon="mdi:arrow-right-thick"></i> Move
            </button>
          {% elif batch_action == 'delete' %}
            <button type="submit" class="btn btn-danger">
              <i class="iconify" data-icon="mdi:close-thick"></i> Delete
            </button>
          {% endif %}
        {% endif %}
      </div>
    </div>
  </form>
</div>

{% endblock projectroles_extend %}
