<h2 class="mb-4"><i class="bi bi-sliders"></i> Configuratie</h2>

<form method="POST" action="/admin/config">
    <input type="hidden" name="csrf_token" value="<?= $csrf ?>">

    <div class="card shadow-sm mb-4">
        <div class="card-header">
            <i class="bi bi-globe"></i> Algemene instellingen
        </div>
        <div class="card-body">
            <div class="row mb-3">
                <div class="col-md-6">
                    <label for="site_title" class="form-label">Site titel</label>
                    <input type="text" class="form-control" id="site_title" name="site_title"
                           value="<?= htmlspecialchars($configData['site_title'] ?? 'CodePress') ?>">
                </div>
                <div class="col-md-6">
                    <label for="default_page" class="form-label">Standaard/startpagina</label>
                    <select name="default_page" id="default_page" class="form-select">
                        <option value="">-- Selecteer --</option>
                        <?php foreach ($availablePages as $page): ?>
                            <option value="<?= htmlspecialchars($page) ?>" <?= ($configData['default_page'] ?? '') === $page ? 'selected' : '' ?>>
                                <?= htmlspecialchars(ucwords(str_replace(['-', '_'], ' ', $page))) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                    <small class="form-text text-muted">Welke pagina wordt getoond als bezoekers de site openen.</small>
                </div>
            </div>
        </div>
    </div>

    <div class="card shadow-sm mb-4">
        <div class="card-header">
            <i class="bi bi-translate"></i> Taal
        </div>
        <div class="card-body">
            <div class="row mb-3">
                <div class="col-md-4">
                    <label for="language_default" class="form-label">Standaard taal</label>
                    <select name="language_default" id="language_default" class="form-select">
                        <?php foreach (['nl' => 'Nederlands', 'en' => 'English'] as $code => $label): ?>
                            <option value="<?= $code ?>" <?= ($configData['language']['default'] ?? 'nl') === $code ? 'selected' : '' ?>>
                                <?= $label ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="col-md-8">
                    <label class="form-label">Beschikbare talen</label>
                    <div>
                        <?php $availLangs = $configData['language']['available'] ?? ['nl', 'en']; ?>
                        <div class="form-check form-check-inline">
                            <input type="checkbox" class="form-check-input" id="lang_nl" name="language_available[]" value="nl" <?= in_array('nl', $availLangs) ? 'checked' : '' ?>>
                            <label class="form-check-label" for="lang_nl">Nederlands</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input type="checkbox" class="form-check-input" id="lang_en" name="language_available[]" value="en" <?= in_array('en', $availLangs) ? 'checked' : '' ?>>
                            <label class="form-check-label" for="lang_en">English</label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="card shadow-sm mb-4">
        <div class="card-header">
            <i class="bi bi-search"></i> SEO
        </div>
        <div class="card-body">
            <div class="mb-3">
                <label for="seo_description" class="form-label">Meta beschrijving</label>
                <textarea class="form-control" id="seo_description" name="seo_description" rows="2"><?= htmlspecialchars($configData['seo']['description'] ?? '') ?></textarea>
            </div>
            <div class="mb-3">
                <label for="seo_keywords" class="form-label">Meta keywords</label>
                <input type="text" class="form-control" id="seo_keywords" name="seo_keywords"
                       value="<?= htmlspecialchars($configData['seo']['keywords'] ?? '') ?>">
                <small class="form-text text-muted">Komma-gescheiden trefwoorden.</small>
            </div>
        </div>
    </div>

    <div class="card shadow-sm mb-4">
        <div class="card-header">
            <i class="bi bi-person"></i> Auteur
        </div>
        <div class="card-body">
            <div class="row mb-3">
                <div class="col-md-6">
                    <label for="author_name" class="form-label">Naam</label>
                    <input type="text" class="form-control" id="author_name" name="author_name"
                           value="<?= htmlspecialchars($configData['author']['name'] ?? '') ?>">
                </div>
                <div class="col-md-6">
                    <label for="author_website" class="form-label">Website</label>
                    <input type="url" class="form-control" id="author_website" name="author_website"
                           value="<?= htmlspecialchars($configData['author']['website'] ?? '') ?>">
                </div>
            </div>
        </div>
    </div>

    <div class="card shadow-sm mb-4">
        <div class="card-header">
            <i class="bi bi-toggle-on"></i> Features
        </div>
        <div class="card-body">
            <div class="form-check mb-2">
                <input type="checkbox" class="form-check-input" id="feature_auto_link" name="feature_auto_link" value="1" <?= !empty($configData['features']['auto_link_pages']) ? 'checked' : '' ?>>
                <label class="form-check-label" for="feature_auto_link">Automatisch pagina's linken</label>
            </div>
            <div class="form-check mb-2">
                <input type="checkbox" class="form-check-input" id="feature_search" name="feature_search" value="1" <?= !empty($configData['features']['search_enabled']) ? 'checked' : '' ?>>
                <label class="form-check-label" for="feature_search">Zoekfunctie inschakelen</label>
            </div>
            <div class="form-check mb-2">
                <input type="checkbox" class="form-check-input" id="feature_breadcrumbs" name="feature_breadcrumbs" value="1" <?= !empty($configData['features']['breadcrumbs_enabled']) ? 'checked' : '' ?>>
                <label class="form-check-label" for="feature_breadcrumbs">Breadcrumbs tonen</label>
            </div>
            <div class="form-check">
                <input type="checkbox" class="form-check-input" id="show_version" name="show_version" value="1" <?= !empty($configData['show_version']) ? 'checked' : '' ?>>
                <label class="form-check-label" for="show_version">CMS versie tonen in footer</label>
            </div>
        </div>
    </div>

    <button type="submit" class="btn btn-primary btn-lg">
        <i class="bi bi-check-lg"></i> Configuratie opslaan
    </button>
</form>
