<?php
$extraStyles = ['../../css/style-ajout.css'];
require_once __DIR__ . '/header.php';

$error = isset($_GET['error']) ? trim((string)$_GET['error']) : '';
$success = isset($_GET['success']) && $_GET['success'] === '1';
?>
<main class="add-memory-main">
    <form action="traitement-ajout-souvenir.php" method="post" class="add-memory-form" enctype="multipart/form-data">
        <h1>Ajouter un souvenir</h1>

        <?php if ($error !== ''): ?>
            <p class="add-memory-message add-memory-error"><?= htmlspecialchars($error, ENT_QUOTES, 'UTF-8') ?></p>
        <?php elseif ($success): ?>
            <p class="add-memory-message add-memory-success">Souvenir ajoute avec succes.</p>
        <?php endif; ?>

        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars(csrfToken(), ENT_QUOTES, 'UTF-8') ?>">

        <label for="nom">Nom du souvenir</label>
        <input id="nom" name="nom" type="text" placeholder="Nom du souvenir" maxlength="120" required>

        <label for="description">Description</label>
        <textarea id="description" name="description" placeholder="Décris ton souvenir..." required></textarea>

        <label for="visibility">Visibilite</label>
        <select id="visibility" name="visibility" required>
            <option value="private" selected>Prive</option>
            <option value="public">Public</option>
        </select>

        <label for="image">Image du souvenir</label>
        <input id="image" name="image" type="file" accept="image/*" required>
        
        <button type="submit" class="home-button">Ajouter le souvenir</button>
    </form>
</main>

<?php
require_once __DIR__ . '/footer.php';
?>