{% extends "base.html" %}
{% block title %}ENT{% endblock %}
{% block content %}
<div class="container-fluid">
    <h1 class="h3 mb-4">Intégration ENT77</h1>
    
    {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
            {% for category, message in messages %}
            <div class="alert alert-{{ category }}">
                {{ message }}
            </div>
            {% endfor %}
        {% endif %}
    {% endwith %}
    
    {% if credentials %}
    <div class="alert alert-success">
        <i class="bi bi-check-circle"></i> Identifiants ENT configurés pour <strong>{{ credentials.ent_username }}</strong>
    </div>
    
    <div class="row">
        <div class="col-md-6 mb-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Actions</h5>
                </div>
                <div class="card-body">
                    <a href="{{ url_for('ent.inbox') }}" class="btn btn-outline-primary me-2">
                        <i class="bi bi-inbox"></i> Boîte de réception
                    </a>
                    <a href="{{ url_for('ent.staff') }}" class="btn btn-outline-secondary">
                        <i class="bi bi-people"></i> Personnel
                    </a>
                </div>
            </div>
        </div>
    </div>
    
    <div class="card mt-3">
        <div class="card-header">
            <h5 class="mb-0">Modifier les identifiants</h5>
        </div>
        <div class="card-body">
            <form method="POST" action="{{ url_for('ent.index') }}">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                <input type="hidden" name="action" value="update">
                <div class="mb-3">
                    <label for="ent_username" class="form-label">Nom d'utilisateur ENT</label>
                    <input type="text" class="form-control" id="ent_username" name="ent_username" value="{{ credentials.ent_username }}" required>
                </div>
                <div class="mb-3">
                    <label for="ent_password" class="form-label">Mot de passe ENT</label>
                    <input type="password" class="form-control" id="ent_password" name="ent_password" placeholder="Laisser vide pour conserver l'actuel">
                </div>
                <button type="submit" class="btn btn-primary">
                    <i class="bi bi-save"></i> Mettre à jour
                </button>
            </form>
        </div>
    </div>
    {% else %}
    <div class="alert alert-info">
        <i class="bi bi-info-circle"></i> Entrez vos identifiants ENT77 pour activer l'intégration
    </div>
    
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0">Connexion ENT77</h5>
        </div>
        <div class="card-body">
            <form method="POST" action="{{ url_for('ent.index') }}">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                <input type="hidden" name="action" value="create">
                <div class="mb-3">
                    <label for="ent_username" class="form-label">Nom d'utilisateur ENT</label>
                    <input type="text" class="form-control" id="ent_username" name="ent_username" required placeholder="votre.login">
                </div>
                <div class="mb-3">
                    <label for="ent_password" class="form-label">Mot de passe ENT</label>
                    <input type="password" class="form-control" id="ent_password" name="ent_password" required>
                </div>
                <button type="submit" class="btn btn-primary">
                    <i class="bi bi-box-arrow-in-right"></i> Se connecter
                </button>
            </form>
        </div>
    </div>
    {% endif %}
</div>
{% endblock %}