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

{% if file.changed_chunk_indexes or file.binary or file.deleted %}
{%  if not standalone %}
<table class="sidebyside{% if not file.interfilediff and file.newfile %} 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 }}</th>
{%   endif %}{# file.dest_filename == file.depot_filename #}
  </tr>
  <tr>
   <th colspan="2" class="rev">{{file.revision}}</th>
   <th colspan="2" class="rev">{{file.dest_revision}}</th>
  </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>
{%  else %}
{%   if file.deleted %}
 <tbody class="deleted">
  <tr>
   <td colspan="4">{% trans "This file was deleted. The content cannot be displayed." %}</td>
  </tr>
 </tbody>
{%   else %}
{%    if file.whitespace_only %}
    <tbody class="whitespace-file">
     <tr>
      <td colspan="4">{% trans "This file contains only whitespace changes." %}</td>
     </tr>
    </tbody>
{%    endif %}
{%    for chunk in file.chunks %}
{%     if not chunk.collapsable or not collapseall %}
 <tbody id="chunk{{file.index}}.{{chunk.index}}"{% ifnotequal chunk.change "equal" %} class="{{chunk.change}}{% if chunk.meta.whitespace_chunk%} whitespace-chunk{% endif%}"{% else %}{% if chunk.collapsable %} class="collapsable"{% endif %}{% endifnotequal %}>
{%      for line in chunk.lines %}
  <tr line="{{line.0}}"{% ifnotequal chunk.change "equal" %} {% attr "class" %}{% if forloop.first %}first {% endif %}{% if forloop.last %}last {% endif %} {% if line.7 %}whitespace-line{% endif %}{% endattr %}{% endifnotequal %}>
{%       if forloop.first %}
   <th>{% ifnotequal chunk.change 'equal' %}<a name="{{file.index}}.{{chunk.index}}" class="chunk-anchor"></a>{% endifnotequal %}{{line.1}}</th>
{%       else %}
   <th>{{line.1}}</th>
{%       endif %}
{%       ifequal chunk.change "replace" %}
   <td><pre>{{ line.2|highlightregion:line.3|showextrawhitespace }}</pre></td>
   <th>{{line.4}}</th>
   <td><pre>{{ line.5|highlightregion:line.6|showextrawhitespace }}</pre></td>
{%       else %}
   <td>{% ifequal chunk.change 'insert' %}{% if line.8 %}
    <a href="#" class="moved-from" line="{{line.8}}" target="{{line.4}}">{% trans "Moved from" %} {{line.8}}</a>
    {% endif %}{% endifequal %}
    <pre>{{line.2|showextrawhitespace}}</pre>
   </td>
   <th>{{line.4}}</th>
   <td>{% ifequal chunk.change 'delete' %}{% if line.8 %}
    <a href="#" class="moved-to" line="{{line.8}}" target="{{line.1}}">{% trans "Moved to" %} {{line.8}}</a>
    {% endif %}{% endifequal %}
    <pre>{{line.5|showextrawhitespace}}</pre>
   </td>
{%       endifequal %}
  </tr>
{%      endfor %}
 </tbody>
{%     else %}
 <tbody class="diff-header" id="collapsed-chunk{{file.index}}.{{forloop.counter0}}">
  <tr>
   <th>...</th>
   <td colspan="3">{{chunk.numlines}} line{{chunk.numlines|pluralize}} hidden [<a href="#" onclick="javascript:expandChunk('{{base_url}}', 'file{{file.index}}', '{{file.filediff.id}}', '{{file.filediff.diffset.revision}}', {% if file.interfilediff %}'{{file.interfilediff.diffset.revision}}'{% else %}null{% endif %}, '{{forloop.counter0}}', this); return false;">{% trans "Expand" %}</a>]
   </td>
  </tr>
{% if chunk.meta.headers %}
  <tr>
{%  ifequal chunk.meta.headers.0 chunk.meta.headers.1 %}
   <td colspan="4"><pre>{{chunk.meta.headers.0}}</pre></td>
{%  else %}
   <td colspan="2"><pre>{{chunk.meta.headers.0}}</pre></td>
   <td colspan="2"><pre>{{chunk.meta.headers.1}}</pre></td>
{%  endifequal %}
  </tr>
{% endif %}
 </tbody>
{%      endif %}
{%     endfor %}{# chunks #}
{%    endif %}{# not file.deleted #}
{%   endif %}{# not file.binary #}
{%  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 #}
