{% load translations %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load permissions %}
{% load icons %}

{% for item in unitdata %}
<tbody class="zen-unit">


<tr id="row-status-{{ item.unit.checksum }}">
<td>
{{ item.unit.position }}
{% include "snippets/unit-readonly-badge.html" with unit=item.unit %}
</td>
<td colspan="2">
<a href="{% url 'translate' project=project.slug component=object.component.slug lang=object.language.code %}?{{ search_url }}&amp;offset={{ item.offset }}" class="btn btn-link btn-xs pull-right flip" title="{% trans "Open in full editor" %}">{% icon "pencil.svg" %}</a>
{% if item.unit.context %}
<div class="pull-right flip zen-context">
<label>{{ unit.translation.component.context_label }}</label>
{{ item.unit.context }}
</div>
{% endif %}
{% get_location_links user.profile item.unit %}
</td>
</tr>


{% if item.unit.note %}
<tr id="row-note-{{ item.unit.checksum }}">
<td></td>
<td colspan="2" class="translatetext">
    <label>{% trans "Source string comment" %}</label>
    {% format_translation item.unit.note item.unit.translation.component.source_language %}
</td>
</tr>
{% endif %}


{% if item.unit.source_unit.explanation %}
<tr id="row-explanation-{{ item.unit.checksum }}">
<td></td>
<td colspan="2" class="translatetext">
    <label>{% trans "Explanation" %}</label>
    <div class="list-group">
        <div class="list-group-item">
            <div class="list-group-item-text">
                {{ item.unit.source_unit.explanation|markdown }}
            </div>
        </div>
    </div>
</td>
</tr>
{% endif %}


<tr id="row-source-{{ item.unit.checksum }}">
<td>
{% if user.profile.zen_mode == user.profile.ZEN_HORIZONTAL %}
{% loading_icon item.unit.checksum %}
<span id="status-{{ item.unit.checksum }}">{% get_state_flags item.unit %}</span>
{% endif %}
</td>
<td {% if user.profile.zen_mode != user.profile.ZEN_HORIZONTAL %}colspan="2"{% endif %} class="translatetext">

{% if item.secondary %}
{% for unit in item.secondary %}
<div class="form-group">
<label>
    {{ unit.translation.language }}
    {% perm 'unit.edit' unit as user_can_edit_secondary %}
    {% if user_can_edit_secondary %}
    <a title="{% trans "Edit string" %}"href="{{ unit.get_absolute_url }}" class="btn btn-link btn-xs">{% icon "pencil.svg" %}</a>
    {% endif %}
</label>
{% format_translation unit.target unit.translation.language unit.translation.plural unit=unit %}
</div>
{% endfor %}
{% endif %}

{% if item.unit.previous_source and item.unit.fuzzy %}
<div class="form-group">
<label>{% trans "Source change" %}</label>
{% format_translation item.unit.source item.unit.translation.component.source_language diff=item.unit.previous_source num_plurals=item.unit.translation.plural.number %}
</div>
{% endif %}

{% if not user.profile.hide_source_secondary or not item.secondary %}
<div class="form-group">
<label>
    {{ item.unit.translation.component.source_language }}
    {% perm 'unit.edit' item.unit.source_unit as user_can_edit_template %}
    <a title="{% trans "Edit source string" %}"href="{{ item.unit.source_unit.get_absolute_url }}" class="btn btn-link btn-xs">{% icon "pencil.svg" %}</a>
</label>
{% format_translation item.unit.source item.unit.translation.component.source_language search_match=search_query num_plurals=item.unit.translation.plural.number unit=item.unit %}
</div>
{% endif %}

</td>

{% if user.profile.zen_mode != user.profile.ZEN_HORIZONTAL %}
</tr>


<tr id="row-edit-{{ item.unit.checksum }}">
<td>
{% loading_icon item.unit.checksum %}
<span id="status-{{ item.unit.checksum }}">{% get_state_flags item.unit %}</span>
</td>
{% endif %}
<td {% if user.profile.zen_mode != user.profile.ZEN_HORIZONTAL %}colspan="2"{% endif %} class="translator">
{% crispy item.form %}
</td>
</tr>


</tbody>
{% endfor %}

{% if last_section %}
<tbody>
<tr><td colspan="3" id="last-section">
{% trans 'The translation has come to an end.' as msg %}
{% show_message 'info' msg %}
</td></tr>
</tbody>
{% endif %}
