@extends('super-admin.layout')

@section('title', 'Settings')

@section('content')
<div class="pg-head">
    <div>
        <h1>Platform settings</h1>
        <p>Configurable business rules stored in the database. Config file values are used as fallbacks until saved here.</p>
    </div>
</div>

@php
    $groupLabels = [
        'general' => 'General',
        'business' => 'Business & billing',
        'campus' => 'Campus sponsorship',
        'email' => 'Email',
        'security' => 'Security',
    ];
@endphp

<div style="display:grid;gap:1rem;max-width:820px">
    @foreach($definitions as $group => $keys)
        <div class="card form-panel">
            <h2>{{ $groupLabels[$group] ?? ucfirst($group) }}</h2>
            <form method="POST" action="{{ route('mexco.super.settings.update', $group) }}" class="form-stack">
                @csrf
                @method('PUT')
                @foreach($keys as $key => $meta)
                    <div class="form-row">
                        <label class="form-label">{{ $meta['label'] }}</label>
                        @if($meta['type'] === 'boolean')
                            <label class="d-flex gap-2 align-items-center">
                                <input type="checkbox" name="{{ $key }}" value="1"
                                    @checked(old($key, $values[$group][$key] ?? false))>
                                Enabled
                            </label>
                        @else
                            <input type="{{ $meta['type'] === 'integer' ? 'number' : 'text' }}"
                                   name="{{ $key }}"
                                   class="form-input"
                                   value="{{ old($key, $values[$group][$key] ?? '') }}"
                                   @if($meta['type'] === 'integer') min="0" @endif>
                        @endif
                    </div>
                @endforeach
                <button type="submit" class="btn-purple btn-sm">Save {{ strtolower($groupLabels[$group] ?? $group) }}</button>
            </form>
        </div>
    @endforeach
</div>
@endsection
