<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-plug"></i> Plugins</h2>
    <a href="/admin/plugins-new" class="btn btn-primary btn-sm">
        <i class="bi bi-plus-lg"></i> Nieuwe plugin
    </a>
</div>

<div class="card shadow-sm mb-4">
    <div class="card-body">
        <h5 class="card-title"><i class="bi bi-info-circle"></i> Plugin Ontwikkelaarshandleiding</h5>
        <p class="text-muted mb-2">Een plugin moet aan de volgende eisen voldoen om correct te werken:</p>
        <div class="row g-3">
            <div class="col-md-4">
                <div class="d-flex align-items-start">
                    <i class="bi bi-folder2-open text-primary me-2 mt-1"></i>
                    <div>
                        <strong>Mapstructuur</strong><br>
                        <code class="small">plugins/Naam/Naam.php</code>
                        <small class="text-muted d-block">Mapnaam en bestandsnaam moeten identiek zijn.</small>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="d-flex align-items-start">
                    <i class="bi bi-code-square text-primary me-2 mt-1"></i>
                    <div>
                        <strong>Class naam</strong><br>
                        <code class="small">class PluginNaam</code>
                        <small class="text-muted d-block">De class moet exact dezelfde naam hebben als de map.</small>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="d-flex align-items-start">
                    <i class="bi bi-puzzle text-primary me-2 mt-1"></i>
                    <div>
                        <strong>Optionele hooks</strong><br>
                        <code class="small">setAPI(CMSAPI)</code> · <code class="small">getSidebarContent()</code>
                        <small class="text-muted d-block">Voor CMS-toegang en sidebar-weergave.</small>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="d-flex align-items-start">
                    <i class="bi bi-gear-wide text-primary me-2 mt-1"></i>
                    <div>
                        <strong>Configuratie (optioneel)</strong><br>
                        <code class="small">config.json</code>
                        <small class="text-muted d-block">Wordt getoond met een configuratieformulier in de admin.</small>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="d-flex align-items-start">
                    <i class="bi bi-shield-check text-primary me-2 mt-1"></i>
                    <div>
                        <strong>Beveiliging</strong><br>
                        <code class="small">htmlspecialchars()</code>
                        <small class="text-muted d-block">Altijd output escapen. Volg PSR-12.</small>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="d-flex align-items-start">
                    <i class="bi bi-book text-primary me-2 mt-1"></i>
                    <div>
                        <strong>Documentatie (optioneel)</strong><br>
                        <code class="small">README.md</code>
                        <small class="text-muted d-block">Aangeraden voor uitleg over de plugin.</small>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php if (empty($plugins)): ?>
    <div class="alert alert-info">Geen plugins gevonden in de plugins map.</div>
<?php else: ?>
    <div class="row g-4">
        <?php foreach ($plugins as $plugin): ?>
            <div class="col-md-6">
                <div class="card shadow-sm">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <strong><i class="bi bi-plug"></i> <?= htmlspecialchars($plugin['name']) ?></strong>
                        <?php if ($plugin['viewable']): ?>
                            <span class="badge bg-success">Zichtbaar</span>
                        <?php else: ?>
                            <span class="badge bg-secondary">Systeem</span>
                        <?php endif; ?>
                    </div>
                    <div class="card-body">
                        <table class="table table-sm mb-0">
                            <tr>
                                <td class="text-muted">Hoofdbestand</td>
                                <td>
                                    <?= $plugin['has_main'] ? '<i class="bi bi-check-circle text-success"></i> Aanwezig' : '<i class="bi bi-x-circle text-danger"></i> Ontbreekt' ?>
                                </td>
                            </tr>
                            <tr>
                                <td class="text-muted">Configuratie</td>
                                <td>
                                    <?= $plugin['has_config'] ? '<i class="bi bi-check-circle text-success"></i> Aanwezig' : '<i class="bi bi-dash-circle text-muted"></i> Geen' ?>
                                </td>
                            </tr>
                            <tr>
                                <td class="text-muted">README</td>
                                <td>
                                    <?= $plugin['has_readme'] ? '<i class="bi bi-check-circle text-success"></i> Aanwezig' : '<i class="bi bi-dash-circle text-muted"></i> Geen' ?>
                                </td>
                            </tr>
                        </table>
                        <div class="mt-3 d-flex justify-content-between align-items-center">
                            <div class="btn-group btn-group-sm">
                                <?php if ($plugin['has_main']): ?>
                                    <a href="/admin/plugins-edit&plugin=<?= urlencode($plugin['name']) ?>" class="btn btn-outline-secondary" title="Bewerken">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                <?php endif; ?>
                                <form method="POST" action="/admin/plugins-toggle&plugin=<?= urlencode($plugin['name']) ?>" class="d-inline">
                                    <input type="hidden" name="csrf_token" value="<?= $csrf ?>">
                                    <button type="submit" class="btn btn-sm <?= $plugin['viewable'] ? 'btn-outline-warning' : 'btn-outline-success' ?>" title="<?= $plugin['viewable'] ? 'Verbergen' : 'Tonen' ?>">
                                        <i class="bi <?= $plugin['viewable'] ? 'bi-eye-slash' : 'bi-eye' ?>"></i> <?= $plugin['viewable'] ? 'Verberg' : 'Toon' ?>
                                    </button>
                                </form>
                                <?php if ($plugin['has_config']): ?>
                                    <a href="/admin/plugins-config&plugin=<?= urlencode($plugin['name']) ?>" class="btn btn-outline-primary" title="Configureren">
                                        <i class="bi bi-gear"></i>
                                    </a>
                                <?php endif; ?>
                            </div>
                            <form method="POST" action="/admin/plugins-delete&plugin=<?= urlencode($plugin['name']) ?>" class="d-inline" onsubmit="return confirm('Weet je zeker dat je de plugin &#39;<?= htmlspecialchars($plugin['name']) ?>&#39; wilt verwijderen? Alle bestanden worden permanent verwijderd.')">
                                <input type="hidden" name="csrf_token" value="<?= $csrf ?>">
                                <button type="submit" class="btn btn-sm btn-outline-danger" title="Verwijderen">
                                    <i class="bi bi-trash"></i>
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
