{{--
    文件功能：婚姻参数配置页（所有参数按分组展示，可批量保存）

    @author   ChatRoom Laravel
    @version  1.0.0
--}}

@extends('admin.layouts.app')

@section('title', '婚姻参数配置')

@section('content')

    <div class="flex items-center justify-between mb-5">
        <div>
            <h2 class="text-xl font-bold text-gray-800">⚙️ 婚姻参数配置</h2>
            <p class="text-sm text-gray-500 mt-1">修改参数后点击「保存」生效，参数变更会自动清除缓存</p>
        </div>
        <a href="{{ route('admin.marriages.index') }}" class="text-sm text-indigo-600 hover:underline">← 返回总览</a>
    </div>

    <form action="{{ route('admin.marriages.configs.update') }}" method="POST">
        @csrf

        @foreach ($groups as $groupName => $configs)
            <div class="bg-white rounded-xl shadow-sm border overflow-hidden mb-5">
                <div class="px-5 py-3 bg-gray-50 border-b flex items-center gap-2">
                    <span class="font-bold text-gray-700">{{ $groupName }}</span>
                    <span class="text-xs text-gray-400">（{{ $configs->count() }} 项）</span>
                </div>
                <div class="divide-y">
                    @foreach ($configs as $cfg)
                        <div class="px-5 py-4 flex items-center gap-4">
                            <div class="flex-1 min-w-0">
                                <div class="font-bold text-gray-800 text-sm">{{ $cfg->label }}</div>
                                @if ($cfg->description)
                                    <div class="text-xs text-gray-400 mt-0.5">{{ $cfg->description }}</div>
                                @endif
                                <div class="text-xs font-mono text-gray-300 mt-0.5">{{ $cfg->key }}</div>
                            </div>
                            <div class="flex items-center gap-2 shrink-0">
                                @if ($cfg->min !== null)
                                    <span class="text-xs text-gray-400">最小: {{ $cfg->min }}</span>
                                @endif
                                <input type="number" name="configs[{{ $cfg->key }}]" value="{{ $cfg->value }}"
                                    @if ($cfg->min !== null) min="{{ $cfg->min }}" @endif
                                    @if ($cfg->max !== null) max="{{ $cfg->max }}" @endif required
                                    class="border rounded-lg px-3 py-1.5 text-sm w-28 text-center font-bold focus:outline-none focus:ring-2 focus:ring-indigo-300">
                                @if ($cfg->max !== null)
                                    <span class="text-xs text-gray-400">最大: {{ $cfg->max }}</span>
                                @endif
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        @endforeach

        <div class="flex justify-end gap-3 mt-2 pb-6">
            <a href="{{ route('admin.marriages.index') }}"
                class="px-5 py-2.5 border rounded-lg text-sm text-gray-600 hover:bg-gray-50">取消</a>
            <button type="submit"
                class="px-6 py-2.5 bg-indigo-600 text-white rounded-lg font-bold text-sm hover:bg-indigo-700 shadow-sm transition">
                💾 保存所有配置
            </button>
        </div>
    </form>

@endsection
