{% extends "base.html" %}

{% block title %}{{ title }}{% endblock %}

{% block content %}
<div id="admin-content" class="container users-form-container">
    <div class="row">
        <div class="col-12 mb-4 admin-header">
            <h1>{{ title }}</h1>
        </div>
    </div>
    
    <div class="row mb-4">
        <div class="col-12">
            <p class="mb-0">Complete el formulario con la información del usuario.</p>
        </div>
    </div>
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card shadow-sm">
                <div class="card-header">
                    <h3>{{ legend }}</h3>
                </div>
                <div class="card-body">
                    <form method="POST" action="">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                        {{ form.hidden_tag() }}
                        <fieldset class="form-group">
                            <div class="mb-3">
                                {{ form.username.label(class="form-label") }}
                                {{ form.username(class="form-control") }}
                                {% for error in form.username.errors %}
                                    <div class="invalid-feedback d-block">{{ error }}</div>
                                {% endfor %}
                            </div>
                            <div class="mb-3">
                                {{ form.email.label(class="form-label") }}
                                {{ form.email(class="form-control") }}
                                {% for error in form.email.errors %}
                                    <div class="invalid-feedback d-block">{{ error }}</div>
                                {% endfor %}
                            </div>
                            <div class="mb-3">
                                {{ form.password.label(class="form-label") }}
                                {{ form.password(class="form-control") }}
                                {% for error in form.password.errors %}
                                    <div class="invalid-feedback d-block">{{ error }}</div>
                                {% endfor %}
                            </div>
                            <div class="mb-3">
                                {{ form.confirm_password.label(class="form-label") }}
                                {{ form.confirm_password(class="form-control") }}
                                {% for error in form.confirm_password.errors %}
                                    <div class="invalid-feedback d-block">{{ error }}</div>
                                {% endfor %}
                            </div>
                            <div class="mb-3">
                                {{ form.roles.label(class="form-label") }} <small class="text-muted">(Mantén presionado Ctrl o Cmd para seleccionar varios)</small>
                                {{ form.roles(class="form-select", size=5) }}
                                {% for error in form.roles.errors %}
                                    <div class="invalid-feedback d-block">{{ error }}</div>
                                {% endfor %}
                            </div>
                        </fieldset>
                        <div class="form-group mt-4">
                            {{ form.submit(class="btn btn-primary") }}
                            <a href="{{ url_for('admin.list_users') }}" class="btn btn-secondary">Cancelar</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock content %}
