{% load difftags i18n djblets_deco djblets_utils reviewtags static %}

{% if standalone and error %}
{{error}}
{% endif %}

{% definevar 'line_fmt' %}
  <tr line="%(linenum_row)s"%(row_class_attr)s>
{%  if not file.is_new_file %}
   <th>%(anchor_html)s%(linenum1)s</th>
   <td%(cell_1_class_attr)s>
    %(moved_to_html)s
    %(begin_collapse_html)s
    <pre>%(line1)s</pre>
    %(end_collapse_html)s
   </td>
{%  endif %}
   <th>%(linenum2)s</th>
   <td%(cell_2_class_attr)s>
    %(moved_from_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">
  <div class="diff-collapse-btn" title="{% trans "Collapse lines" %}"
       data-chunk-index="%(chunk_index)s" data-lines-of-context="0">
   <div class="rb-icon rb-icon-diff-collapse-chunk"></div>
  </div>
{% enddefinevar %}

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

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

{% if not standalone %}
<table id="file{{file.filediff.id}}" class="{% spaceless %}
  sidebyside
  {% if file.is_new_file %}newfile{% endif %}
  {% if file.binary %}diff-binary{% endif %}
  {% if file.deleted %}diff-deleted{% endif %}
  {% endspaceless %}"
       data-lines-equal="{{equal_lines}}">
 <colgroup>
{%  if not file.is_new_file %}
  <col class="line" />
  <col class="left" />
{%  endif %}
  <col class="line" />
  <col class="right" />
 </colgroup>
 <thead>
  <tr class="filename-row">
{%  if file.dest_filename == file.depot_filename %}
   <th colspan="4">
    <a name="{{file.index}}" class="file-anchor"></a>
{%   if file.binary %}
{%    if modified_diff_file_attachment %}
    <img class="header-file-icon" src="{{modified_diff_file_attachment.icon_url}}" />
{%    elif orig_diff_file_attachment %}
    <img class="header-file-icon" src="{{orig_diff_file_attachment.icon_url}}" />
{%    endif %}
{%   endif %}
    {{file.depot_filename}}
  </th>
{%  else %}
{%   if not file.is_new_file %}
   <th colspan="2"><a name="{{file.index}}" class="file-anchor"></a>{{ file.depot_filename }}</th>
{%   endif %}
   <th colspan="2">
{%   if file.is_new_file %}
    <a name="{{file.index}}" class="file-anchor"></a>
{%   endif %}
    {{file.dest_filename}}{% if file.moved %}{% trans " (moved)" %}{% elif file.copied %}{% trans " (copied)" %}{% endif %}</th>
{%  endif %}{# file.dest_filename == file.depot_filename #}
  </tr>
  <tr class="revision-row">
{%  if file.moved_or_copied and file.num_changes == 0 %}
   <th colspan="4"></th>
{%  else %}
{%   if not file.is_new_file %}
   <th></th>
   <th class="revision-col">
{%    if download_orig_url %}
    <a class="rb-icon rb-icon-download download-link" href="{{download_orig_url}}" alt="{% trans 'Download' %}" title="{% trans 'Download' %}"></a>
{%    endif %}
    {{file.revision}}
    </th>
{%   endif %}
   <th></th>
{%   if not file.deleted %}
   <th class="revision-col">
{%    if download_modified_url %}
    <a class="rb-icon rb-icon-download download-link" href="{{download_modified_url}}" alt="{% trans 'Download' %}" title="{% trans 'Download' %}"></a>
{%    endif %}
    {{file.dest_revision}}
   </th>
{%   else %}
   <th></th>
{%   endif %}
{%  endif %}{# num_changes and moved #}
  </tr>
 </thead>
{% endif %}{# not standalone #}

{% if file.binary %}
 <tbody class="binary" data-file-id="{{modified_diff_file_attachment.id}}">
{%  if orig_diff_file_attachment or modified_diff_file_attachment %}
  <tr class="inline-actions-header">
{%   if file.moved_or_copied and file.num_changes == 0 or file.newfile and not orig_diff_file_attachment %}
   <td colspan="4">
{%   else %}
   <td colspan="2">
    <div class="inline-actions-container clearfix">
     <ul class="actions inline-actions-left">
     </ul>
    </div>
   </td>
   <td colspan="2">
{%   endif %}
    <div class="inline-actions-container clearfix">
     <ul class="actions inline-actions-right">
{%   if modified_diff_file_attachment %}
{%    if not modified_attachment_review_ui_html and not diff_attachment_review_ui_html %}
{%     if modified_diff_file_attachment.review_ui %}
      <li class="file-review"><a href="{% url 'file-attachment' modified_diff_file_attachment.get_review_request.display_id modified_diff_file_attachment.pk %}">{% trans "Review" %}</a></li>
{%     else %}
      <li class="file-add-comment"><a href="#">{% trans "New Comment" %}</a></li>
{%     endif %}
{%    endif %}
{%   endif %}
     </ul>
    </div>
  </tr>
{%  endif %}
  <tr class="inline-files-container">
{%  if diff_attachment_review_ui_html %}
  <td colspan="4" class="diff-review-ui">{{diff_attachment_review_ui_html}}</td>
{%  else %}
{%   if file.moved_or_copied and file.num_changes == 0 or file.newfile and not orig_diff_file_attachment %}
   <td colspan="4">
{%   else %}
   <td colspan="2">
{%    if not orig_diff_file_attachment %}
{%     trans "This is a binary file. The content cannot be displayed." %}
{%    elif orig_attachment_review_ui_html %}
{{     orig_attachment_review_ui_html}}
{%    elif orig_diff_file_attachment.thumbnail %}
    <div class="file-thumbnail-container">{{orig_diff_file_attachment.thumbnail}}</div>
{%    else %}
{%     trans "No preview available." %}
{%    endif %}
   </td>
   <td colspan="2">
{%   endif %}
{%   if not modified_diff_file_attachment %}
{%    trans "This is a binary file. The content cannot be displayed." %}
{%   elif modified_attachment_review_ui_html %}
{{    modified_attachment_review_ui_html}}
{%   elif modified_diff_file_attachment.thumbnail %}
    <div class="file-thumbnail-container">{{modified_diff_file_attachment.thumbnail}}</div>
{%   else %}
{%    trans "No preview available." %}
{%   endif %}
{%  endif %}
   </td>
  </tr>
 </tbody>
{% elif file.moved_or_copied and file.num_changes == 0 %}
 <tbody class="no-changes">
  <tr>
   <td colspan="4">{% trans "No changes were made to this file." %}</td>
  </tr>
 </tbody>
{% elif file.newfile and file.num_chunks == 0 %}
 <tbody class="new-empty-file">
  <tr>
   <td colspan="4">{% trans "This is an empty file." %}</td>
  </tr>
 </tbody>
{% elif file.deleted %}
 <tbody class="deleted">
  <tr>
   <td colspan="4">
{%  if file.num_changes == 0 %}
{%   trans "This empty file was deleted. The content cannot be displayed." %}
{%  else %}
{%   trans "This file was deleted. The content cannot be displayed." %}
{%  endif %}
   </td>
  </tr>
 </tbody>
{% else %}
{%  if file.whitespace_only and not standalone %}
 <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}}"{% 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.index 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' %}{% blocktrans count lines=chunk.numlines %}{{lines}} line{% plural %}{{lines}} lines{% endblocktrans %}{% 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>
{%  endif %}
