{# -*- coding: utf-8 -*-

  This file is part of Invenio.
  Copyright (C) 2015-2018 CERN.

  Invenio is free software; you can redistribute it and/or modify it
  under the terms of the MIT License; see LICENSE file for more details.
#}

{%- extends config.OAUTH2SERVER_COVER_TEMPLATE %}

{%- import "invenio_oauth2server/settings/helpers.html" as helpers with context %}

{% block page_body %}
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
{{ helpers.panel_start(_('Authorize application'), icon='fa fa-shield fa-fw') }}
<h1 align="center">{{ _('Authorize application') }}</h1>
<h3 align="center">{{ _("Application '%(client_name)s' by '%(client_user)s' wants permission to access your '%(current_user)s' account.",
                        client_name=client.name, client_user=client.user.nickname or client.user.email, current_user=current_user.nickname or current_user.email) }}</h3>
<hr />
<div class="row">
<div class="col-md-8">
<div class="text-left">

  <h4>{{ _('Review permissions') }}</h4>
  {%- for group in scopes|groupby('group') %}
    {%- if loop.first %}<table class="table table-striped table-bordered"><tbody>{% endif %}
      <tr>
        <td><strong>{{group.grouper}}</strong></td>
        <td><ul>{% for scope in group.list %}<li>{{scope.help_text}}</li>{% endfor %}</ul></td>
      </tr>
    {%- if loop.last %}</tbody></table>{% endif %}
  {%- else %}
    <p><em>No permissions granted.</em></p>
  {%- endfor %}
</div>
</div>
<div class="col-md-4">
  <div class="well">
    <div class="text-left">
    <span class="text-muted">{{ _('Application') }}</span>
    <h4>{{client.name}}</h4>
    {%- if client.description %}<p>{{client.description}}</p>{% endif %}
    {%- if client.website %}<p><a href="{{client.website}}">{{ _('Visit application website') }}</a></p>{% endif %}
    <hr />
    <p class="text-center text-muted">
    <i class="fa fa-users"></i> {{ client.get_users }} {{ 'user' if client.get_users == 1 else 'users' }}
    </p>
  </div>
  </div>
</div>
</div>
<hr />
<div align="center">
  <form action="" method="POST">
    <button type="submit" value="yes" name="confirm" class="btn btn-success"><i class="fa fa-check"></i> {{ _('Authorize application') }}</button>
    <button type="submit" value="no" name="confirm" class="btn btn-danger"><i class="fa fa-ban"></i> {{ _('Reject') }}</button>
  </form>
</div>
{{ helpers.panel_end() }}
</div>
</div>
</div>
{% endblock %}
