[%# 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>
  #                 Vaskin Kissoyan <vkissoyan@yahoo.com>
  #                 Vitaly Harisov <vitaly@rathedg.com>
  #                 Svetlana Harisova <light@rathedg.com>
  #                 Kohei Yoshino <kohei.yoshino@gmail.com>
  #%]

[%# INTERFACE:
  # (All the below interface elements are optional.)
  # title: string. Page title.
  # header: string. Main page header.
  # subheader: string. Page subheader.
  # bodyclasses: array of extra CSS classes for the <body>
  # onload: string. JavaScript code to run when the page finishes loading.
  # javascript: string. JavaScript to go in the header.
  # javascript_urls: list. List of URLs to JavaScript.
  # style: string. CSS style.
  # style_urls: list. List of URLs to CSS style sheets.
  # message: string. A message to display to the user. May contain HTML.
  # atomlink: Atom link URL, May contain HTML
  # generate_api_token: generate a token which can be used to make authenticated webservice calls
  # no_body: if true the body element will not be generated
  # allow_mobile: allow special CSS and viewport for detected mobile user agents
  # use_login_page: display a link to the full login page, rather than an inline login.
  # robots: index / noindex (default: index)
  #%]

[% IF message %]
  [% PROCESS global/messages.html.tmpl %]
[% END %]

[% DEFAULT
  subheader = ""
  onload = ""
  javascript_urls = []
  style_urls = []
  no_yui = 0
  jquery = []
  jquery_css = []
  generate_api_token = 1
  robots = 'index'
%]

[%# These are JS URLs that are *always* on the page and come before
  # every other JS URL.
  #%]
[% SET starting_js_urls = [
  "js/jquery/jquery-min.js",
  "js/jquery/ui/jquery-ui-min.js"
] %]

[% IF NOT no_yui %]
  [% starting_js_urls.push("js/yui.js") %]
[% END %]

[% SET jq_css_urls = [
  "js/jquery/ui/jquery-ui-min.css",
  "js/jquery/ui/jquery-ui-structure-min.css",
  "js/jquery/ui/jquery-ui-theme-min.css",
] %]
[% style_urls.import(jquery_css, jq_css_urls) FILTER null %]

[%# Add our required jQuery plugins %]
[% jquery.push("devbridgeAutocomplete") %]

[% IF allow_mobile && is_mobile_browser %]
  [% style_urls.push("skins/standard/mobile.css") %]
[% END %]

[%# Enable syntax highlighting with Prism.js %]
[% javascript_urls.push('js/lib/prism.js') %]
[% style_urls.push('skins/lib/prism.css') %]

[%# We should be able to set the default value of the header variable
  # to the value of the title variable using the DEFAULT directive,
  # but that doesn't work if a caller sets header to the empty string
  # to avoid header inheriting the value of title, since DEFAULT
  # mistakenly treats empty strings as undefined and gives header the
  # value of title anyway.  To get around that problem we explicitly
  # set header's default value here only if it is undefined. %]
[% IF !header.defined %][% header = title %][% END %]
<!DOCTYPE html>
<html lang="en">
  <head>
    [% IF Param('utf8') %]
      <meta charset="UTF-8">
    [% END %]
    [% IF meta_refresh %]
      <meta http-equiv="refresh"
        content="[% meta_refresh FILTER html %]">
    [% END %]
    [% USE Bugzilla %]

    [%- js_BUGZILLA = {
            config => {
                basepath => basepath,
            }
            user => {
                # TODO: Move all properties form bug_modal/header.html.tmpl
                login => user.login,
            },
            param => {
                maxattachmentsize => Param('maxattachmentsize'),
                maxusermatches => Param('maxusermatches'),
                splinter_base => Param('splinter_base'),
            },
            constant => {
                COMMENT_COLS => constants.COMMENT_COLS,
            },
            string => {
                # Please keep these in alphabetical order.
                bug_type_required =>
                    "You must select a Type for this $terms.bug",
                component_required =>
                    "You must select a Component for this $terms.bug",
                description_required =>
                    "You must enter a Description for this $terms.bug",
                short_desc_required =>
                    "You must enter a Summary for this $terms.bug",
                version_required =>
                    "You must select a Version for this $terms.bug"
            }
        };
    %]
    [% Hook.process("start") %]
    [%
       IF generate_api_token;
        js_BUGZILLA.api_token = get_api_token();
       END;
    %]

    <meta name="viewport" content="width=1024">
    <meta name="color-scheme" content="dark light">
    <meta name="generator" content="[% terms.Bugzilla _ " " _ constants.BUGZILLA_VERSION FILTER html %]">
    <meta name="bugzilla-global" content="dummy"
        id="bugzilla-global" data-bugzilla="[% json_encode(js_BUGZILLA) FILTER html %]">
    <title>[% title %]</title>

    [% IF robots == "noindex" %]
      <meta name="robots" content="noindex">
    [% END %]

    [% PROCESS "global/site-navigation.html.tmpl" %]

    [% PROCESS 'global/setting-descs.none.tmpl' %]

    [% SET css_sets = css_files(style_urls.unique, no_yui) %]
    [% FOREACH asset_url = css_sets.standard %]
      [% PROCESS format_css_link %]
    [% END %]
    [% FOREACH asset_url = css_sets.skin %]
      [% PROCESS format_css_link %]
    [% END %]

    [% IF style %]
      <style>
        [% style %]
      </style>
    [% END %]

    [% FOREACH asset_url = css_sets.custom %]
      [% PROCESS format_css_link %]
    [% END %]

    [%# jQuery Plugins %]
    [% FOREACH jq_name = jquery.unique %]
      [% starting_js_urls.push("js/jquery/plugins/$jq_name/${jq_name}-min.js") %]
    [% END %]
    [% starting_js_urls.push('js/global.js', 'js/util.js', 'js/dropdown.js') %]

    [% FOREACH asset_url = starting_js_urls %]
      [% PROCESS format_js_link %]
    [% END %]

    [% inline_javascript = BLOCK %]
        [% IF NOT no_yui %]
          YAHOO.namespace('bugzilla');
          if ( "onpagehide" in window || YAHOO.env.ua.gecko) {
              YAHOO.util.Event._simpleRemove(window, "unload",
                                             YAHOO.util.Event._unload);
          }
          [% INCLUDE 'global/value-descs.js.tmpl' %]
        [% END %]

        [% IF javascript %]
          [% javascript %]
        [% END %]
    [% END %]
    [% IF inline_javascript.search("\\S") %]
      <script [% script_nonce FILTER none %]>
        [% inline_javascript FILTER none %]
      </script>
    [% END %]

    [% FOREACH asset_url = javascript_urls %]
      [% PROCESS format_js_link %]
    [% END %]

    [%# this puts the live bookmark up on Firefox for the Atom feed %]
    [% IF atomlink %]
       <link rel="alternate"
             type="application/atom+xml" title="Atom feed"
             href="[% atomlink FILTER html %]">
    [% END %]

    [%# Required for the 'Auto-discovery' feature in Firefox 2 and IE 7. %]
    <link rel="search" type="application/opensearchdescription+xml"
                       title="[% terms.BugzillaTitle %]" href="[% basepath FILTER none %]search_plugin.cgi">
    [% IF allow_mobile && is_mobile_browser %]
      <meta name="viewport" content="width=device-width, initial-scale=1">
    [% END %]
    [% Hook.process("additional_header") %]
  </head>

[% RETURN IF no_body %]

[%# Migration note: contents of the old Param 'bodyhtml' go in the body tag,
  # but set the onload attribute in the DEFAULT directive above.
  #%]
  [% IF onload %]
  <script [% script_nonce FILTER none %]>
  $(function() { [% onload %] });
  </script>
  [% END %]
  <body
        class="[% urlbase.replace('^https?://','').replace('/$','').replace('[-~@:/.]+','-') FILTER css_class_quote %]
               skin-[% user.settings.skin.value FILTER css_class_quote %]
               [% IF Bugzilla.request_cache.mfa_warning %]
                mfa-warning
               [% END %]
               [% FOREACH class = bodyclasses %]
                 [% ' ' %][% class FILTER css_class_quote %]
               [% END %] yui-skin-sam">

[%# Migration note: the following file corresponds to the old Param
  # 'bannerhtml'
  #%]

<div id="wrapper">

<aside id="message-container" role="complementary">
  <noscript>
    <div class="noscript">
      <div class="inner">
        <p>Please enable JavaScript in your browser to use all the features on this site.</p>
      </div>
    </div>
  </noscript>
  [% IF Bugzilla.request_cache.mfa_warning
        AND user.mfa_required_date
        AND NOT Bugzilla.request_cache.on_mfa_page %]
    <div class="warning">
      <div class="inner">
        <p>
          Please <a href="[% basepath FILTER none %]userprefs.cgi?tab=mfa">enable two-factor authentication</a>
          [% IF Param('mfa_group_grace_period') %]
            before <i>[% user.mfa_required_date FILTER time %]</i>.
          [% ELSE %]
            now.
          [% END %]
        </p>
      </div>
    </div>
  [% END %]
  [% announcehtml = Param('announcehtml') %]
  [% checksum     = md5(announcehtml) %]
  [% IF announcehtml AND c.session.announcement_checksum != checksum %]
    <div id="new_announcement" class="new_announcement" data-checksum="[% checksum FILTER html %]">
      <div class="inner">
        [% announcehtml FILTER none %]
      </div>
    </div>
  [% END %]
</aside>

<header id="header" role="banner">
  <div class="inner">
    <h1 id="header-title" class="title"><a href="[% c.url_for('/home').to_abs FILTER html %]" title="Go to home page">[% terms.Bugzilla %]</a></h1>
    <form role="search" id="header-search" class="quicksearch" action="[% basepath FILTER none %]buglist.cgi" data-no-csrf>
      <section class="searchbox-outer dropdown" role="combobox" aria-expanded="false" aria-haspopup="listbox"
               aria-labelledby="header-search-label" aria-owns="header-search-dropdown">
        <h2 id="header-search-label">Quick Search</h2>
        <span class="icon" aria-hidden="true"></span>
        <input role="searchbox" id="quicksearch_top" class="dropdown-button" name="quicksearch" autocomplete="off"
               value="[% quicksearch FILTER html %]" placeholder="Search [% terms.Bugs %]"
               title="Enter a [% terms.bug %] number or some search terms" aria-controls="header-search-dropdown"
               aria-labelledby="header-search-label">
        [% PROCESS "global/header-search-dropdown.html.tmpl" %]
      </section>
    </form>
    <nav id="header-nav">
      <ul class="links">
        <li class="link-browse">
          <a href="[% basepath FILTER none %]describecomponents.cgi" title="Browse [% terms.bugs %] by component">
            <span class="icon" aria-hidden="true"></span>
            <span class="label">Browse</span>
          </a>
        </li>
        <li class="link-search">
          <a href="[% basepath FILTER none %]query.cgi?format=advanced" title="Search [% terms.bugs %] using various criteria">
            <span class="icon" aria-hidden="true"></span>
            <span class="label">Advanced Search</span>
          </a>
        </li>
        [% IF user.id %]
          <li class="link-file">
            <a href="[% basepath FILTER none %]enter_bug.cgi" title="File a new [% terms.bug %]">
              <span class="icon" aria-hidden="true"></span>
              <span class="label">New [% terms.Bug %]</span>
            </a>
          </li>
        [% END %]
        [% Hook.process('action-links') %]
      </ul>
      <div class="dropdown">
        <button type="button" id="header-tools-menu-button" class="dropdown-button minor" title="More tools…"
                aria-label="More tools…" aria-expanded="false" aria-haspopup="true" aria-controls="header-tools-menu">
          <span class="icon" aria-hidden="true"></span>
        </button>
        <ul class="dropdown-content left" id="header-tools-menu" role="menu" style="display:none;">
          [% IF user.id %]
            <li role="presentation">
              <a href="[% basepath FILTER none %]request.cgi?requester=[% user.login FILTER uri %]&amp;requestee=[% user.login FILTER uri %]&amp;do_union=1&amp;group=type&amp;action=queue" role="menuitem" tabindex="-1">My Requests</a>
            </li>
          [% END %]
          <li role="presentation">
            <a href="[% basepath FILTER none %]report.cgi" role="menuitem" tabindex="-1">Reports</a>
          </li>
          [% IF user.in_group('tweakparams') || user.in_group('editusers') || user.can_bless || user.in_group('disableusers')
                || (Param('useclassification') && user.in_group('editclassifications'))
                || user.in_group('editcomponents') || user.in_group('admin') || user.in_group('creategroups')
                || user.in_group('editkeywords') || user.in_group('bz_canusewhines')
                || user.get_products_by_permission("editcomponents").size %]
            <li role="presentation">
              <a href="[% basepath FILTER none %]admin.cgi" role="menuitem" tabindex="-1">Administration</a>
            </li>
          [% END %]
          [% IF Param('docs_urlbase') %]
            <li role="separator"></li>
            <li role="presentation">
              <a href="[% docs_urlbase FILTER html %]" role="menuitem" tabindex="-1">Documentation</a>
            </li>
          [% END %]
        </ul>
      </div>
    </nav>
    [% Hook.process("badge") %]
    [% IF user.id %]
      <div id="header-account" class="dropdown">
        <button type="button" id="header-account-menu-button" class="dropdown-button minor" title="Account"
                aria-label="Account" aria-expanded="false" aria-haspopup="true" aria-controls="header-account-menu">
          [% IF user.gravatar %]
            <img src="[% user.gravatar FILTER html %]" width="32" height="32" alt="">
          [% ELSE %]
            <span class="icon" aria-hidden="true"></span>
          [% END %]
        </button>
        <ul class="dropdown-content left" id="header-account-menu" role="menu" style="display:none;">
          <li role="presentation">
            <div class="account-label">
              <div class="name">[% user.name FILTER html %]</div>
              <div class="email">[% user.login FILTER html %]</div>
            </div>
          </li>
          <li role="separator"></li>
          <li role="presentation">
            <a href="[% basepath FILTER none %]user_profile?user_id=[% user.id FILTER none %]" role="menuitem" tabindex="-1">My Profile</a>
          </li>
          <li role="presentation">
            <a href="[% basepath FILTER none %]page.cgi?id=user_activity.html&amp;action=run&amp;who=[% user.login FILTER uri %]" role="menuitem"
               tabindex="-1">My Activity</a>
          </li>
          <li role="presentation">
            <a href="[% basepath FILTER none %]userprefs.cgi" role="menuitem" tabindex="-1">Preferences</a>
          </li>
          <li role="separator"></li>
          <li role="presentation">
            <a href="[% basepath FILTER none %]index.cgi?logout=1" role="menuitem" tabindex="-1">Log out</a>
          </li>
          [% IF sudoer %]
            <li role="presentation">
              <a href="[% basepath FILTER none %]relogin.cgi?action=end-sudo" role="menuitem" tabindex="-1">End sudo session impersonating [% user.login FILTER html %]</a>
            </li>
          [% END %]
        </ul>
      </div>
    [% ELSE %]
      <ul id="header-login" class="links">
          [% PROCESS "account/auth/signup-small.html.tmpl" qs_suffix = "_top" %]
        [% IF user.authorizer.can_login %]
          [% PROCESS "account/auth/login-small.html.tmpl" qs_suffix = "_top" use_login_page = use_login_page %]
        [% END %]
      </ul>
    [% END %]
    [% Hook.process('external-links') %]
  </div>
</header> [%# header %]

[%
  IF bug && bug.groups_in.size;
    is_security_bug = 0;
    FOREACH group IN bug.groups_in;
      is_security_bug = 1 IF group.secure_mail;
    END;
%]
  <div id="private-bug-banner" class="[% IF is_security_bug %]security[% ELSE %]confidential[% END %]">
    <span class="icon" aria-hidden="true"></span>
    <strong>
      [% IF is_security_bug %]
        Security Issue - <a href="https://firefox-source-docs.mozilla.org/bug-mgmt/processes/security-approval.html">
        Approval Process</a>
      [% ELSE %]
        Confidential
      [% END %]
    </strong>
  </div>
[% END %]

<main id="bugzilla-body" tabindex="-1">
<div id="main-inner">

[%# in most cases the "header" variable provides redundant information, however
  # there are exceptions where not displaying this text is problematic. %]
[% IF template.name.match('^attachment/')
      && !header.match('^Bug&nbsp;\d+$') %]
  <h2>[% header FILTER none %]</h2>
[% END %]

[%# Show banner for users who have email disabled due to bounces %]
[% IF user.bounce_count AND user.email_disabled %]
  <div id="message">
    Change notification emails have been disabled for your account due to issues delivering to your address.
    <a href="/bounced_emails/[% user.id FILTER uri %]" id="bounced_emails_link">View recent errors and reactivate email</a>.
  </div>
[% END %]

[% IF message %]
  <div id="message">[% message %]</div>
[% END %]

[% BLOCK format_css_link %]
  <link href="[% asset_url FILTER html %]" rel="stylesheet" type="text/css">
  [% "\n" %]
[% END %]

[% BLOCK format_js_link %]
  <script [% script_nonce FILTER none %] src="[% asset_url FILTER version FILTER html %]"></script>
  [% "\n" %]
[% END %]
