[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Bug Tracking System.
  #
  # The Initial Developer of the Original Code is Netscape Communications
  # Corporation. Portions created by Netscape are
  # Copyright (C) 1998 Netscape Communications Corporation. All
  # Rights Reserved.
  #
  # Contributor(s): Gervase Markham <gerv@gerv.net>
  #                 Max Kanat-Alexander <mkanat@bugzilla.org>
  #                 Shane H. W. Travis <travis@sedsystems.ca>
  #                 Vitaliy Filippov <vitalif@mail.ru>
  #%]

[%# FIXME check if all is working correctly without JavaScript! (definitely there are bugs) %]

[% PROCESS bug/time.html.tmpl %]

[% DEFAULT mode = "show" %]

[%# This auto-sizes the comments and positions the collapse/expand links to the right. %]
<table class="bz_comment_table" cellpadding="0" cellspacing="0"[% ' width="100%"' IF user.settings.comment_width.value == 'on' %]><tr>
<td>

[% PROCESS "bug/comment-preview-div.html.tmpl" %]

[% FOREACH comment = comments %]
  [% PROCESS a_comment %]
[% END %]

[%# Note: this template is used in multiple places; if you use this hook,
  # make sure you are aware of this fact.
  #%]
[% Hook.process("aftercomments") %]

</td>
<td width="200">
  [% IF mode == "edit" %]
    <script type="text/javascript">
      addActionLinks([% json(comment_indexes(comments)) %]);
    </script>
    <ul class="bz_collapse_expand_comments">
      <li><a href="#" onclick="toggle_all_comments('collapse'); return false;">Collapse All Comments</a></li>
      <li><a href="#" onclick="toggle_all_comments('expand'); return false;">Expand All Comments</a></li>
    </ul>
  [% END %]
</td>
</tr></table>

[%############################################################################%]
[%# Block for individual comments                                            #%]
[%############################################################################%]

[% BLOCK a_comment %]
  [% RETURN IF comment.is_private AND !user.is_insider %]
  [% has_worktime = user.is_timetracker && (comment.work_time > 0 || comment.work_time < 0) %]
  [% wt_only = comment.type == constants.CMT_WORKTIME || comment.type == constants.CMT_BACKDATED_WORKTIME %]
  [% wt_all = user.settings.showhide_comments.value == 'all' %]
  [% wt_wt = user.settings.showhide_comments.value == 'worktime' %]
  [%# CMT_BACKDATED_WORKTIME comments will break numbering if transformed back to normal %]
  [%
     wt_btn = !multiple
       && comment.type != constants.CMT_BACKDATED_WORKTIME
       && (wt_wt && (has_worktime || wt_only) || wt_all)
       && (comment.who == user.id || user.in_group('worktimeadmin'))
  %]
  <div class="bz_comment
                [%- " bz_private" IF comment.is_private %]
                [%- " bz_comment_hilite" IF marks.$count %]
                [%- " bz_first_comment" IF comment.count == 0 %]">
      [% IF comment.count == 0 %]
        [% class_name = "bz_first_comment_head" %]
        [% comment_label = "Description" %]
      [% ELSE %]
        [% class_name = wt_only ? "bz_comment_wthead" : "bz_comment_head" %]
        [% comment_label = "Comment " _ comment.count %]
      [% END %]

      <div class="[% class_name %]">

        <span class="bz_comment_actions" id="comment_act_[% comment.id %]"></span>

        [% IF wt_btn %]
        <span class="bz_comment_actions">
          [% IF wt_only %]
          <img src="images/clock.gif" width="16" height="16"
              alt="Comment is marked as worktime-only. Click to mark it as normal, then click Save Changes"
            title="Comment is marked as worktime-only. Click to mark it as normal, then click Save Changes"
            style="cursor: pointer; vertical-align: middle"
            onclick="toggle_wtonly([% comment.id %],1,this)" />
          <input type="hidden" id="cmt_normal_[% comment.id %]" name="cmt_normal_[% comment.id %]" value="" />
          [% ELSIF comment.type == constants.CMT_NORMAL %]
          <img src="images/clockx.gif" width="16" height="16"
              alt="Comment is marked as normal. Click to mark it as worktime-only, then click Save Changes"
            title="Comment is marked as normal. Click to mark it as worktime-only, then click Save Changes"
            style="cursor: pointer; vertical-align: middle"
            onclick="toggle_wtonly([% comment.id %],0,this)" />
          <input type="hidden" id="cmt_worktime_[% comment.id %]" name="cmt_worktime_[% comment.id %]" value="" />
          [% END %]
        </span>
        [% END %]

        [% IF mode == "edit" && user.is_insider %]
          <div class="bz_private_checkbox">
            <input type="hidden" value="1"
                   name="defined_isprivate_[% comment.id %]" />
            <input type="checkbox"
                   name="isprivate_[% comment.id %]" value="1"
                   id="isprivate_[% comment.id %]"
                   onClick="updateCommentPrivacy(this, [% comment.id %])"
                   [% " checked=\"checked\"" IF comment.is_private %] />
            <label for="isprivate_[% comment.id %]">Private</label>
          </div>
        [% END %]

        <a name="[% comment.bug_when FILTER timestamp %]"></a>
        [% IF NOT wt_only %]
        <span class="bz_comment_number">
          [% IF comment.author.id == user.id && collision != 1 %]
          [<a href="#" onclick="showEditComment([% comment.id %]); return false;">Edit Comment</a>]
          [% END %]
          <a name="c[% comment.count %]"
             href="show_bug.cgi?id=[% bug.bug_id %]#c[% comment.count %]">
            [%- comment_label FILTER html %]</a>
        </span>
        [% END %]

        <span class="bz_comment_user">
          [% INCLUDE global/user.html.tmpl who = comment.author %]
        </span>

        <span class="bz_comment_user_images">
          [% FOREACH group = comment.author.direct_group_membership %]
            [% NEXT UNLESS group.icon_url %]
            <img src="[% group.icon_url FILTER html %]"
                 alt="[% group.name FILTER html %]"
                 title="[% group.name FILTER html %] - [% group.description FILTER html %]">
          [% END %]
        </span>

        <span class="bz_comment_time">
          [%+ comment.creation_ts FILTER time %]
        </span>

        [% IF wt_only && has_worktime %]
        <div class="bz_comment_worktime">
          [% PROCESS formattimeunit time_unit=comment.work_time %]h
        </div>
        [% END %]

        <div style="clear: both"></div>
      </div>

      [% IF !wt_only && has_worktime %]
        <br />
        Additional hours worked:
        [%+ PROCESS formattimeunit time_unit=comment.work_time %]
      [% END %]

[%# Don't indent the <pre> block, since then the spaces are displayed in the
  # generated HTML
  #%]
<div class="bz_comment_text[% " collapsed" IF wt_only %][% " bz_fullscreen_comment" IF user.settings.comment_width.value == 'on' %]" id="comment_text_[% comment.id %]">
  [%- comment.body_full({ wrap => 1, wo_preview => (user.settings.preview_long_comments.value == 'off') }) -%]
</div>
    </div>
[% END %]
