{% extends 'base.html' %}

{% block app_content %}
    {% if logs %}
    <div class="container">
        <h3>Dernières opérations sur cette fiche</h3>
        <ul>
            {% for log in logs %}
                <li>
                    <span style="margin-right: 10px;">{{ log.date.strftime('%d %b %Hh%M') }}</span>
                    <span>{{ log.text|safe }} par {{ log.authenticated_user|get_nomcomplet }}</span>
                </li>
            {% endfor %}
        </ul>
    </div>
    {% endif %}
    {% if historique %}
    <div class="container">
        <h3>Historique</h3>
        <ul>
            {% for data in historique %}
                <li>
                    <span style="margin-right: 10px;">{{ data[0].date_debut.strftime('%d/%m/%Y') }} - {{ data[0].date_fin.strftime('%d/%m/%Y') }}</span>
                    <span style="margin-right: 10px;">
                        {{ data[0].type_offre }} réalisé par {{ data[1].nom|format_nom }} {{ data[1].prenom|format_prenom }} en {{ data[0].formation_text }}
                    </span>
                </li>
            {% endfor %}
        </ul>
    </div>
    {% endif %}
    <div class="container">
        <h2>Fiche entreprise - {{ entreprise.nom }} ({{ entreprise.siret }})</h2>

        <div>
            <p>
                SIRET : {{ entreprise.siret }}<br>
                Nom : {{ entreprise.nom }}<br>
                Adresse : {{ entreprise.adresse }}<br>
                Code postal : {{ entreprise.codepostal }}<br>
                Ville : {{ entreprise.ville }}<br>
                Pays : {{ entreprise.pays }}
            </p>
        </div>

        {% if contacts %}
        <div>
        {% for contact in contacts %}
            Contact {{loop.index}}
            {% include 'entreprises/_contact.html' %}
        {% endfor %}
        </div>
        {% endif %}
        
        {% if offres %}
        <div>
        {% for offre in offres %}
            Offre {{loop.index}} (ajouté le {{offre.date_ajout.strftime('%d/%m/%Y') }})
            {% include 'entreprises/_offre.html' %}
        {% endfor %}
        </div>
        {% endif %}
        
        <div>
            <a class="btn btn-primary" href="{{ url_for('entreprises.edit_entreprise', id=entreprise.id) }}">Modifier</a>
            <a class="btn btn-danger" href="{{ url_for('entreprises.delete_entreprise', id=entreprise.id) }}">Supprimer</a>
            <a class="btn btn-primary" href="{{ url_for('entreprises.add_offre', id=entreprise.id) }}">Ajouter offre</a>
            <a class="btn btn-primary" href="{{ url_for('entreprises.add_contact', id=entreprise.id) }}">Ajouter contact</a>
            <a class="btn btn-primary" href="{{ url_for('entreprises.add_historique', id=entreprise.id) }}">Ajouter historique</a>
        </div> 
    </div>
{% endblock %}