{% extends theme('base.html') %}

{% block style %}
    <link href="/static/datatables/jquery.dataTables.min.css" rel="stylesheet">
    <link href="/static/datatables/dataTables.semanticui.min.css" rel="stylesheet">
{% endblock %}

{% block script %}
    <script src="/static/datatables/jquery.dataTables.min.js"></script>
    <script src="/static/datatables/dataTables.semanticui.min.js"></script>
    <script src="/static/js/users.js"></script>
{% endblock %}

{% block content %}
    <div class="ui segment">
        <h2 class="ui center aligned header">
            <div class="content">
                {{ _("My consents") }}
            </div>
            <div class="sub header">
                {% trans %}Consult and revoke the authorization you gave to websites.{% endtrans %}
            </div>
        </h2>

        {% if consents %}
            <div class="ui centered cards">
                {% for consent in consents %}
                    {% set client = clients[consent.client] %}
                    <div class="ui card">
                        <div class="content">
                            {% if client.logo_uri %}
                                <img class="right floated mini ui image" src="{{ client.logo_uri }}">
                            {% endif %}
                            {% if client.uri %}
                                <a href="{{ client.uri }}" class="header">{{ client.client_name }}</a>
                            {% else %}
                                <div class="header">{{ client.client_name }}</div>
                            {% endif %}
                            <div class="meta">{% trans %}From:{% endtrans %} {{ consent.issue_date.strftime("%d/%m/%Y %H:%M:%S") }}</div>
                            {% if consent.revokation_date %}
                                <div class="meta">{% trans %}Revoked:{% endtrans %} {{ consent.revokation_date.strftime("%d/%m/%Y %H:%M:%S") }}</div>
                            {% endif %}
                            <div class="description">
                                <p>{% trans %}Has access to:{% endtrans %}</p>
                                <ul>
                                    {% for s in consent.scope %}
                                        <li>{{ s }}</li>
                                    {% endfor %}
                                </ul>
                            </div>
                        </div>
                        <a class="ui bottom attached button" href="{{ url_for('oidc.consents.delete', consent_id=consent.cn[0] ) }}">
                            <i class="remove icon"></i>
                            {% trans %}Remove access{% endtrans %}
                        </a>
                    </div>
                {% endfor %}
            </div>
        {% else %}
            <div class="ui center aligned">
                <i class="massive smile outline icon image ui"></i>

                <h2 class="ui center aligned header">
                    <div class="content">{% trans %}Nothing here{% endtrans %}</div>
                    <div class="sub header">{% trans %}You did not authorize applications yet.{% endtrans %}</div>
                </h2>
            </div>
        {% endif %}
    </div>
{% endblock %}
