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

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1><i class="fas fa-tachometer-alt me-2"></i> Tableau de bord</h1>
        <div>
            <span class="text-muted">{{ now.strftime('%d/%m/%Y') }}</span>
        </div>
    </div>
    
    <!-- Stats Cards -->
    <div class="row">
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="stats-card">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <div class="title">Produits</div>
                        <div class="value">{{ product_count }}</div>
                    </div>
                    <div class="icon">
                        <i class="fas fa-box"></i>
                    </div>
                </div>
                <div class="mt-3">
                    <a href="{{ url_for('admin.products') }}" class="text-decoration-none">Voir les produits <i class="fas fa-arrow-right ms-1"></i></a>
                </div>
            </div>
        </div>
        
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="stats-card">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <div class="title">Catégories</div>
                        <div class="value">{{ category_count }}</div>
                    </div>
                    <div class="icon">
                        <i class="fas fa-tags"></i>
                    </div>
                </div>
                <div class="mt-3">
                    <a href="{{ url_for('admin.categories') }}" class="text-decoration-none">Voir les catégories <i class="fas fa-arrow-right ms-1"></i></a>
                </div>
            </div>
        </div>
        
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="stats-card">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <div class="title">Services</div>
                        <div class="value">{{ service_count }}</div>
                    </div>
                    <div class="icon">
                        <i class="fas fa-tools"></i>
                    </div>
                </div>
                <div class="mt-3">
                    <a href="{{ url_for('admin.services') }}" class="text-decoration-none">Voir les services <i class="fas fa-arrow-right ms-1"></i></a>
                </div>
            </div>
        </div>
        
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="stats-card">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <div class="title">Messages non lus</div>
                        <div class="value">{{ unread_message_count }}</div>
                    </div>
                    <div class="icon">
                        <i class="fas fa-envelope"></i>
                    </div>
                </div>
                <div class="mt-3">
                    <a href="{{ url_for('admin.contacts') }}" class="text-decoration-none">Voir les messages <i class="fas fa-arrow-right ms-1"></i></a>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Recent Messages and Quick Actions -->
    <div class="row">
        <!-- Recent Messages -->
        <div class="col-xl-8 mb-4">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-white">
                    <h5 class="mb-0"><i class="fas fa-envelope me-2"></i> Messages récents</h5>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <thead>
                                <tr>
                                    <th>Nom</th>
                                    <th>Email</th>
                                    <th>Date</th>
                                    <th>Statut</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% if recent_contacts %}
                                    {% for contact in recent_contacts %}
                                        <tr class="{{ 'table-warning' if not contact.is_read else '' }}" data-id="{{ contact.id }}">
                                            <td>{{ contact.name }}</td>
                                            <td><a href="mailto:{{ contact.email }}">{{ contact.email }}</a></td>
                                            <td>{{ contact.created_at.strftime('%d/%m/%Y') }}</td>
                                            <td>
                                                {% if contact.is_read %}
                                                    <span class="badge bg-success">Lu</span>
                                                {% else %}
                                                    <span class="badge bg-warning text-dark">Non lu</span>
                                                {% endif %}
                                            </td>
                                            <td>
                                                <a href="{{ url_for('admin.view_contact', id=contact.id) }}" class="btn btn-sm btn-primary message-link" data-id="{{ contact.id }}">
                                                    <i class="fas fa-eye"></i>
                                                </a>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                {% else %}
                                    <tr>
                                        <td colspan="5" class="text-center">Aucun message récent</td>
                                    </tr>
                                {% endif %}
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="card-footer bg-white text-end">
                    <a href="{{ url_for('admin.contacts') }}" class="text-decoration-none">Voir tous les messages <i class="fas fa-arrow-right ms-1"></i></a>
                </div>
            </div>
        </div>
        
        <!-- Quick Actions -->
        <div class="col-xl-4 mb-4">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-header bg-white">
                    <h5 class="mb-0"><i class="fas fa-bolt me-2"></i> Actions rapides</h5>
                </div>
                <div class="card-body">
                    <div class="d-grid gap-3">
                        <a href="{{ url_for('admin.add_product') }}" class="btn btn-outline-primary">
                            <i class="fas fa-plus-circle me-2"></i> Ajouter un produit
                        </a>
                        <a href="{{ url_for('admin.add_category') }}" class="btn btn-outline-primary">
                            <i class="fas fa-plus-circle me-2"></i> Ajouter une catégorie
                        </a>
                        <a href="{{ url_for('admin.add_service') }}" class="btn btn-outline-primary">
                            <i class="fas fa-plus-circle me-2"></i> Ajouter un service
                        </a>

                        <a href="{{ url_for('main.index') }}" class="btn btn-outline-secondary" target="_blank">
                            <i class="fas fa-external-link-alt me-2"></i> Voir le site
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Recent Activity -->
    <div class="row">
        <div class="col-12 mb-4">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-white">
                    <h5 class="mb-0"><i class="fas fa-chart-line me-2"></i> Statistiques du site</h5>
                </div>
                <div class="card-body">
                    <div class="alert alert-info">
                        <i class="fas fa-info-circle me-2"></i> Cette fonctionnalité sera disponible prochainement. Elle permettra de visualiser les statistiques de fréquentation du site.
                    </div>
                    
                    <div class="row text-center">
                        <div class="col-md-3 mb-3 mb-md-0">
                            <div class="p-3">
                                <h4 class="text-primary">0</h4>
                                <p class="text-muted mb-0">Visiteurs aujourd'hui</p>
                            </div>
                        </div>
                        <div class="col-md-3 mb-3 mb-md-0">
                            <div class="p-3">
                                <h4 class="text-primary">0</h4>
                                <p class="text-muted mb-0">Pages vues</p>
                            </div>
                        </div>
                        <div class="col-md-3 mb-3 mb-md-0">
                            <div class="p-3">
                                <h4 class="text-primary">0</h4>
                                <p class="text-muted mb-0">Nouveaux visiteurs</p>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="p-3">
                                <h4 class="text-primary">0</h4>
                                <p class="text-muted mb-0">Taux de rebond</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
