{%- extends "admin/_base.html" %}

{% block content %}

  <h2><a href="{{ url_for('.tags_ns', ns=ns) }}">{{ ns }}</a></h2>

  <form action="" method="POST" enctype="multipart/form-data">
    {{ csrf.field() }}

    <table class="table table-striped">
      <thead>
        <tr>
          <th>{{ _('Tag') }}</th>
          <th>{{ _('# Tagged objects') }}</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        {%- for tag in tags %}
          <tr>
            <td><a href="{{ url_for('.tags_tag_edit', ns=tag.tag_ns, object_id=tag.tag_id) }}">{{ tag.tag_label }}</a></td>
            <td>{{ tag.obj_count or 0 }}</td>
            <td><input type="checkbox" name="selected" value="{{ tag.tag_id }}" {%- if tag.tag_id in selected_tags %} checked{%- endif %}/></td>
          </tr>
        {%- endfor %}
      </tbody>
    </table>

    <div class="form-group form-actions">
    </div>

    <fieldset>
      <legend>{{ _('Merge tags') }}</legend>
      <div class="form-group">
        <label class="control-label">{{ _('Target tag') }}</label>
        <select name="merge_to" class="form-control js-widget"
                data-init-with="select2" data-init-params="{}">
          <option></option>
          {%- for tag in tags %}
            <option value="{{ tag.tag_id }}" {%- if tag.tag_id == merge_to %} selected{%- endif %}>{{ tag.tag_label }}</option>
          {%- endfor %}
        </select>
      </div>
      <div class="form-group form-actions">
        <button class="btn btn-primary" name="__action" value="merge">{{ _('Merge tags') }}</button>
      </div>
    </fieldset>

    <fieldset>
      <legend>{{ _('Delete selected tags') }}</legend>
      <div class="form-group form-actions {%- if 'confirm_delete' in errors %} error{%- endif %}">
      <label class="control-label">
        <input type="checkbox" name="confirm_delete" />
        {{ _('Check to confirm definitive deletion of selected tags') }}
      </label>
      {%- if 'confirm_delete' in errors %}
        <span class="help-inline text-danger">{{ errors['confirm_delete'] }}</span>
      {%- endif %}
      <br />
      <button class="btn btn-danger" name="__action" value="delete"><i class="fa fa-exclamation-triangle"></i> {{ _('Delete selected tags') }}</button>
      </div>
    </fieldset>
  </form>
{% endblock %}
