{% extends "base_template.html" %}

{% block title %}View dataset{% endblock %}

{% block content %}

<h1 class="h3 mb-3">Edit profile</h1>

{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="row">
    <div class="col-12 mb-3">
        <!-- Aquí se elige la clase en función de la categoría del mensaje -->
        <div class="alert alert-{{ category }}" role="alert">
            <div class="alert-message">
                {% if category == 'success' %}
                <h4 class="alert-heading"><i class="align-middle" data-feather="check-circle"></i> Success</h4>
                {% elif category == 'error' %}
                <h4 class="alert-heading"><i class="align-middle" data-feather="x-circle"></i> Error</h4>
                {% endif %}
                <p style="margin-bottom: 0px">{{ message }}</p>
            </div>
        </div>
    </div>
</div>
{% endfor %}
{% endif %}
{% endwith %}


<div class="row">

    <div class="col-12 col-lg-6">

        <form method="POST" action="{{ url_for('profile.edit_profile') }}" class="needs-validation" novalidate>
            {{ form.hidden_tag() }}

            <div class="row form-group">

                <div class="col-6">
                    {{ form.surname.label(class="form-label") }}
                    {% set surname_value = form.surname.data if form.surname.data else current_user.profile.surname %}
                    {{ form.surname(class="form-control", placeholder="Enter your surname", required=true,
                    value=surname_value) }}
                    {% for error in form.surname.errors %}
                    <span style="color: red;">{{ error }}</span>
                    <br>
                    {% endfor %}
                </div>

                <div class="col-6">
                    {{ form.name.label(class="form-label") }}
                    {% set name_value = form.name.data if form.name.data else current_user.profile.name %}
                    {{ form.name(class="form-control", placeholder="Enter your name",
                    required=true, value=name_value) }}
                    {% for error in form.name.errors %}
                    <span style="color: red;">{{ error }}</span>
                    <br>
                    {% endfor %}
                </div>

            </div>

            <div class="row form-group">

                <div class="col-12 mt-3">
                    {{ form.submit(class="btn btn-primary") }}
                </div>


            </div>
        </form>


    </div>

    <div class="row">

        <div class="col-lg-6 col-12">

            {% if error %}

            <div class="mt-3">
                <p style="color: red;"><strong>Error:</strong> {{ error }}
            </div>

            {% endif %}

        </div>

    </div>

</div>

{% endblock %}
