{% load dict_key_extras %}
{% load timestamptags %}
{% load tz %}

<thead>
    {% if data.menu and not data.title %}
        <th> <input type="checkbox" id="select_all_{{group}}" onchange="selectAll(this, '{{group}}')"> </th>
    {% endif %}
    <th>Name</th>
    <th>Role</th>
    <th>Last Modification date</th>
    {% if data.username_list %}
        <th>User</th>
    {% endif %}
    {% if not data.title%}
        <th>Workspace</th>
    {% endif %}
    <th>Actions</th>
    <th>Status</th>
</thead>
<tbody>
    {% for data_loaded in objects %}
        <tr objectid="{{data_loaded.data.id}}">
            {% if data.menu and not data.title %}
            <td id="actionCheckbox_{{forloop.counter}}">
                <input type="checkbox" id={{data_loaded.data.id}} name={{group}}>
            </td>
            {% endif %}
            <td>
                {{ data_loaded.data.title }}
                {% if data.administration and data_loaded.forms_count > 0  %}
                    ,<text class="text-danger"> Draft{{ data_loaded.forms_count|pluralize }} </text>
                {% elif data_loaded.form_id %}
                    ,<text class="text-danger"> Draft </text>
                {% endif %}
            </td>
            <td>
                {{ data_loaded.data_role }}
            </td>
            <td>
                {{ data_loaded.data.last_modification_date|localtime }}
            </td>
            {% if data.username_list %}
            <td>
                {% with key=data_loaded.data.user_id %}
                  {{ data.username_list|get:key }}
                {% endwith %}
            </td>
            {% endif %}
            {% if not data.title%}
            <td>
                {% if data_loaded.data.workspace %}
                    {{ data_loaded.data.workspace.title }}
                {% else %}
                    None
                {% endif %}
            </td>
            {% endif %}
            <td>
                <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownActions" {% if BOOTSTRAP_VERSION|first == "4" %}data-toggle{% elif BOOTSTRAP_VERSION|first == "5"  %}data-bs-toggle{% endif %}="dropdown" aria-haspopup="true" aria-expanded="false">
                    <i class="fas fa-sliders"></i> Actions
                </button>
                <div class="dropdown-menu" aria-labelledby="dropdownActions">
                    <a class="dropdown-item view-record-btn {% if not data_loaded.can_read %}" href="#">
                        <i class="fas fa-file-alt"></i> View
                    </a>

                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item edit-record-btn {% if not data_loaded.can_write %} disabled {% endif %}" href="#">
                            <i class="fas fa-edit"></i> Edit
                    </a>
                    {% if data_loaded.data.template.format == "XSD" %}
                        {% if data_loaded.form_id %}
                        <a class="dropdown-item {% if not data_loaded.can_write %} disabled {% endif %}" href="{% url 'core_curate_app_xml_text_editor_view'%}?id={{ data_loaded.form_id }}">
                            <i class="fas fa-code"></i> Open Draft
                        </a>
                        {% else %}
                        <a class="dropdown-item open-xml-record-btn {% if not data_loaded.can_write %} disabled {% endif %}" href="#">
                            <i class="fas fa-code"></i> Open
                        </a>
                        {% endif %}
                    {% elif data_loaded.data.template.format == "JSON" %}
                        {% if data_loaded.form_id %}
                        <a class="dropdown-item {% if not data_loaded.can_write %} disabled {% endif %}" href="{% url 'core_curate_app_json_text_editor_view'%}?id={{ data_loaded.form_id }}">
                            <i class="fas fa-code"></i> Open Draft
                        </a>
                        {% else %}
                        <a class="dropdown-item open-json-record-btn {% if not data_loaded.can_write %} disabled {% endif %}" href="#">
                            <i class="fas fa-code"></i> Open
                        </a>
                        {% endif %}
                    {% endif %}
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item assign-workspace-record-btn {% if not data_loaded.can_change_workspace %} disabled {% endif %}" href="#">
                        <i class="fas fa-folder"></i> Change workspace
                    </a>
                    <a class="dropdown-item change-owner-btn {% if not data_loaded.is_owner %} disabled {% endif %}" href="#">
                        <i class="fas fa-user-circle"></i> Change Owner
                    </a>
                    <a class="dropdown-item publish-record-btn {% if not data_loaded.can_set_public %} disabled {% endif %}" href="#">
                        <i class="fas fa-share-alt"></i> Publish
                    </a>
                    {% if data.administration and  data_loaded.forms_count > 0 %}
                        <div class="dropdown-divider"></div>
                        <a objectid="{{data_loaded.data.id}}" class="dropdown-item delete-data-draft-list-btn" href="#">
                            <i class="fas fa-trash"></i> Delete Draft{{ data_loaded.forms_count|pluralize }}
                        </a>
                    {% elif data_loaded.form_id %}
                        <div class="dropdown-divider"></div>
                        <a objectid="{{data_loaded.form_id}}" class="dropdown-item  delete-draft-btn" href="#">
                            <i class="fas fa-trash"></i> Delete Draft
                        </a>
                    {% endif %}
                </div>
            </td>
            <td class="status-cell-admin">
                <span class="{% if BOOTSTRAP_VERSION|first == "4" %}float-right{% elif BOOTSTRAP_VERSION|first == "5"  %}float-end{% endif %} dropdown">
                    {% if data_loaded.data_status == data_loaded.data_status_values.ACTIVE  %}
                        <span data-status="active" class="dropbtn status-active"></span>
                    {% endif %}
                    {% if data_loaded.data_status == data_loaded.data_status_values.INACTIVE  %}
                        <span data-status="inactive" class="dropbtn status-inactive"></span>
                    {% endif %}
                    {% if data_loaded.data_status == data_loaded.data_status_values.DELETED  %}
                        <span data-status="deleted" class="dropbtn status-deleted"></span>
                    {% endif %}
                  <div class="dropdown-content">
                      <a data-status="active" class="switch font-active">Active</a>
                      <a data-status="inactive" class="switch font-inactive">Inactive</a>
                        {% if data_loaded.data.workspace.is_public %}
                            <a data-status="deleted" class="switch font-deleted">Deleted</a>
                        {% endif %}
                  </div>
                </span>
                {% if data_loaded.data_status == data_loaded.data_status_values.ACTIVE  %}
                    <span class="{% if BOOTSTRAP_VERSION|first == "4" %}float-right{% elif BOOTSTRAP_VERSION|first == "5"  %}float-end{% endif %} label-status font-active">Active</span>
                {% endif %}
                {% if data_loaded.data_status == data_loaded.data_status_values.INACTIVE  %}
                    <span class="{% if BOOTSTRAP_VERSION|first == "4" %}float-right{% elif BOOTSTRAP_VERSION|first == "5"  %}float-end{% endif %} label-status font-inactive">Inactive</span>
                {% endif %}
                {% if data_loaded.data_status == data_loaded.data_status_values.DELETED  %}
                    <span class="{% if BOOTSTRAP_VERSION|first == "4" %}float-right{% elif BOOTSTRAP_VERSION|first == "5"  %}float-end{% endif %} label-status font-deleted">Deleted</span>
                {% endif %}
            </td>
        </tr>
    {% endfor %}
</tbody>