[%# This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  #
  # This Source Code Form is "Incompatible With Secondary Licenses", as
  # defined by the Mozilla Public License, v. 2.0.
  #%]

[% PROCESS "global/field-descs.none.tmpl" %]
[% PROCESS "global/reason-descs.none.tmpl" %]

[% isnew = bug.lastdiffed ? 0 : 1 %]
<html>
<head>
  <base href="[% urlbase FILTER html %]">
</head>
<body style="font-family: sans-serif">

  [% IF !to_user.in_group('editbugs') %]
    <div id="noreply" style="font-size: 90%; color: #666666">
      Do not reply to this email. You can add comments to this [% terms.bug %] at
      [%# using the bug_link filter here causes a weird template error %]
      <a href="[% urlbase FILTER html %]show_bug.cgi?id=[% bug.id FILTER none %]">
      [% urlbase FILTER html %]show_bug.cgi?id=[% bug.id FILTER none %]</a>
    </div>
    <br>
  [% END %]

  [% IF isnew %]
    [% PROCESS generate_new %]
  [% ELSE %]
    [% PROCESS generate_diffs %]
  [% END %]

  [% SET comment_anchor = '' %]
  [% IF new_comments.size %]
    <div id="comments">
      [% FOREACH comment = new_comments.reverse %]
        <div>
          [% IF comment.count %]
            [% comment_anchor = "#c$comment.count" %]
            <b>
              [% "Comment # ${comment.count}"
                FILTER bug_link(bug, { comment_num => comment.count, full_url => 1 }) FILTER none %]
              on [% "$terms.Bug $bug.id" FILTER bug_link(bug, { full_url => 1 }) FILTER none %]
              from [% INCLUDE global/user.html.tmpl user = to_user, who = comment.author %]
              at [% comment.creation_ts FILTER time(undef, to_user.timezone) %]
            </b>
          [% END %]
          [% IF comment.is_markdown AND Param('use_markdown') %]
            [% should_wrap = 0 %]
            [% comment_tag = 'div' %]
          [% ELSE %]
            [% should_wrap = 1 %]
            [% comment_tag = 'pre' %]
          [% END %]
          <[% comment_tag FILTER none %] class="comment" [% IF comment_tag == 'pre' %] style="font-size: initial" [% END %]>[% comment.body_full({ wrap => should_wrap }) FILTER renderMarkdown(bug, comment) %]</[% comment_tag FILTER none %]>
        </div>
      [% END %]
    </div>
    <br>
  [% END %]

  [% IF referenced_bugs.size %]
    <div id="referenced">
      <hr style="border: 1px dashed #969696">
      <b>Referenced [% terms.Bugs %]:</b>
      <ul>
        [% FOREACH ref = referenced_bugs %]
          <li>
            [<a href="[% urlbase FILTER html %]show_bug.cgi?id=[% ref.id FILTER none %]">
            [% terms.Bug %]&nbsp;[% ref.id FILTER none %]</a>] [% ref.short_desc FILTER html %]
          </li>
        [% END %]
      </ul>
    </div>
    <br>
  [% END %]

  <div id="bug_details" style="font-size: 90%; color: #666666">
    <hr style="border: 1px dashed #969696">
    Product/Component: [% bug.product FILTER html %] :: [% bug.component FILTER html %]<br>
    [% "You are mentoring this " _ terms.bug IF bug.is_mentor(to_user) %]
  </div>

  [% seen_header = 0 %]
  [% FOREACH flag = tracking_flags %]
    [% NEXT IF bug.${flag.name} == "---" %]
    [% IF !seen_header %]
      [% seen_header = 1 %]
      <div id="tracking" style="font-size: 90%; color: #666666">
        <hr style="border: 1px dashed #969696">
        <b>Tracking Flags:</b>
        <ul>
    [% END %]
    <li>[% flag.description FILTER html %]:[% bug.${flag.name} FILTER html %]</li>
  [% END %]
  [% IF seen_header %]
      </ul>
    </div>
  [% END %]

  <div id="reason" style="font-size: 90%; color: #666666">
    <hr style="border: 1px dashed #969696">
    <b>You are receiving this mail because:</b>
    <ul>
      [% FOREACH reason = reasons %]
        [% IF reason_descs.$reason  %]
          <li>[% reason_descs.$reason FILTER html %]</li>
        [% END %]
      [% END %]
      [% FOREACH reason = reasons_watch %]
        [% IF watch_reason_descs.$reason %]
          <li>[% watch_reason_descs.$reason FILTER html %]</li>
        [% END %]
      [% END %]
    </ul>
    Configure your email settings at
    <a href="[% urlbase FILTER none %]userprefs.cgi?tab=email">[% urlbase FILTER none %]userprefs.cgi?tab=email</a>.
  </div>

  <div itemscope itemtype="http://schema.org/EmailMessage">
    <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
      [%# Filtering of the URL param is not required & would break the URL when the comment anchor is set %]
      <link itemprop="url" href="[% urlbase FILTER html %]show_bug.cgi?id=[% "$bug.id$comment_anchor" FILTER none %]">
      <meta itemprop="name" content="View [% terms.bug %]">
    </div>
    <meta itemprop="description" content="[% terms.Bugzilla %] [%+ terms.bug %] update notification">
  </div>
  @@body-headers@@
</body>
</html>

[% BLOCK generate_new %]
  <div class="new">
    <table border="0" cellspacing="0" cellpadding="3">
    [% FOREACH change = diffs %]
      [% PROCESS "email/bugmail-common.txt.tmpl" %]
      <tr>
        <td class="c1" style="border-right: 1px solid #969696" nowrap><b>[% field_label FILTER html %]</b></td>
        <td class="c2">
          [% IF change.field_name == "bug_id" %]
            [% new_value FILTER bug_link(bug, full_url => 1) FILTER none %]
          [% ELSE %]
            [% new_value FILTER html %]
          [% END %]
        </td>
      </tr>
    [% END %]
    </table>
  </div>
  <br>
[% END %]

[% BLOCK generate_diffs %]
  [% SET in_table = 0 %]
  [% last_changer = 0 %]
  [% FOREACH change = diffs %]
    [% PROCESS "email/bugmail-common.txt.tmpl" %]
    [% IF changer.id != last_changer %]
      [% last_changer = changer.id %]
      [% IF in_table == 1 %]
          </table>
        </div>
        <br>
        [% SET in_table = 0 %]
      [% END %]

      <b>
        [% IF change.blocker %]
          [% "${terms.Bug} ${bug.id}" FILTER bug_link(bug, full_url => 1) FILTER none %]
          depends on
          <a href="[% urlbase FILTER html %]show_bug.cgi?id=[% change.blocker.id FILTER none %]">
          [% terms.Bug %]&nbsp;[% change.blocker.id FILTER none %]</a>,
          which changed state.<br>
        [% ELSE %]
          [% INCLUDE global/user.html.tmpl user = to_user, who = changer %] changed
          [%+ "${terms.Bug} ${bug.id}" FILTER bug_link(bug, full_url => 1) FILTER none %]
          at [% change.bug_when FILTER time(undef, to_user.timezone) %]</b>:<br>
        [% END %]
      </b>

      [% IF in_table == 0 %]
        <br>
        <div class="diffs">
          <table border="0" cellspacing="0" cellpadding="5">
        [% SET in_table = 1 %]
      [% END %]
      <tr class="head">
        <td class="c1" style="border-bottom: 1px solid #969696; border-right: 1px solid #969696"><b>What</b></td>
        <td class="c2" style="border-bottom: 1px solid #969696; border-right: 1px solid #969696"><b>Removed</b></td>
        <td class="c3" style="border-bottom: 1px solid #969696"><b>Added</b></td>
      </tr>
    [% END %]

    <tr>
      <td class="c1" style="border-right: 1px solid #969696" nowrap>[% field_label FILTER html %]</td>
      <td class="c2" style="border-right: 1px solid #969696">
        [% IF old_value %]
          [% old_value FILTER html %]
        [% ELSE %]
          &nbsp;
        [% END %]
      </td>
      <td>
        [% IF new_value %]
          [% new_value FILTER html %]
        [% ELSE %]
          &nbsp;
        [% END %]
      </td>
    </tr>
  [% END %]
  [% IF in_table %]
      </table>
    </div>
    <br>
  [% END %]
[% END %]

