<!-- Header Details -->
{% from "macros.html" import orcid_url, image %}
<header>
  {% block header %}
    <div class="lead banner"
         style="background-image:url({{url_for('static', filename='images/banner.svg')}}); background-position: right top; background-size: auto 127px; background-repeat: no-repeat; height: 127px; background-color: #000;">
    </div>
  {% endblock %}

  <nav class="navbar navbar-default">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                                                              data-target="#navbar-collapse-1" aria-expanded="false">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
      </div>
      <div class="collapse navbar-collapse" id="navbar-collapse-1">
        <ul class="nav navbar-nav">
          <li id="login"><a href="{{ url_for('index') }}">
              <span data-toggle="tooltip"
                    data-placement="bottom"
                    title="Home" class="fa fa-home glyphicon glyphicon-home"
                                 style="font-size: large;" aria-hidden="true"></span></a></li>
          <li id="about"><a href="{{ url_for('about') }}">
              <span data-toggle="tooltip"
                    data-placement="bottom" title="About the Hub">About</span>
          </a></li>
          <li id="faq"><a href="{{ url_for('faq') }}">
              <span data-toggle="tooltip"
                    data-placement="bottom" title="The Hub's Frequently Asked Questions">FAQ</span>
          </a></li>
          {% if current_user.confirmed %}
            {% if current_user.org_links|length > 1 %}
              <li>
                <p class="navbar-btn">
                <select class="selectpicker"
                        data-style="btn-primary" id="select-org"
                                                 title="Current Organisation"
                                                 onchange='location.href="/select/user_org/"+this.value'>
                  {% for ol in current_user.org_links %}
                    <option data-tokens="{{ol.id}}" value="{{ol.id}}" {{"selected" if current_user.organisation.id == ol.org_id else ''}}>{{ol.org_name}}</option>
                  {% endfor %}
                </select>
                </p>
              </li>
            {% endif %}
            {% if current_user.organisation.confirmed %}
              <li id="profile"><a href="{{ url_for('link') }}">
                  <span
                                  data-toggle="tooltip" data-placement="bottom"
                                                        title="View/give your ORCID permission(s) via the Hub">Your ORCID</span></a></li>
              {% if current_user.has_role("ADMIN") %}
                <li class="dropdown">
                  <a class="dropdown-toggle" data-toggle="dropdown" href="#">Your People<span class="caret"></span></a>
                  <ul class="dropdown-menu">
                   <li id="viewmembers.index_view"><a href="{{ url_for('viewmembers.index_view')}}">
                      <span data-toggle="tooltip" data-placement="bottom" title="ORCID iDs/emails of all people linked with your organisation in the Hub">
                        View/Export People
                      </span></a>
                    </li>
                    <li id="invite_user"><a href="{{ url_for('invite_user') }}" data-toggle="tooltip"
                                                                                title="Send an invitation to a new student/staff member">New Student/Staff Invitation</a></li>
                  </ul>
                </li>
                <li class="dropdown">
                  <a class="dropdown-toggle" data-toggle="dropdown" href="#">Tasks<span class="caret"></span></a>
                  <ul class="dropdown-menu">
                    <li id="load_researcher_affiliations"><a href="{{ url_for('load_researcher_affiliations')}}" data-toggle="tooltip"
                                                                                                                 title="Import an affiliations batch file">Upload Affiliations</a></li>
                    <li id="load_researcher_funding"><a href="{{ url_for('load_researcher_funding')}}" data-toggle="tooltip"
                                                                                                       title="Import a funding batch file">Upload Funding</a></li>
                    <li id="load_researcher_works"><a href="{{ url_for('load_researcher_work')}}" data-toggle="tooltip"
                                                                                                       title="Import a works batch file">Upload Works</a></li>
                    <li id="load_peer_review"><a href="{{ url_for('load_researcher_peer_review')}}"  data-toggle="tooltip"
                                                                                        title="Import a peer reviews batch file">Upload Peer Reviews</a></li>
                    <li id="load_researcher_urls"><a href="{{ url_for('load_researcher_urls')}}"  data-toggle="tooltip"
                                                                    title="Import a researcher urls batch file">Upload Researcher Urls</a></li>
                    <li id="load_other_names"><a href="{{ url_for('load_other_names')}}"  data-toggle="tooltip"
                                                                    title="Import researcher other names batch file">Upload Researcher Other Names</a></li>
                    <li id="load_keyword"><a href="{{ url_for('load_keyword')}}"  data-toggle="tooltip"
                                                                                        title="Import researcher keyword batch file">Upload Researcher Keyword</a></li>
                    <li id="load_country"><a href="{{ url_for('load_country')}}"  data-toggle="tooltip"
                                                                                        title="Import researcher Country batch file">Upload Researcher Country</a></li>
                    <li id="load_other_ids"><a href="{{ url_for('load_other_ids')}}"  data-toggle="tooltip"
                                                                                        title="Import researcher Other IDs batch file">Upload Researcher Other IDs</a></li>
                    <li class="divider"></li>
                    <li id="sync_profiles"><a href="{{ url_for('sync_profiles')}}"  data-toggle="tooltip"
                                                                                        title="Synchronize researcher porfiles">Sync Profiles</a></li>
                    <li class="divider"></li>
                    <li id="task.index_view"><a href="{{ url_for('task.index_view')}}"  data-toggle="tooltip"
                                                                                        title="Review the progress and results of your current batch tasks">Uploaded Tasks</a></li>
                  </ul>
                </li>
              {% endif %}
            {% endif %}
            {% if current_user.is_tech_contact_of() or current_user.is_admin_of() %}
              <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">Settings
                  <span class="caret"></span></a>
                <ul class="dropdown-menu">
                  {% if current_user.is_tech_contact_of() %}
                    <li id="onboard_org"><a href="{{ url_for('onboard_org')}}">
                        <span data-toggle="tooltip" title="View/get your organisation's ORCID information">Your Organisation</span></a></li>


                    {% if current_user.organisation.can_use_api %}
                      <li id="application"><a data-toggle="tooltip" title="Register/manage Hub API client credentials" href="{{ url_for('application')}}">Hub API Registration</a></li>
                    {% endif %}
                  {% endif %}
                  <li class="dropdown-submenu">
                    <a class="dropdown-toggle" tabindex="-1" href="#">Customize Email<!-- span class="caret"></span --></a>
                    <ul class="dropdown-menu">

                      <li id="logo"><a href="{{ url_for('logo')}}">
                          <span data-toggle="tooltip" title="Upload your organisation's logo">Logo</span></a></li>
                      <li id="manage_email_template"><a href="{{ url_for('manage_email_template')}}">
                          <span data-toggle="tooltip" title="Customize email template with desired look and content">Template</span></a></li>
                    </ul>
                  </li>
                  <li id="groupidrecord.index_view"><a href="{{ url_for('groupidrecord.index_view')}}"  data-toggle="tooltip"
                                                                                    title="Create/update group id records for peer review">Manage GroupId Records</a></li>
                  {% if current_user.is_tech_contact_of() %}
                    <li id="org_webhook"><a href="{{ url_for('org_webhook')}}">
                        <span data-toggle="tooltip" title="Activate ORCID webhooks for your organisation">Set Webhooks</span></a></li>
                  {% endif %}
                </ul>
              </li>
            {% endif %}
            {% if current_user.has_role("SUPERUSER") %}
              <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">Hub Admin
                  <span class="caret"></span></a>
                <ul class="dropdown-menu">
                  <li id="user.index_view"><a data-toggle="tooltip" title="User roles" href="{{ url_for('user.index_view')}}">Users</a></li>
                  <li id="orcidtoken.index_view"><a data-toggle="tooltip" title="ORCID access tokens" href="{{ url_for('orcidtoken.index_view')}}">ORCID Tokens</a></li>
                  <li class="divider"></li>
                  <li id="registerOrganisation"><a href="{{ url_for('invite_organisation') }}">
                    <span data-toggle="tooltip" title="Send a Tech Contact/Org Admin invitation or replace the existing Technical Contact of an organisation.">Onboard Organisation</span></a>
                  </li>
                  <li id="organisation.index_view"><a data-toggle="tooltip" title="Onboarded organisations" href="{{ url_for('organisation.index_view')}}">Active Organisations</a>
                  </li>
                  <li class="dropdown-submenu">
                    <a class="dropdown-toggle" tabindex="-1" href="#">Organisation Setup<!-- span class="caret"></span --></a>
                    <ul class="dropdown-menu">
                      <li id="load_org"><a data-toggle="tooltip" title="Bulk import organisation data for onboarding" href="{{ url_for('load_org')}}">Upload Organisation Data</a></li>
                      <li id="orginfo.index_view"><a data-toggle="tooltip" title="Create/view/edit organisation data" href="{{ url_for('orginfo.index_view')}}">Manage Organisation
                          Data</a></li>
                    </ul>
                  </li>
                  <li class="divider"></li>
                  <li class="dropdown-submenu">
                    <a class="dropdown-toggle" tabindex="-1" href="#">Reports<!-- span class="caret"></span --></a>
                    <ul class="dropdown-menu">
                      <li id="user_summary"><a data-toggle="tooltip" title="User Summary" href="{{ url_for('user_summary')}}">Users</a></li>
                      <li id="org_invitation_summary"><a data-toggle="tooltip" title="Summary of organisation contact invitations" href="{{ url_for('org_invitation_summary')}}">Organisation Invitations</a></li>
                      <li id="user_invitation_summary"><a data-toggle="tooltip" title="Summary of user invitations" href="{{ url_for('user_invitation_summary')}}">User Invitations</a></li>
                    </ul>
                  </li>
                  {%- if config.REDIS_URL %}
                            <li class="divider"></li>
                            <li id="rq_dashboard.overview"><a data-toggle="tooltip" data-placement="left" title="Message Queues" href="{{ url_for('rq_dashboard.overview', url=request.url)}}">Message Queues</a></li>
                            <li id="schedude.index_view"><a data-toggle="tooltip" data-placement="left" title="Scheduled Jobs" href="{{ url_for('schedude.index_view') }}">Scheduled Jobs</a></li>
                  {% endif -%}
                  <li id="userinvitation.index_view"><a data-toggle="tooltip" title="The User Invitations recently sent." href="{{ url_for('userinvitation.index_view')}}">User Invitations</a></li>
                  <li id="orginvitation.index_view"><a data-toggle="tooltip" title="The Organisation On-boarding Invitations recently sent." href="{{ url_for('orginvitation.index_view')}}">Organisation Invitations</a></li>
                  {% if has_audit_logs() %}
                  <li class="divider"></li>
                  <li class="dropdown-submenu">
                    <a class="dropdown-toggle" tabindex="-1" href="#">Audit Logs<!-- span class="caret"></span --></a>
                    <ul class="dropdown-menu">
                      <li id="organisation_log.index_view"><a data-toggle="tooltip" title="Organisation Audit Log" href="{{ url_for('organisation_log.index_view')}}">Organisations</a></li>
                      <li id="user_log.index_view"><a data-toggle="tooltip" title="User Audit Log" href="{{ url_for('user_log.index_view')}}">Users</a></li>
                      <li id="task_log.index_view"><a data-toggle="tooltip" title="Task Audit Log" href="{{ url_for('task_log.index_view')}}">Tasks</a></li>
                    </ul>
                  </li>
                  {% endif %}
                </ul>
              </li>
            {% endif %}
          {% endif %}
        </ul>
        <ul class="nav navbar-nav navbar-right">
          {% if current_user.confirmed %}
            <li>{{orcid_url(current_user)}}</li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <img alt="GRAVATAR" src="{{ current_user.avatar(20) }}">
                <strong>{{ current_user.name }}</strong>
                <span class="glyphicon glyphicon-chevron-down"></span>
              </a>
              <ul class="dropdown-menu">
                <li>
                  <div class="navbar-login">
                    <div class="row">
                      <div class="col-lg-4">
                        <p class="text-center">
                        <!-- span class="glyphicon glyphicon-user icon-size"></span -->
                        <a href={{current_user.gravatar_profile_url}}>
                          <img alt="GRAVATAR100" src="{{ current_user.avatar(100) }}">
                        </a>
                        </p>
                      </div>
                      <div class="col-lg-8">
                        <p class="text-left"><strong>{{ current_user.name }}</strong></p>
                        <p class="text-left small">{{ current_user.email }}</p>
                        <p class="text-left small">Edu Person Affiliation:
                        {{ current_user.affiliations }}</p>
                        <p class="text-left">
                        {% if current_user.organisation.confirmed %}
                          <a href="{{url_for('profile')}}"
                             class="btn btn-primary btn-block btn-sm">Profile</a>
                          {% if current_user.orcid %}
                            <form class="icon" method="POST" action="{{url_for('remove_linkage')}}">
                            <button onclick="return safeConfirm('Are you sure you want to remove the ORCID ID and token associated with this account?\n\nBy clicking &quot;OK&quot;'+
                            ' we will remove the access token given to this organisation! \n\n You may not be able to login again because you are deleting your associated ORCiD iD!');"
                              data-toggle="tooltip"
                              data-placement="bottom"
                              title="Remove Erroneous Linkage..."
                              class="btn btn-danger">Remove ORCID Linkage</button> <br>
                            </form>
                          {% endif %}
                        {% endif %}
                        </p>
                      </div>
                    </div>
                  </div>
                </li>
              </ul>
            </li>
            <li><a href="{{url_for('logout')}}"><span class="glyphicon glyphicon-log-out"></span> log out</a>
            </li>
          {% else %}
            <li>
              {% if config.SHIBBOLETH_DISABLED %}
                <a href="{{orcid_login_url()|safe}}">
                  <button id="connect-orcid-button">
                    <img id="orcid-id-icon" src="https://orcid.org/sites/default/files/images/orcid_24x24.png" width="24" height="24" alt="ORCID iD icon"/>Register or Connect your ORCID iD
                  </button>
                </a>
              {% else %}
              <a href="#login-modal" data-toggle="modal">
                <span class="glyphicon glyphicon-log-in"></span> <b>log in</b>
              </a>
              <div class="modal fade" id="login-modal" role="dialog">
                <div class="modal-dialog">
                  <div class="modal-content">
                    <div class="modal-header">
                      <span id="modal-title" class="modal-title"><b>Log in using your:</b></span>
                      <span class="pull-right">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                      </span>
                    </div>
                    <div class="modal-body" style="padding: 0px 30px 0px 30px;">
                      <div class="row">
                        <div class="col-md-6" style="border-right: 1px solid #ddd">
                          <h3 class="text-center">Institutional credentials</h3>
                          <img class="center-block" alt="Login via Tuakiri" src="{{image('REANNZ_Tuakiri_service.png')}}" style="width:50%">
                          <br/>
                          <p>I'm currently employed by, or studying, with a <a href="#" data-toggle="tooltip"
                                                                                        title="Tuakiri-members are all Universities and Crown Research Institutes (with the exception of GNS)">
                            Tuakiri-member organisation</a></p>
                          <a href="{{tuakiri_login_url()|safe}}">
                            <div class="tuakiri">
                              <div class="btn btn-primary center-block">Login&nbsp;via&nbsp;Tuakiri</div>
                            </div>
                          </a>
                          <p></p>
                          <p><small>This log in takes you to the Tuakiri Directory Service where you can select your Home Organisation.
                            Once returned to the Hub, you'll be able to give your organisation permission to write your affiliation to your ORCID record</small></p>
                        </div>
                        <div class="col-md-6 center-block">
                          <h3 class="text-center">ORCID record</h3>
                          <img class="center-block" alt="Login via Orcid" src="{{image('orcid-logo.png')}}" style="width:50%">
                          <br/>
                          <p>I'm the Tech Contact or Administrator for a Non-Tuakiri member organsation</p>
                          <a href="{{orcid_login_url()|safe}}">
                            <div class="orcid">
                              <div class="btn btn-primary center-block">Login&nbsp;via&nbsp;ORCID</div>
                            </div>
                          </a>
                          <p></p>
                          <p><small>This log in takes you to ORCID to let the Hub retrieve your ORCID iD.<br/>
                            Once you've linked your ORCID iD to an organisation using the Hub, you can use this ORCID record to log in.</small></p>
                        </div>
                      </div>
                    </div>
                    <div class="modal-footer">
                      <p>You can <b>only</b> log in with your ORCID record if you've already linked your iD via the Hub</p>
                    </div>
                  </div>
                </div>
              </div>
              {% endif %}
            </li>
          {% endif %}
        </ul>
        <!-- button class="btn btn-danger navbar-btn">Button</button -->
      </div>
    </div>
  </nav>
</header>
{% with messages = get_flashed_messages(with_categories=true) %}
  <!-- Categories: success (green), info (blue), warning (yellow), danger (red) -->
  {% if messages %}
    {% for category, message in messages %}
      <div class="alert alert-{{ category if category != "message" else "info" }} alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <strong>{{category.capitalize()}}!</strong> {{ message | safe }}
      </div>
    {% endfor %}
  {% endif %}
{% endwith %}
