{% extends 'panel.html.twig' %}

{% block panel_contents %}
    {% if user.getActiveCertificates()|length < user.getMaxKeys() %}
        <a href="/panel/certificates/new" class="certificate-create">create</a>
    {% endif %}

    <div class="title">
        <h1>Certificates</h1>
        <div class="undertone">You used {{ user.getActiveCertificates()|length }} of your {{ user.getMaxKeys() }} certificates</div>
    </div>

    <ul class="certificate-list">
        {% for certificate in user.getActiveCertificates() %}
            <li>
                <div class="text">
                    <div class="name">{{ certificate.getName() }}.{{ user.getUsername() }}</div>
                    <div class="expiry">expires {{ certificate.getExpiresOn().format('j F Y') }}</div>
                </div>
                <div class="actions">
                    {% if not certificate.getPrivateKey() is empty %}
                    <span class="certificate-download-key">
                        <a target="_blank" href="/panel/certificates/download-key/{{ certificate.getName() }}">download key</a>
                    </span>
                    {% endif %}
                    <span class="certificate-download">
                        <a target="_blank" href="/panel/certificates/download/{{ certificate.getName() }}">download</a>
                    </span>
                    <span class="certificate-delete">revoke</span>
                </div>
                <div class="revoke-q">
                    <span class="q">Are you sure you want to revoke this certificate?</span>
                    <span data-name="{{ certificate.getName() }}" class="yes">
                        <a>yes</a>
                    </span>
                    <span class="no">
                        <a>no</a>
                    </span>
                </div>
            </li>
        {% else %}
            <li>You don't have any certificates :( why not <a href="/panel/certificates/new">create</a> one?</li>
        {% endfor %}
    </ul>
{% endblock %}