{% extends 'admin/_layout.html.twig' %}

{% block title %}Attestation {{ attestation.reference }} - Association E-Cosplay{% endblock %}

{% block admin_content %}
<div class="page-container">
    <div class="flex items-center justify-between mb-6">
        <div>
            <h1 class="text-2xl font-bold heading-page">{{ attestation.reference }}</h1>
            <p class="text-xs text-gray-400 mt-1">{{ attestation.title }}</p>
        </div>
        <div class="flex items-center gap-3">
            {% if attestation.state == 'signed' %}
                <span class="px-3 py-1 bg-green-500/20 text-green-700 font-bold uppercase text-xs">Signee</span>
            {% else %}
                <span class="px-3 py-1 bg-yellow-100 text-yellow-800 font-bold uppercase text-xs">Brouillon</span>
            {% endif %}
            <a href="{{ path('app_admin_attestation_custom_index') }}" class="px-4 py-2 glass font-bold uppercase text-xs tracking-widest hover:bg-gray-900 hover:text-white transition-all">Retour</a>
        </div>
    </div>

    {% for type, messages in app.flashes %}
        {% for message in messages %}
            <div class="mb-4 p-4 glass font-medium text-sm {{ type == 'success' ? 'border-green-300 text-green-800' : 'border-red-300 text-red-800' }}">{{ message }}</div>
        {% endfor %}
    {% endfor %}

    {# Contenu de l'attestation #}
    <div class="glass p-6 mb-6">
        <h2 class="text-sm font-bold uppercase tracking-wider mb-4">{{ attestation.title }}</h2>

        <p class="text-sm text-gray-600 mb-4 italic">
            "Je soussigne(e), President(e) de l'Association E-Cosplay et le bureau de l'association, atteste les elements suivants :"
        </p>

        <div class="space-y-2 mb-4">
            {% for item in attestation.items %}
                <div class="flex items-start gap-3 glass p-3">
                    <span class="text-xs font-bold text-gray-400 mt-0.5">{{ loop.index }}.</span>
                    <p class="text-sm text-gray-700">{{ item }}</p>
                </div>
            {% endfor %}
        </div>

        <p class="text-sm text-gray-600 italic">
            "La presente attestation est etablie pour faire valoir les droits de l'Association E-Cosplay. Les elements presentes ci-dessus sont conformes et veridiques."
        </p>
    </div>

    {# Infos techniques #}
    <div class="glass p-5 mb-6">
        <div class="grid grid-cols-2 md:grid-cols-4 gap-3 text-xs">
            <div>
                <p class="text-[9px] font-bold uppercase tracking-wider text-gray-400">Reference</p>
                <p class="font-mono font-bold mt-1">{{ attestation.reference }}</p>
            </div>
            <div>
                <p class="text-[9px] font-bold uppercase tracking-wider text-gray-400">HMAC</p>
                <p class="font-mono font-bold mt-1 text-[10px]">{{ attestation.hmac[:16] }}...</p>
            </div>
            <div>
                <p class="text-[9px] font-bold uppercase tracking-wider text-gray-400">Creee le</p>
                <p class="font-bold mt-1">{{ attestation.createdAt|date('d/m/Y H:i') }}</p>
            </div>
            {% if attestation.signedAt %}
                <div>
                    <p class="text-[9px] font-bold uppercase tracking-wider text-gray-400">Signee le</p>
                    <p class="font-bold mt-1 text-green-600">{{ attestation.signedAt|date('d/m/Y H:i') }}</p>
                </div>
            {% endif %}
        </div>
    </div>

    {# Actions #}
    <div class="flex flex-wrap gap-2 mb-6">
        {% if attestation.pdfUnsigned %}
            <a href="{{ vich_uploader_asset(attestation, 'pdfUnsignedFile') }}" target="_blank"
               class="px-4 py-2 bg-gray-900 text-white font-bold uppercase text-[10px] tracking-wider hover:bg-[#fabf04] hover:text-gray-900 transition-all">
                Voir PDF
            </a>
        {% endif %}
        {% if attestation.state == 'draft' %}
            <form method="post" action="{{ path('app_admin_attestation_custom_regenerate_pdf', {id: attestation.id}) }}" data-confirm="Regenerer le PDF ?">
                <button type="submit" class="px-4 py-2 bg-yellow-500/20 text-yellow-700 hover:bg-yellow-500 hover:text-white font-bold uppercase text-[10px] tracking-wider transition-all">Regenerer PDF</button>
            </form>
            <form method="post" action="{{ path('app_admin_attestation_custom_sign', {id: attestation.id}) }}" data-confirm="Signer electroniquement cette attestation via DocuSeal ?">
                <button type="submit" class="px-4 py-2 bg-purple-500/20 text-purple-700 hover:bg-purple-500 hover:text-white font-bold uppercase text-[10px] tracking-wider transition-all">Signer (DocuSeal)</button>
            </form>
        {% endif %}
        {% if attestation.pdfSigned %}
            <a href="{{ vich_uploader_asset(attestation, 'pdfSignedFile') }}" target="_blank"
               class="px-4 py-2 bg-green-500/20 text-green-700 font-bold uppercase text-[10px] tracking-wider hover:bg-green-500 hover:text-white transition-all">
                PDF signe
            </a>
        {% endif %}
        {% if attestation.pdfAudit %}
            <a href="{{ vich_uploader_asset(attestation, 'pdfAuditFile') }}" target="_blank"
               class="px-4 py-2 bg-blue-500/20 text-blue-700 font-bold uppercase text-[10px] tracking-wider hover:bg-blue-500 hover:text-white transition-all">
                Audit signature
            </a>
        {% endif %}
        <form method="post" action="{{ path('app_admin_attestation_custom_delete', {id: attestation.id}) }}" data-confirm="Supprimer definitivement cette attestation ?">
            <button type="submit" class="px-4 py-2 bg-red-500/20 text-red-700 hover:bg-red-500 hover:text-white font-bold uppercase text-[10px] tracking-wider transition-all">Supprimer</button>
        </form>
    </div>
</div>
{% endblock %}
