{% extends "backend/template.html" %}

{% block content %}
{% with messages = get_flashed_messages() %}
{% for message in messages %}
{{ message }}
{% endfor %}
{% endwith%}

<div class="container mt-3">
    <!-- Botón para regresar al listado -->
    {% if backlink %}
        <a href="{{ backlink }}" class="btn btn-secondary">Regresar</a>
    {% else %}
        <button onclick="window.history.back();" class="btn btn-secondary">Regresar</button>
    {% endif %}
    <!-- Botón para editar -->
    <a href="{{ url_for('.edit_record', record_id=institution.id, classid=classid, backlink=backlink) }}" class="btn btn-primary">Editar</a>
    <!-- Botón para borrar -->
    <form action="{{ url_for('.delete_record', record_id=institution.id, classid=classid, backlink=backlink) }}" method="post"
        style="display: inline;"><input type="hidden" id="csrf_token" name="csrf_token" value="{{ csrf_token() }}">
        <button type="submit" class="btn btn-danger"
            onclick="return confirm('¿Estás seguro de que quieres eliminar esta institución?');">Borrar</button>
    </form>
    <a href="{{ url_for('field.create_record', parent=institution.clazz_id, backlink=backlink) }}" class="btn btn-success mb-3">Crear Field</a>

    <h2>{{ classname }}: {{institution.id}}</h2>
    <div class="card">
        <div class="card-body">
    <div class="row">
        {% for container_name, container_data in containers.items() %}
                <div class="{{ container_data.class }}">
                    {% if container_data.title %}<h3>{{ container_data.title }}</h3>{% endif %}
                    {% for key, value in container_data.fields.items() %}
                    {% set field_value = institution|safe_getattr(value.id) %}
                    <div class="{{ value.class }}">
                        <p>
                            <b>{{ value.label }}:</b> {{field_value}}
                        </p>
                    </div>
                    {% endfor %}
                </div>
                {% endfor %}
            </div>
        </div>
    </div>
  
</div>
{% endblock %}