<?php
/** @var \BotGuard\Core\View $this @var \BotGuard\Core\Csrf $csrf @var array $modules */
$this->layout('layouts.app');
?>
<h1 class="h4 mb-1">Detection Modules</h1>
<p class="text-secondary small mb-4">Enable or disable modules and tune their scoring weight. Changes apply on the next verification.</p>

<form method="post" action="/admin/modules">
    <?= $csrf->field() ?>
    <div class="card border-0 shadow-sm">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table align-middle mb-0">
                    <thead>
                        <tr class="text-secondary small text-uppercase">
                            <th style="width:90px">Enabled</th><th>Module</th><th>Group</th><th style="width:200px">Weight</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($modules as $m): $key = e($m['module_key']); ?>
                            <tr>
                                <td>
                                    <div class="form-check form-switch">
                                        <input class="form-check-input" type="checkbox"
                                               name="enabled[<?= $key ?>]" value="1" <?= $m['enabled'] ? 'checked' : '' ?>>
                                    </div>
                                </td>
                                <td>
                                    <div class="fw-semibold"><?= e($m['label']) ?></div>
                                    <div class="text-secondary small"><?= $key ?></div>
                                </td>
                                <td><span class="badge text-bg-secondary"><?= e($m['group']) ?></span></td>
                                <td>
                                    <div class="input-group input-group-sm">
                                        <input type="number" step="0.5" min="0" max="100" class="form-control"
                                               name="weight[<?= $key ?>]" value="<?= e((float) $m['weight']) ?>">
                                        <span class="input-group-text">pts</span>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="card-footer bg-body">
            <button class="btn btn-primary" type="submit"><i class="bi bi-save"></i> Save modules</button>
        </div>
    </div>
</form>
