<?php
require_once 'config/database.php';

// Fetch staff members
$stmt = $pdo->query("SELECT * FROM personnel ORDER BY list_order ASC");
$staff = $stmt->fetchAll();

$title = 'Personnel Communal';

include 'includes/header.php';
?>

<main class="min-h-screen py-16 bg-alsace-cream">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        <h2 class="font-serif text-3xl md:text-4xl font-bold text-alsace-red mb-12 border-b-2 border-alsace-red pb-4">
            <?php echo htmlspecialchars($title); ?>
        </h2>

        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
            <?php foreach($staff as $s): ?>
            <div class="bg-white rounded-2xl shadow-md overflow-hidden border border-gray-100 hover:shadow-lg transition group">
                <div class="aspect-square relative overflow-hidden bg-gray-100">
                    <?php if($s['photo']): ?>
                        <img src="<?php echo htmlspecialchars($s['photo']); ?>" alt="<?php echo htmlspecialchars($s['name']); ?>" class="w-full h-full object-cover group-hover:scale-105 transition duration-500">
                    <?php else: ?>
                        <div class="w-full h-full flex items-center justify-center text-gray-300">
                            <i data-lucide="user" class="w-20 h-20 opacity-50"></i>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="p-6 text-center">
                    <h3 class="font-serif text-xl font-bold text-gray-900 mb-1 group-hover:text-alsace-red transition"><?php echo htmlspecialchars($s['name']); ?></h3>
                    <p class="text-alsace-red font-medium"><?php echo htmlspecialchars($s['role']); ?></p>
                </div>
            </div>
            <?php endforeach; ?>

            <?php if(empty($staff)): ?>
                <div class="col-span-full text-center py-12 bg-white rounded-xl shadow-sm border border-gray-100">
                    <p class="text-gray-500 text-lg italic">Informations en cours de mise à jour.</p>
                </div>
            <?php endif; ?>
        </div>
    </div>
</main>

<script>
    if(typeof lucide !== 'undefined') {
        lucide.createIcons();
    }
</script>

<?php include 'includes/footer.php'; ?>