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

[% style_urls.push('extensions/Review/web/styles/badge.css') %]
[% javascript_urls.push('js/lib/md5.min.js', 'extensions/Review/web/js/badge.js') %]

[% RETURN UNLESS template.name == 'attachment/edit.html.tmpl'
      || template.name == 'attachment/create.html.tmpl'
      || template.name == 'attachment/diff-header.html.tmpl'
      || template.name == 'bug/create/create.html.tmpl'
      || template.name == 'pages/splinter.html.tmpl' %]

[% style_urls.push('extensions/Review/web/styles/review.css') %]
[% javascript_urls.push('extensions/Review/web/js/review.js') %]

[% IF bug %]
  [%# create attachment %]
  [% mentors = bug.mentors( exclude_review_blocked => 1 ) %]
  [% product_obj = bug.product_obj %]
  [% component_obj = bug.component_obj %]
[% ELSIF attachment.bug %]
  [%# edit attachment %]
  [% mentors = attachment.bug.mentors( exclude_review_blocked => 1 ) %]
  [% product_obj = attachment.bug.product_obj %]
  [% component_obj = attachment.bug.component_obj %]
[% ELSE %]
  [%# create bug %]
  [% mentors = [] %]
  [% product_obj = product %]
  [% component_obj = 0 %]
[% END %]

[% review_js = BLOCK %]
  review_suggestions = {
    _mentors: [
      [% FOREACH u = mentors %]
        [% NEXT IF NOT u.is_active %]
        [% NEXT IF u.id == user.id %]
        [% PROCESS reviewer %][% "," UNLESS loop.last %]
      [% END %]
    ],

    [% IF product_obj.reviewers %]
      _product: [
        [% FOREACH u = product_obj.reviewers_objs %]
          [% NEXT IF u.id == user.id %]
          [% PROCESS reviewer %][% "," UNLESS loop.last %]
        [% END %]
      ],
    [% END %]

    [% IF component_obj %]
      [%# single component (create/edit attachment) %]
      '[% component_obj.name FILTER js %]': [
        [% FOREACH u = component_obj.reviewers_objs %]
          [% NEXT IF u.id == user.id %]
          [% PROCESS reviewer %][% "," UNLESS loop.last %]
        [% END %]
      ],
    [% ELSE %]
      [%# all components (create bug) %]
      [% FOREACH comp = product_obj.components %]
        [% NEXT UNLESS comp.reviewers %]
        '[% comp.name FILTER js %]': [
          [% FOREACH u = comp.reviewers_objs %]
            [% NEXT IF u.id == user.id %]
            [% PROCESS reviewer %][% "," UNLESS loop.last %]
          [% END %]
        ],
      [% END %]
    [% END %]

    [%# to keep IE happy, no trailing commas %]
    _end: 1
  };

  [% IF component_obj %]
    static_component = '[% component_obj.name FILTER js %]';
  [% ELSE %]
    static_component = false;
  [% END %]
[% END %]
[% javascript = javascript _ review_js %]

[% BLOCK reviewer %]
  { login: '[% u.login FILTER js%]', identity: '[% u.identity FILTER js %]', review_count: [% u.review_count FILTER js %] }
[% END %]
