[%# 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.
  #%]

[%#
  # bug: (bug object) the main bug object
  # active_attachments: array of active attachment objects
  # obsolete_attachments: array of obsolete attachment objects
  #%]

[% IF active_attachments || obsolete_attachments %]
<table role="table" class="layout-table" id="attachments">
  [% FOREACH attachment IN bug.attachments %]
    [%
      NEXT IF attachment.isprivate
        && !(user.is_insider
              || attachment.attacher.id == user.id
              || (attachment.is_bounty_attachment && user.id == bug.reporter.id));
      attachment_rendered = 0;
      Hook.process("row");
      NEXT IF attachment_rendered;
    %]
    <tr class="
        [%~ " bz_private" IF attachment.isprivate %]
        [%~ " attach-obsolete" IF attachment.isobsolete %]
        [%~ " attach-patch" IF attachment.can_review %]
    " [% IF attachment.isobsolete %]style="display:none"[% END %]>
      <td class="attach-desc-td">
        <div class="attach-desc">
          [% IF attachment.is_image %]
            <a href="[% basepath FILTER none %]attachment.cgi?id=[% attachment.id FILTER none %]"
              title="[% attachment.description FILTER html %]"
              class="lightbox">
              <img src="[% basepath FILTER none %]extensions/BugModal/web/image.png" width="16" height="16">
              [%~ attachment.description FILTER html %]
            </a>
          [% ELSE %]
            <a href="[% basepath FILTER none %]attachment.cgi?id=[% attachment.id FILTER none %]">
              [%~ attachment.description FILTER html %]</a>
          [% END %]
        </div>
        <div>
          [% activity_id = bug.find_activity_id_for_attachment(attachment) %]
          [% IF activity_id %]
            <a href="#[% activity_id FILTER none %]" class="attach-time activity-ref">
              [% INCLUDE bug_modal/rel_time.html.tmpl ts=attachment.attached %]</a>
          [% ELSE %]
            <span class="attach-time">[% INCLUDE bug_modal/rel_time.html.tmpl ts=attachment.attached %]</span>
          [% END %]
          <span class="attach-author">[% INCLUDE bug_modal/user.html.tmpl u=attachment.attacher %]</span>
        </div>
        <div class="attach-info">
          [% IF attachment.datasize %]
            [%- attachment.datasize FILTER unitconvert %]
          [% ELSE %]
            (deleted)
          [% END %],
          [%+ attachment.ispatch ? "patch" : attachment.contenttype FILTER html -%]
        </div>
      </td>
      <td>
        [% FOREACH flag IN attachment.flags %]
          <div class="attach-flag">
            [% INCLUDE bug_modal/user.html.tmpl u=flag.setter simple=1 %]:
            [% activity_id = bug.find_activity_id_for_flag(flag) %]
            [% IF activity_id %]
              <a href="#[% activity_id FILTER none %]"
            [% ELSE %]
              <span
            [% END %]
              [% IF user.setting("ui_use_absolute_time") == "on" %]
                  class="flag-name-status abs-time-title[% " activity-ref" IF activity_id %]"
                  title="[% flag.creation_date FILTER time("%Y-%m-%d %H:%M %Z") FILTER html %]"
              [% ELSE %]
                  class="flag-name-status rel-time-title[% " activity-ref" IF activity_id %]"
                  title="[% flag.creation_date FILTER time_duration FILTER html %]"
              [% END %]
              data-time="[% flag.creation_date FILTER epoch FILTER none %]"
            >
              [%+ flag.type.name FILTER html %][% flag.status FILTER none %]
            [% activity_id ? "</a>" : "</span>" %]
            [% IF flag.requestee %]
              [%+ INCLUDE bug_modal/user.html.tmpl u=flag.requestee simple=1 %]
            [% END %]
          </div>
        [% END %]
      </td>
      <td class="attach-actions">
        <a href="[% basepath FILTER none %]attachment.cgi?id=[% attachment.id FILTER none %]&amp;action=edit">Details</a>
        [% IF attachment.ispatch %]
          | <a href="[% basepath FILTER none %]attachment.cgi?id=[% attachment.id FILTER none %]&amp;action=diff">Diff</a>
        [% END %]
        [% Hook.process("action", "attachment/list.html.tmpl") %]
    </tr>
  [% END %]
</table>
[% END %]

<footer id="attachments-footer">
  <div id="attachments-actions">
    [% IF user.id %]
      <a href="[% basepath FILTER none %]attachment.cgi?bugid=[% bug.id FILTER uri %]&amp;action=enter" id="attachments-add-link">
        <button type="button" role="none" id="attachments-add-btn" class="secondary">Attach New File</button>
      </a>
    [% END %]
    [% IF obsolete_attachments %]
      <button type="button" id="attachments-obsolete-btn" class="secondary">Show Obsolete</button>
    [% END %]
  </div>
  [%# BMO - attachment related warnings %]
  [% Hook.process("warnings") %]
</footer>
