{% extends 'admin/base.html' %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        {% if category %}
            <h1><i class="fas fa-edit me-2"></i> Modifier une catégorie</h1>
        {% else %}
            <h1><i class="fas fa-plus-circle me-2"></i> Ajouter une catégorie</h1>
        {% endif %}
        <a href="{{ url_for('admin.categories') }}" class="btn btn-secondary">
            <i class="fas fa-arrow-left me-2"></i> Retour à la liste
        </a>
    </div>
    
    <div class="card border-0 shadow-sm">
        <div class="card-body p-4">
            <form method="post" class="needs-validation" novalidate>
                {{ form.hidden_tag() }}
                
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <div class="form-group">
                            {{ form.name.label(class="form-label") }}
                            {{ form.name(class="form-control" + (" is-invalid" if form.name.errors else "")) }}
                            {% if form.name.errors %}
                                <div class="invalid-feedback">
                                    {% for error in form.name.errors %}
                                        {{ error }}
                                    {% endfor %}
                                </div>
                            {% endif %}
                        </div>
                    </div>
                    <div class="col-md-6 mb-3">
                        <div class="form-group">
                            {{ form.parent_id.label(class="form-label") }}
                            {{ form.parent_id(class="form-select" + (" is-invalid" if form.parent_id.errors else "")) }}
                            {% if form.parent_id.errors %}
                                <div class="invalid-feedback">
                                    {% for error in form.parent_id.errors %}
                                        {{ error }}
                                    {% endfor %}
                                </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
                
                <div class="form-group mb-3">
                    {{ form.description.label(class="form-label") }}
                    {{ form.description(class="form-control" + (" is-invalid" if form.description.errors else ""), rows=4) }}
                    {% if form.description.errors %}
                        <div class="invalid-feedback">
                            {% for error in form.description.errors %}
                                {{ error }}
                            {% endfor %}
                        </div>
                    {% endif %}
                </div>
                
                <div class="d-flex justify-content-between mt-4">
                    <a href="{{ url_for('admin.categories') }}" class="btn btn-secondary">Annuler</a>
                    {{ form.submit(class="btn btn-primary") }}
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}
