<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $uuid = $_POST['uuid'];
    $cle = $_POST['cle'];
    $client = $_POST['client'];
    $etat = "actif";
    $date_activation = date("Y-m-d");

    $file = __DIR__ . "/api/licences.json";
    $licences = json_decode(file_get_contents($file), true);
    $licences[] = compact('uuid', 'cle', 'client', 'etat', 'date_activation');
    file_put_contents($file, json_encode($licences, JSON_PRETTY_PRINT));
    header("Location: index.php");
    exit;
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Ajouter une licence</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>Ajouter une licence</h1>
    <form method="post">
        <div class="mb-3">
            <label>Client</label>
            <input name="client" class="form-control" required>
        </div>
        <div class="mb-3">
            <label>UUID</label>
            <input name="uuid" class="form-control" required>
        </div>
        <div class="mb-3">
            <label>Clé</label>
            <input name="cle" class="form-control" required>
        </div>
        <button class="btn btn-primary">✅ Enregistrer</button>
        <a href="index.php" class="btn btn-secondary">Retour</a>
    </form>
</body>
</html>
