@extends('layouts.app', ['title' => 'Admin Settings | Print Cards'])

@section('content')
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-1">Platform Settings</h1>
            <p class="text-muted mb-0">Manage pricing, payment gateway values, courier defaults, and homepage content.</p>
        </div>
        <a href="{{ route('admin.dashboard') }}" class="btn btn-outline-secondary">Back to Dashboard</a>
    </div>

    <form method="POST" action="{{ route('admin.settings.update') }}" class="row g-4">
        @csrf
        @foreach($settings as $group => $items)
            <div class="col-12">
                <div class="card card-soft">
                    <div class="card-body">
                        <h2 class="h5 text-capitalize mb-3">{{ str_replace('_', ' ', $group) }}</h2>
                        <div class="row g-3">
                            @foreach($items as $setting)
                                <div class="{{ $setting->type === 'json' ? 'col-12' : 'col-md-6' }}">
                                    <label class="form-label">{{ $setting->label }}</label>
                                    @if($setting->type === 'boolean')
                                        <select name="settings[{{ $setting->key }}]" class="form-select">
                                            <option value="true" @selected($setting->value === 'true')>Enabled</option>
                                            <option value="false" @selected($setting->value === 'false')>Disabled</option>
                                        </select>
                                    @elseif($setting->type === 'json')
                                        <textarea name="settings[{{ $setting->key }}]" rows="6" class="form-control">{{ $setting->value }}</textarea>
                                    @else
                                        <input type="text" name="settings[{{ $setting->key }}]" class="form-control" value="{{ $setting->value }}">
                                    @endif
                                </div>
                            @endforeach
                        </div>
                    </div>
                </div>
            </div>
        @endforeach
        <div class="col-12 d-grid">
            <button class="btn btn-primary btn-lg" type="submit">Save Settings</button>
        </div>
    </form>
@endsection
