[%# 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/variables.none.tmpl;
  USE Bugzilla;

  # <title>
  IF bugs.defined;
    bug = bugs.0;
  END;
  title = "$bug.bug_id - ";
  IF bug.alias;
    filtered_alias = bug.alias FILTER html;
    title = title _ "($filtered_alias) ";
  END;
  unfiltered_title = title _ bug.short_desc;
  filtered_desc = bug.short_desc FILTER html;
  title = title _ filtered_desc;

  generate_api_token = 1;

  # these aren't always defined
  UNLESS bodyclasses.defined;
    bodyclasses = [];
  END;
  UNLESS javascript_urls.defined;
    javascript_urls = [];
  END;
  UNLESS style_urls.defined;
    style_urls = [];
  END;
  UNLESS jquery.defined;
    jquery = [];
  END;

  # right now we need yui for tracking flags and needinfo extensions
  no_yui = 0;

  # add body classes for sec-groups, etc
  FOREACH group IN bug.groups_in;
    bodyclasses.push("bz_group_$group.name");
  END;
  bodyclasses.push("bug_modal");

  # assets
  javascript_urls.push(
    "extensions/BugModal/web/autosize.min.js",
    "extensions/ProdCompSearch/web/js/prod_comp_search.js",
    "extensions/BugModal/web/bug_modal.js",
    "extensions/BugModal/web/comments.js",
    "extensions/ComponentWatching/web/js/overlay.js",
    "js/bugzilla-readable-status-min.js",
    "js/field.js",
    "js/comments.js"
  );
  jquery.push(
    "contextMenu",
  );
  style_urls.push(
    "extensions/BugModal/web/bug_modal.css",
    "js/jquery/plugins/contextMenu/contextMenu.css"
  );
%]

[% javascript = BLOCK %]
  [%# add tracking flags JSON if available %]
  [% IF tracking_flags %]
    [% javascript_urls.push("extensions/TrackingFlags/web/js/flags.js") %]
    var tracking_flags_str = "[% tracking_flags_json FILTER js %]";
    var TrackingFlags = $.parseJSON(tracking_flags_str);
  [% END %]

  [%# update last-visited %]
  [% IF user.id %]
    document.addEventListener('DOMContentLoaded', () => show_new_changes_indicator(), { once: true });
  [% END %]

  [%# expose useful data to js %]
  BUGZILLA.bug_id = [% bug.id FILTER none %];
  BUGZILLA.bug_title = '[% unfiltered_title FILTER js %]';
  BUGZILLA.bug_summary = '[% bug.short_desc FILTER js %]';
  BUGZILLA.bug_url = '[% Bugzilla.localconfig.canonical_urlbase _ "show_bug.cgi?id=" _ bug.id FILTER js %]';
  BUGZILLA.bug_keywords = '[% bug.keywords FILTER js %]',
  BUGZILLA.user = {
    id: [% user.id FILTER none %],
    login: '[% user.login FILTER js %]',
    is_insider: [% user.is_insider ? "true" : "false" %],
    is_timetracker: [% user.is_timetracker ? "true" : "false" %],
    can_tag: [% user.can_tag_comments ? "true" : "false" %],
    timezone: '[% user.timezone.name FILTER js %]',
    settings: {
      quote_replies: '[% user.settings.quote_replies.value FILTER js %]',
      zoom_textareas: [% user.settings.zoom_textareas.value == "on" ? "true" : "false" %],
      remember_collapsed: [% user.settings.ui_remember_collapsed.value == "on" ? "true" : "false" %],
      inline_attachments: [% user.settings.inline_attachments.value == "on" ? "true" : "false" %],
      autosize_comments: [% user.settings.autosize_comments.value == "on" ? "true" : "false" %]
    }
  };
  [% IF user.id %]
    BUGZILLA.default_assignee   = '[% bug.component_obj.default_assignee.login FILTER js %]';
    BUGZILLA.default_qa_contact = '[% bug.component_obj.default_qa_contact.login FILTER js %]';
    BUGZILLA.constant.min_comment_tag_length = [% constants.MIN_COMMENT_TAG_LENGTH FILTER none %];
    BUGZILLA.constant.max_comment_tag_length = [% constants.MAX_COMMENT_TAG_LENGTH FILTER none %];
  [% END %]

  [% IF user.is_timetracker %]
    BUGZILLA.remaining_time = [% bug.remaining_time FILTER js %]; // holds the original value
  [% END %]
  BUGZILLA.bug_secure = [% bug.groups_in.size ? 'true' : 'false' %];
[% END %]

[% Hook.process("end") %]
