{% extends "base.html" %}
{% block content %}

<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1>
            <i class="bi bi-pencil"></i> 
            {% if service %}Modifier{% else %}Nouveau{% endif %} service
        </h1>
        <a href="{{ url_for('services.index') }}" class="btn btn-secondary">
            <i class="bi bi-arrow-left"></i> Retour
        </a>
    </div>

    <div class="card">
        <div class="card-body">
            <form method="POST">
                <div class="mb-3">
                    <label class="form-label">Nom du service *</label>
                    <input type="text" name="name" class="form-control" 
                           value="{{ service.name if service else '' }}" required>
                </div>
                
                <div class="mb-3">
                    <label class="form-label">Description</label>
                    <textarea name="description" class="form-control" rows="3">{{ service.description if service else '' }}</textarea>
                </div>
                
                <div class="mb-3">
                    <label class="form-label">Responsable</label>
                    <select name="manager_id" class="form-select">
                        <option value="None">Aucun responsable</option>
                        {% for user in users %}
                        <option value="{{ user.id }}" 
                            {% if service and service.manager_id == user.id %}selected{% endif %}>
                            {{ user.full_name }}
                        </option>
                        {% endfor %}
                    </select>
                </div>
                
                <div class="mb-3">
                    <label class="form-label">Chargé d'opération</label>
                    <select name="operator_id" class="form-select">
                        <option value="None">Aucun chargé d'opération</option>
                        {% for user in users %}
                        <option value="{{ user.id }}" 
                            {% if service and service.operator_id == user.id %}selected{% endif %}>
                            {{ user.full_name }}
                        </option>
                        {% endfor %}
                    </select>
                </div>
                
                <button type="submit" class="btn btn-primary">
                    <i class="bi bi-check"></i> {% if service %}Mettre à jour{% else %}Créer{% endif %}
                </button>
            </form>
        </div>
    </div>
</div>

{% endblock %}