{% load djblets_deco djblets_extensions djblets_utils gravatars i18n %}
{% load rb_extensions reviewtags tz %}

<a name="review{{entry.review.id}}"></a>
<div id="review{{entry.review.id}}" class="review" data-review-id="{{entry.review.id}}" data-ship-it="{{entry.review.ship_it|yesno:'true,false'}}">
{% if forloop.last %}
 <a name="last-review"></a>
{% endif %}
 <div class="box-statuses">
  <div class="box-status{% if entry.review.ship_it %} ship-it{% endif %}{% if entry.issue_open_count > 0 %} has-issues{% endif %}">
   <div class="gravatar-container">
{% if siteconfig_settings.integration_gravatars %}
    {% gravatar entry.review.user 48 %}
{% endif %}
   </div>
   <div class="labels-container">
{%  if entry.review.ship_it %}
    <label class="ship-it-label">{% trans "Ship it!" %}</label>
{%  endif %}
{%  if entry.has_issues %}
    <label class="fix-it-label"{% if entry.issue_open_count == 0 %} style="display: none;"{% endif %}>{% trans "Fix it!" %}</label>
{%  endif %}
   </div>
  </div>
 </div>
{% box entry.class %}
 <div class="box-main">

  <div class="header">
{%  template_hook_point "review-summary-header-pre" %}
   <div class="collapse-button btn"><div class="rb-icon {% if entry.collapsed %}rb-icon-expand-review{% else %}rb-icon-collapse-review{% endif %}"></div></div>
   <div class="header-details">
    <div class="reviewer"><a href="{% url 'user' entry.review.user %}" class="user">{{entry.review.user|user_displayname}}</a></div>
    <div class="posted_time">{% localtime on %}{% blocktrans with entry.review.timestamp as timestamp and entry.review.timestamp|date:"c" as timestamp_raw %}<time class="timesince" datetime="{{timestamp_raw}}">{{timestamp}}</time>{% endblocktrans %}{% endlocaltime %}</div>
   </div>
{%  template_hook_point "review-summary-header-post" %}
  </div>

  <div class="banners"></div>

  <div class="body">
   <pre class="body_top reviewtext {% rich_text_classname entry.review.body_top_rich_text %}">{{entry.review.body_top|render_markdown:entry.review.body_top_rich_text}}</pre>
   <div class="body-top-comment-section">
{%  reply_section entry "" "body_top" "rcbt" entry.review.body_top %}
   </div>

{%  if entry.comments.diff_comments or entry.comments.screenshot_comments or entry.comments.file_attachment_comments %}
   <dl class="review-comments">

{%   for comment in entry.comments.screenshot_comments %}
    <dt>
     <a class="comment-anchor" name="{{comment.anchor_prefix}}{{comment.id}}"></a>
     <div class="screenshot">
      <span class="filename">
       <a href="{{comment.screenshot.get_absolute_url}}">{% spaceless %}
{% if draft and comment.screenshot.draft_caption %}
{{comment.screenshot.draft_caption}}
{% else %}
{{comment.screenshot.caption|default_if_none:comment.screenshot.image.name|basename}}
{% endif %}
{% endspaceless %}</a>
      </span>
      {{comment.image|safe}}
     </div>
    </dt>
    <dd>
{%    comment_detail_display_hook comment "review" %}
{%    if comment.issue_opened %}
     <div class="issue-indicator">
       {% comment_issue review_request_details comment "screenshot_comments" %}
     </div>
{%    endif %}
     <pre class="reviewtext comment-text {% rich_text_classname comment.rich_text %}" id="{{comment.anchor_prefix}}{{comment.id}}">{{comment.text|render_markdown:comment.rich_text}}</pre>
{%    reply_section entry comment "screenshot_comments" "rc" comment.text %}
    </dd>
{%   endfor %}

{%   for comment in entry.comments.file_attachment_comments %}
    <dt>
     <a class="comment-anchor" name="{{comment.anchor_prefix}}{{comment.id}}"></a>
     <div class="file-attachment">
      <div class="file-attachment-comment-header">
       <a href="{{comment.get_absolute_url}}">
        <span class="filename">{{comment.get_link_text}}</span>
       </a>
{%    if comment.file_attachment.attachment_revision %}
        <span class="diffrevision">
{%     if comment.diff_against_file_attachment %}
{%      blocktrans with revision1=comment.diff_against_file_attachment.attachment_revision revision2=comment.file_attachment.attachment_revision %}
         (Revisions {{revision1}} - {{revision2}})
{%      endblocktrans %}
{%     else %}
{%      blocktrans with revision=comment.file_attachment.attachment_revision %}
          (Revision {{revision}})
{%      endblocktrans %}
{%     endif %}
        </span>
{%    endif %}
      </div>
{%    with comment.thumbnail as thumbnail %}
{%     if thumbnail %}
      <div class="thumbnail">{{thumbnail|default:''|safe}}</div>
{%     endif %}
{%    endwith %}
     </div>
    </dt>
    <dd>
{%    comment_detail_display_hook comment "review" %}
{%    if comment.issue_opened %}
     <div class="issue-indicator">
{%     comment_issue review_request_details comment "file_attachment_comments" %}
     </div>
{%    endif %}
     <pre class="reviewtext comment-text {% rich_text_classname comment.rich_text %}" id="{{comment.anchor_prefix}}{{comment.id}}">{{comment.text|render_markdown:comment.rich_text}}</pre>
{%    reply_section entry comment "file_attachment_comments" "rc" comment.text %}
    </dd>
{%   endfor %}

{%   for comment in entry.comments.diff_comments %}
    <dt>
     <a class="comment-anchor" name="{{comment.anchor_prefix}}{{comment.id}}"></a>
     <div id="comment_container_{{comment.id}}" class="comment_container">
      <table class="sidebyside loading">
       <thead>
        <tr class="filename-row">
         <th class="filename">
          <a name="{{comment.get_absolute_url}}">{{comment.filediff.dest_file_display}}</a>
          <span class="diffrevision">
{%    if comment.interfilediff %}
           (Diff revisions {{comment.filediff.diffset.revision}} - {{comment.interfilediff.diffset.revision}})
{%    else %}
           (Diff revision {{comment.filediff.diffset.revision}})
{%    endif %}
          </span>
         </th>
        </tr>
       </thead>
       <tbody>
        <tr><td><pre>&nbsp;</pre></td></tr>{# header entry #}
{%    for i in comment.num_lines|default_if_none:1|range %}
        <tr><td><pre>&nbsp;</pre></td></tr>
{%    endfor %}
       </tbody>
      </table>
     </div>
    </dt>
    <dd>
{%    comment_detail_display_hook comment "review" %}
{%    if comment.issue_opened %}
     <div class="issue-indicator">
{%     comment_issue review_request_details comment "diff_comments" %}
     </div>
{%    endif %}
     <pre class="reviewtext comment-text {% rich_text_classname comment.rich_text %}" id="{{comment.anchor_prefix}}{{comment.id}}">{{comment.text|render_markdown:comment.rich_text}}</pre>
{%    reply_section entry comment "diff_comments" "rc" comment.text %}
    </dd>
{%   endfor %}
   </dl>
{%  endif %}
{%  if entry.review.body_bottom %}
   <pre class="body_bottom reviewtext {% rich_text_classname entry.review.body_bottom_rich_text %}">{{entry.review.body_bottom|render_markdown:entry.review.body_bottom_rich_text}}</pre>
   <div class="body-top-comment-section">
{%   reply_section entry "" "body_bottom" "rcbb" entry.review.body_bottom %}
   </div>
{%  endif %}
  </div>
 </div>
{% endbox %}
</div>
