{% load i18n %}
{% load difftags %}
{% load djblets_deco %}
{% load djblets_utils %}
{% load static %}
{% if standalone and error %}
{{error}}
{% endif %}

{% definevar 'line_fmt' %}
  <tr line="%(linenum_row)s"%(class_attr)s>
   <th>%(anchor_html)s%(linenum1)s</th>
   <td>%(moved_from_html)s
    %(begin_collapse_html)s
    <pre>%(line1)s</pre>
    %(end_collapse_html)s
   </td>
   <th>%(linenum2)s</th>
   <td>%(moved_to_html)s
    <pre>%(line2)s</pre>
   </td>
  </tr>
{% enddefinevar %}

{% definevar 'anchor_fmt' %}
 <a name="%(anchor)s" class="chunk-anchor"></a>
{% enddefinevar %}

{% definevar 'begin_collapse_fmt' %}
 <div class="collapse-floater"><img src="{% static "rb/images/diff-collapse.png" %}" width="14" height="14" alt="{% trans "Collapse lines" %}" title="{% trans "Collapse lines" %}" class="diff-collapse-btn" onclick="javascript:RB.expandChunk('{{base_url}}', 'file{{file.index}}', '{{file.filediff.pk}}', '{{file.filediff.diffset.revision}}', {% if file.interfilediff %}'{{file.interfilediff.diffset.revision}}'{% else %}null{% endif %}, '{{file.index}}', '%(chunk_index)s', 0, this); return false;" />
{% enddefinevar %}

{% definevar 'end_collapse_fmt' %}
</div>
{% enddefinevar %}

{% definevar 'moved_fmt' %}
 <a href="#" class="%(class)s" line="%(line)s" target="%(target)s">%(text)s</a>
{% enddefinevar %}

{% if file.changed_chunk_indexes or file.binary or file.deleted or file.moved %}
{%  if not standalone %}
<table class="sidebyside{% if not file.interfilediff and file.newfile and not file.filediff.parent_diff %} newfile{% endif %}" id="file{{file.filediff.id}}">
 <colgroup>
  <col class="line" />
  <col class="left" />
  <col class="line" />
  <col class="right" />
 </colgroup>
 <thead>
  <tr onClick="gotoAnchor('{{file.index}}');">
{%   if file.dest_filename == file.depot_filename %}
   <th colspan="4"><a name="{{file.index}}" class="file-anchor"></a>{{ file.depot_filename }}</th>
{%   else %}
   <th colspan="2"><a name="{{file.index}}" class="file-anchor"></a>{{ file.depot_filename }}</th>
   <th colspan="2">{{ file.dest_filename }}{% if file.moved %}{% trans " (moved)" %}{% endif %}</th>
{%   endif %}{# file.dest_filename == file.depot_filename #}
  </tr>
  <tr>
{%   if file.moved and file.num_changes == 0 %}
   <th colspan="4" class="rev">{% trans "No changes were made to this file." %}</th>
{%   else %}
   <th colspan="2" class="rev">{{file.revision}}</th>
   <th colspan="2" class="rev">{{file.dest_revision}}</th>
{%   endif %}{# num_changes and moved #}
  </tr>
 </thead>
{%  endif %}{# not standalone #}
{%  if file.binary %}
 <tbody class="binary">
  <tr>
   <td colspan="4">{% trans "This is a binary file. The content cannot be displayed." %}</td>
  </tr>
 </tbody>
{%  elif file.deleted %}
 <tbody class="deleted">
  <tr>
   <td colspan="4">{% trans "This file was deleted. The content cannot be displayed." %}</td>
  </tr>
 </tbody>
{%  elif file.whitespace_only %}
    <tbody class="whitespace-file">
     <tr>
      <td colspan="4">{% trans "This file contains only whitespace changes." %}</td>
     </tr>
    </tbody>
{%  else %}
{%   for chunk in file.chunks %}
{%    if not chunk.collapsable or not collapseall %}
 <tbody id="chunk{{file.index}}.{{chunk.index}}"{% attr "class" %}{% if chunk.change != "equal" %}{{chunk.change}}{% if chunk.meta.whitespace_chunk%} whitespace-chunk{% endif %}{% else %}{% if chunk.collapsable %} collapsable{% endif %}{% endif %}{% if standalone %} loaded{% endif %}{% endattr %}>
{%     diff_lines file chunk standalone line_fmt anchor_fmt begin_collapse_fmt end_collapse_fmt moved_fmt %}
 </tbody>
{%    else %}
 <tbody class="diff-header" id="collapsed-chunk{{file.index}}.{{chunk.index}}">
  <tr>
   <th>
{% if chunk.index != 0 %}
    {% diff_expand_link 'above' _('Show 20 more lines above') 20 0 %}
{% endif %}
   </th>
   <td colspan="3">
    {% definevar 'expand_text' %}{{chunk.numlines}} line{{chunk.numlines|pluralize}}{% enddefinevar %}
    {% diff_expand_link 'all' _('Show all lines') 0 0 expand_text %}
   </td>
  </tr>
{% if chunk.index|add:1 != file.num_chunks %}
  <tr>
   <th>{% diff_expand_link 'below' _('Show 20 more lines below') 0 20 %}</th>
{%   if chunk.meta.headers and chunk.meta.headers.0 %}
{%    if chunk.meta.headers.0.text == chunk.meta.headers.1.text %}
   <td colspan="3">{% diff_chunk_header chunk.meta.headers.0 %}</td>
{%    else %}
   <td>{% diff_chunk_header chunk.meta.headers.0 %}</td>
   <td colspan="2">
{%     if chunk.meta.headers.1 %}
{%      diff_chunk_header chunk.meta.headers.1 %}
{%     endif %}
   </td>
{%    endif %}
{%   else %}
   <td colspan="3"></td>
{%   endif %}
  </tr>
{% endif %}
 </tbody>
{%       endif %}
{%      endfor %}{# chunks #}
{%     endif %}{# file deleted, binary and whitespace_only #}
{%  if not standalone %}
</table>
<script type="text/javascript">
  $(document).ready(function() {
    /* Add to the change index. */
    $("li.change_file_{{file.index}}").html(
      {% include_as_string "diffviewer/changeindex_entry.html" %});
  });
</script>
{%  endif %}{# not standalone #}
{% else %}{# No changed chunks and not a binary file #}
{%  if not standalone %}
<script type="text/javascript">
  $(document).ready(function() {
    $("li.change_file_{{file.index}}").remove();
  });
</script>
{%  endif %}{# not standalone #}
{% endif %}{# No changed chunks and not a binary file #}
