<h4 class="mb-4"><i class="fas fa-cogs me-2"></i><?= lang('admin.settings') ?></h4>
<form method="POST" action="/admin/settings" data-ajax="true">
    <?= csrf_field() ?>
    <ul class="nav nav-tabs mb-3" role="tablist">
        <?php $i = 0; foreach (array_keys($groups) as $group): ?>
        <li class="nav-item">
            <a class="nav-link <?= $i === 0 ? 'active' : '' ?>" data-bs-toggle="tab" href="#tab-<?= e($group) ?>"><?= e(ucfirst(str_replace('_', ' ', $group))) ?></a>
        </li>
        <?php $i++; endforeach; ?>
    </ul>
    <div class="tab-content">
        <?php $i = 0; foreach ($groups as $group => $settings): ?>
        <div class="tab-pane fade <?= $i === 0 ? 'show active' : '' ?>" id="tab-<?= e($group) ?>">
            <div class="card">
                <div class="card-body">
                    <?php foreach ($settings as $s): ?>
                    <div class="row mb-3 align-items-center">
                        <div class="col-md-4">
                            <label class="form-label fw-bold mb-0"><?= e($s['config_key']) ?></label>
                            <?php if ($s['description_en']): ?><br><small class="text-muted"><?= e($s['description_en']) ?></small><?php endif; ?>
                        </div>
                        <div class="col-md-6">
                            <?php if ($s['is_readonly']): ?>
                                <input type="text" class="form-control" value="<?= e($s['config_value'] ?? '') ?>" disabled>
                            <?php elseif ($s['config_type'] === 'boolean'): ?>
                                <select name="config[<?= e($s['config_key']) ?>]" class="form-select">
                                    <option value="true" <?= $s['config_value'] === 'true' ? 'selected' : '' ?>>True</option>
                                    <option value="false" <?= $s['config_value'] === 'false' ? 'selected' : '' ?>>False</option>
                                </select>
                            <?php elseif ($s['config_type'] === 'integer'): ?>
                                <input type="number" name="config[<?= e($s['config_key']) ?>]" class="form-control" value="<?= e($s['config_value'] ?? '') ?>">
                            <?php else: ?>
                                <input type="text" name="config[<?= e($s['config_key']) ?>]" class="form-control" value="<?= e($s['config_value'] ?? '') ?>">
                            <?php endif; ?>
                        </div>
                        <div class="col-md-2"><span class="badge bg-light text-dark"><?= e($s['config_type']) ?></span></div>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php $i++; endforeach; ?>
    </div>
    <?php if (Gate::can('settings.manage')): ?>
    <div class="mt-3"><button type="submit" class="btn btn-primary"><i class="fas fa-save me-1"></i>Save Settings</button></div>
    <?php endif; ?>
</form>