<div class="content-wrapper">
<section class="content pt-3">
<div class="container-fluid pb-5">
<?php
$securitySettings = is_array($securitySettings ?? null) ? $securitySettings : [];
$maintenanceMode = (int)($securitySettings['maintenance_mode'] ?? 0);
$ddosEnabled     = (int)($securitySettings['ddos_enabled'] ?? 0);
$ddosLimit       = (int)($securitySettings['ddos_limit'] ?? 60);
$banList   = is_array($securitySettings['ban_list'] ?? null) ? $securitySettings['ban_list'] : [];
$whitelist = is_array($securitySettings['whitelist'] ?? null) ? $securitySettings['whitelist'] : [];
?>

    <div class="d-flex justify-content-between align-items-center mb-3">
        <div>
            <h3 class="mb-0">
                <i class="bi bi-shield-lock-fill text-primary me-2"></i>
                <?= __('sidebar.security_settings', 'Security & Maintenance') ?>
            </h3>
            <small class="text-muted">
                <?= __('sidebar.manage_site', 'Manage Site') ?> →
                <?= __('sidebar.security_settings', 'Security & Maintenance') ?>
            </small>
        </div>

        <button type="submit" form="securityForm" class="btn btn-primary">
            <i class="bi bi-save me-1"></i>
            <?= __('actions.save', 'Save') ?>
        </button>
    </div>

    <?php if (isset($_GET['saved'])): ?>
        <div class="alert alert-success py-2">
            <i class="bi bi-check-circle me-1"></i>
            <?= __('ui.settings_saved', 'Settings saved successfully') ?>
        </div>
    <?php endif; ?>

    <form id="securityForm" method="POST" action="/admin/settings/security/save">
        <?= \Core\System\Csrf::field(); ?>

        <ul class="nav nav-tabs mb-3" role="tablist">
            <li class="nav-item">
                <button type="button" class="nav-link active" data-bs-toggle="tab" data-bs-target="#tab-maintenance">
                    <i class="bi bi-tools me-1"></i>
                    <?= __('security.tab_maintenance', 'Maintenance') ?>
                </button>
            </li>
            <li class="nav-item">
                <button type="button" class="nav-link" data-bs-toggle="tab" data-bs-target="#tab-ip">
                    <i class="bi bi-hdd-network me-1"></i>
                    <?= __('security.tab_ip_control', 'IP Control') ?>
                </button>
            </li>
            <li class="nav-item">
                <button type="button" class="nav-link" data-bs-toggle="tab" data-bs-target="#tab-ddos">
                    <i class="bi bi-shield-exclamation me-1"></i>
                    <?= __('security.tab_ddos', 'DDoS') ?>
                </button>
            </li>
        </ul>

        <div class="tab-content border border-top-0 p-3 bg-white">
            <div class="tab-pane fade show active" id="tab-maintenance">
                <div class="row g-3">
                    <div class="col-md-4">
                        <label class="form-label"><?= __('security.enable_maintenance') ?></label>
                        <select name="maintenance_mode" class="form-select">
                            <option value="0" <?= $maintenanceMode === 0 ? 'selected' : '' ?>><?= __('actions.no') ?></option>
                            <option value="1" <?= $maintenanceMode === 1 ? 'selected' : '' ?>><?= __('actions.yes') ?></option>
                        </select>
                    </div>
                    <div class="col-md-8">
                        <label class="form-label"><?= __('security.maintenance_msg') ?></label>
                        <textarea name="maintenance_msg" class="form-control" rows="2"><?= htmlspecialchars($securitySettings['maintenance_msg'] ?? '', ENT_QUOTES) ?></textarea>
                    </div>
                </div>
            </div>

            <div class="tab-pane fade" id="tab-ip">
                <div class="row g-3">
                    <div class="col-md-6">
                        <label class="form-label"><?= __('security.ban_list') ?></label>
                        <textarea name="ban_list" class="form-control" rows="6"><?= htmlspecialchars(implode("\n", $banList), ENT_QUOTES) ?></textarea>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label"><?= __('security.whitelist_ips') ?></label>
                        <textarea name="whitelist" class="form-control" rows="6"><?= htmlspecialchars(implode("\n", $whitelist), ENT_QUOTES) ?></textarea>
                    </div>
                </div>
            </div>

            <div class="tab-pane fade" id="tab-ddos">
                <div class="row g-3">
                    <div class="col-md-4">
                        <label class="form-label"><?= __('security.enable_ddos') ?></label>
                        <select name="ddos_enabled" class="form-select">
                            <option value="0" <?= $ddosEnabled === 0 ? 'selected' : '' ?>><?= __('actions.no') ?></option>
                            <option value="1" <?= $ddosEnabled === 1 ? 'selected' : '' ?>><?= __('actions.yes') ?></option>
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label"><?= __('security.ddos_limit') ?></label>
                        <input type="number" name="ddos_limit" min="1" class="form-control" value="<?= $ddosLimit ?>">
                    </div>
                </div>
            </div>
        </div>

        <div class="alert alert-light border mt-3 mb-0">
            <i class="bi bi-info-circle me-1"></i>
            <?= __('security.logs_moved_notice', 'Logs and error history have moved to the dedicated Error Logs page for easier review and copying.') ?>
            <a href="/admin/system/errors" class="alert-link ms-1"><?= __('system.error_logs', 'Error Logs') ?></a>
        </div>
    </form>
</div>
</section>
</div>
