{% extends 'generic/_base.html' %}
{% load helpers %}
{% load form_helpers %}
{% load i18n %}

{% comment %}
Blocks:
  - title:    Page title
  - tabs:     Page tabs
  - content:  Primary page content

Context:
  - form:              The bulk edit form class
  - obj_type_plural:   The plural form of the object type
  - selected_objects:  A queryset matching the objects selected for bulk renaming
  - return_url:        The URL to which the user is redirected after submitting the form
{% endcomment %}

{% block title %}
  {% trans "Renaming" %} {{ selected_objects|length }} {{ obj_type_plural|bettertitle }}
{% endblock %}

{% block tabs %}
  <ul class="nav nav-tabs">
    <li class="nav-item" role="presentation">
      <button class="nav-link active" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
        {% trans "Bulk Rename" %}
      </button>
    </li>
  </ul>
{% endblock tabs %}

{% block content %}
<div class="row mb-3">
    <div class="col col-md-7">
        <table class="table">
            <thead>
                <tr>
                    <th>{% trans "Current Name" %}</th>
                    <th>{% trans "New Name" %}</th>
                </tr>
            </thead>
            <tbody>
                {% for obj in selected_objects %}
                    {% with obj_name=obj|getattr:field_name %}
                        <tr{% if obj.new_name and obj_name != obj.new_name %} class="success"{% endif %}>
                            <td>{{ obj_name }}</td>
                            <td>{{ obj.new_name }}</td>
                        </tr>
                    {% endwith %}
                {% endfor %}
            </tbody>
        </table>
    </div>
    <div class="col col-md-5">
        <form action="" method="post" class="form form-horizontal">
            {% csrf_token %}
            <div class="card">
                <h2 class="card-header">{% trans "Rename" %}</h2>
                <div class="card-body">
                    {% render_form form %}
                </div>
            </div>
            <div class="col col-md-12 my-3 text-end">
                <a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
                <button type="submit" name="_preview" class="btn btn-primary">{% trans "Preview" %}</button>
                {% if '_preview' in request.POST and not form.errors %}
                    <button type="submit" name="_apply" class="btn btn-primary">{% trans "Apply" %}</button>
                {% endif %}
            </div>
        </form>
    </div>
</div>
{% endblock content %}
