<main id="main-content">
    <h1><a href="/admin/contenus.php" class="admin-back-btn" title="Retour"><svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" viewBox="0 0 256 256"><path d="M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm48-88a8,8,0,0,1-8,8H107.31l18.35,18.34a8,8,0,0,1-11.32,11.32l-32-32a8,8,0,0,1,0-11.32l32-32a8,8,0,0,1,11.32,11.32L107.31,120H168A8,8,0,0,1,176,128Z"></path></svg></a> Éditer : <?= htmlspecialchars($editTitle) ?></h1>

    <?php if ($editType === 'about_page'): ?>

    <!-- ── Markdown content ──────────────────────────────────────────────── -->
    <h2>Contenu de la page</h2>
    <form action="/admin/actions/page.php" method="post" class="admin-form">
        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION["csrf_token"]) ?>">
        <input type="hidden" name="slug" value="about">

        <label for="editor">Contenu (Markdown) :</label>
        <input type="hidden" id="content" name="content"
               value="<?= htmlspecialchars($initialContent) ?>">
        <div id="editor"></div>

        <div class="admin-form-footer">
            <button type="submit" class="btn btn--primary">Enregistrer</button>
            <a href="/admin/contenus.php" class="btn btn--secondary admin-cancel-link">Annuler</a>
        </div>
    </form>

    <!-- ── Contacts ──────────────────────────────────────────────────────── -->
    <h2 style="margin-top:3rem;">Contacts</h2>
    <?php
    $aproposKey = 'contacts';
    $groups = $aboutContacts ?? [];
    include APP_ROOT . '/templates/admin/apropos-groups-form.php';
    ?>

    <?php elseif ($editType === 'page' && $pageSlug !== 'about'): ?>
    <form action="/admin/actions/page.php" method="post" class="admin-form">
        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION["csrf_token"]) ?>">
        <input type="hidden" name="slug" value="<?= htmlspecialchars($pageSlug) ?>">

        <label for="editor">Contenu (Markdown) :</label>
        <input type="hidden" id="content" name="content"
               value="<?= htmlspecialchars($initialContent) ?>">
        <div id="editor"></div>

        <div class="admin-form-footer">
            <button type="submit" class="btn btn--primary">Enregistrer</button>
            <a href="/admin/contenus.php" class="btn btn--secondary admin-cancel-link">Annuler</a>
        </div>
    </form>

    <?php elseif ($editType === 'form_help'): ?>
    <p class="param-note">Ce texte est affiché dans le formulaire de soumission des étudiant·es (lien de partage). Supporte le Markdown.</p>
    <form action="/admin/actions/form-help.php" method="post" class="admin-form">
        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
        <input type="hidden" name="form_help_key" value="<?= htmlspecialchars($formHelpKey) ?>">

        <label for="editor">Contenu (Markdown) :</label>
        <input type="hidden" id="content" name="content"
               value="<?= htmlspecialchars($initialContent) ?>">
        <div id="editor"></div>

        <div class="admin-form-footer">
            <button type="submit" class="btn btn--primary">Enregistrer</button>
            <a href="/admin/contenus.php#form-help-blocks" class="btn btn--secondary admin-cancel-link">Annuler</a>
        </div>
    </form>

    <?php else: ?>
    <?php
    $groups = is_array($value) ? $value : [];
    ?>
    <?php include APP_ROOT . '/templates/admin/apropos-groups-form.php'; ?>
    <?php endif; ?>
</main>
