<?php
$licences = json_decode(file_get_contents(__DIR__ . "/api/licences.json"), true);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Gestion des Licences</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body class="p-4">
    <h1>Licences enregistrées</h1>
    <a href="ajouter.php" class="btn btn-success mb-3">➕ Ajouter une licence</a>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>Client</th><th>UUID</th><th>Clé</th><th>État</th><th>Date</th><th>Action</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($licences as $lic): ?>
                <tr>
                    <td><?= htmlspecialchars($lic['client']) ?></td>
                    <td><?= htmlspecialchars($lic['uuid']) ?></td>
                    <td><?= htmlspecialchars($lic['cle']) ?></td>
                    <td><?= htmlspecialchars($lic['etat']) ?></td>
                    <td><?= htmlspecialchars($lic['date_activation']) ?></td>
                    <td>
                        <?php if ($lic['etat'] !== 'bloque'): ?>
                            <a href="bloquer.php?uuid=<?= urlencode($lic['uuid']) ?>" class="btn btn-sm btn-danger">⛔ Bloquer</a>
                        <?php else: ?>
                            <span class="text-muted">Bloqué</span>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</body>
</html>
