@extends('layouts.panel')

@section('title', 'Settings')

@section('content')
    <section class="card">
        <div class="page-header">
            <p class="eyebrow">Control Center Settings</p>
            <h1>General, security, theme, notification, API, and backup controls</h1>
        </div>

        <form action="{{ route('settings.update') }}" method="post" class="content-shell">
            @csrf
            @method('put')

            @foreach ($settings as $group => $items)
                <section class="card">
                    <p class="eyebrow">{{ $group }}</p>
                    <div class="settings-grid">
                        @foreach ($items as $setting)
                            <label>
                                <span>{{ $setting->label }}</span>

                                @if ($setting->type === 'boolean')
                                    <input type="hidden" name="settings[{{ $setting->id }}]" value="0">
                                    <input type="checkbox" name="settings[{{ $setting->id }}]" value="1" @checked($setting->typedValue())>
                                @elseif ($setting->type === 'number')
                                    <input class="field" type="number" name="settings[{{ $setting->id }}]" value="{{ old("settings.{$setting->id}", $setting->typedValue()) }}">
                                @else
                                    <input class="field" type="text" name="settings[{{ $setting->id }}]" value="{{ old("settings.{$setting->id}", $setting->typedValue()) }}">
                                @endif

                                <small class="muted">{{ $setting->description }}</small>
                            </label>
                        @endforeach
                    </div>
                </section>
            @endforeach

            <div class="footer-actions">
                <span class="muted">Changes are written to the database and logged to the audit stream.</span>
                <button class="button primary" type="submit">Save Settings</button>
            </div>
        </form>
    </section>
@endsection
