{{--
    文件功能：后台婚姻管理总览页
    统计卡片 + 最近结婚记录 + 最近离婚记录

    @author   ChatRoom Laravel
    @version  1.0.0
--}}

@extends('admin.layouts.app')

@section('title', '婚姻管理 - 总览')

@section('content')

    {{-- 页面标题 --}}
    <div class="flex items-center justify-between mb-6">
        <div>
            <h2 class="text-xl font-bold text-gray-800">💒 婚姻管理</h2>
            <p class="text-sm text-gray-500 mt-1">婚姻系统总览，管理求婚、结婚、婚礼及参数配置</p>
        </div>
        <div class="flex gap-2">
            <a href="{{ route('admin.marriages.configs') }}"
                class="bg-indigo-600 text-white px-4 py-2 rounded-lg text-sm font-bold hover:bg-indigo-700 transition">
                ⚙️ 参数配置
            </a>
            <a href="{{ route('admin.marriages.tiers') }}" style="background:#db2777;color:#fff;"
                class="px-4 py-2 rounded-lg text-sm font-bold transition hover:opacity-90">
                🎊 婚礼档位
            </a>
        </div>
    </div>

    {{-- 统计卡片 --}}
    <div class="grid grid-cols-2 md:grid-cols-3 xl:grid-cols-6 gap-4 mb-8">
        <div class="bg-white rounded-xl shadow-sm border p-4 text-center">
            <div class="text-2xl mb-1">💑</div>
            <div class="text-2xl font-bold text-indigo-600">{{ $stats['total_married'] }}</div>
            <div class="text-xs text-gray-500 mt-1">当前已婚</div>
        </div>
        <div class="bg-white rounded-xl shadow-sm border p-4 text-center">
            <div class="text-2xl mb-1">💍</div>
            <div class="text-2xl font-bold text-amber-500">{{ $stats['total_pending'] }}</div>
            <div class="text-xs text-gray-500 mt-1">求婚中</div>
        </div>
        <div class="bg-white rounded-xl shadow-sm border p-4 text-center">
            <div class="text-2xl mb-1">💔</div>
            <div class="text-2xl font-bold text-red-500">{{ $stats['total_divorced'] }}</div>
            <div class="text-xs text-gray-500 mt-1">已离婚</div>
        </div>
        <div class="bg-white rounded-xl shadow-sm border p-4 text-center">
            <div class="text-2xl mb-1">🎊</div>
            <div class="text-2xl font-bold text-pink-500">{{ $stats['total_weddings'] }}</div>
            <div class="text-xs text-gray-500 mt-1">婚礼场次</div>
        </div>
        <div class="bg-white rounded-xl shadow-sm border p-4 text-center">
            <div class="text-2xl mb-1">🎁</div>
            <div class="text-2xl font-bold text-green-600">{{ number_format($stats['total_envelopes']) }}</div>
            <div class="text-xs text-gray-500 mt-1">红包总额(金)</div>
        </div>
        <div class="bg-white rounded-xl shadow-sm border p-4 text-center">
            <div class="text-2xl mb-1">✅</div>
            <div class="text-2xl font-bold text-emerald-600">{{ number_format($stats['claimed_amount']) }}</div>
            <div class="text-xs text-gray-500 mt-1">已领取(金)</div>
        </div>
    </div>

    {{-- 快捷入口 --}}
    <div class="grid grid-cols-2 md:grid-cols-4 gap-3 mb-8">
        <a href="{{ route('admin.marriages.list') }}"
            class="bg-white rounded-xl border shadow-sm p-5 flex flex-col items-center gap-2 hover:shadow-md hover:border-blue-300 transition group">
            <span class="text-3xl">📋</span>
            <span class="text-sm font-bold text-gray-700 group-hover:text-blue-600">婚姻列表</span>
        </a>
        <a href="{{ route('admin.marriages.proposals') }}"
            class="bg-white rounded-xl border shadow-sm p-5 flex flex-col items-center gap-2 hover:shadow-md hover:border-amber-300 transition group">
            <span class="text-3xl">💌</span>
            <span class="text-sm font-bold text-gray-700 group-hover:text-amber-600">求婚记录</span>
        </a>
        <a href="{{ route('admin.marriages.ceremonies') }}"
            class="bg-white rounded-xl border shadow-sm p-5 flex flex-col items-center gap-2 hover:shadow-md hover:border-pink-300 transition group">
            <span class="text-3xl">🎊</span>
            <span class="text-sm font-bold text-gray-700 group-hover:text-pink-600">婚礼红包</span>
        </a>
        <a href="{{ route('admin.marriages.intimacy-logs') }}"
            class="bg-white rounded-xl border shadow-sm p-5 flex flex-col items-center gap-2 hover:shadow-md hover:border-purple-300 transition group">
            <span class="text-3xl">💞</span>
            <span class="text-sm font-bold text-gray-700 group-hover:text-purple-600">亲密度日志</span>
        </a>
    </div>

    {{-- 最近已婚 --}}
    <div class="grid grid-cols-1 xl:grid-cols-2 gap-6">
        <div class="bg-white rounded-xl shadow-sm border overflow-hidden">
            <div class="px-5 py-4 flex justify-between items-center border-b bg-gray-50">
                <h3 class="font-bold text-gray-700">💑 最近结婚</h3>
                <a href="{{ route('admin.marriages.list') }}" class="text-xs text-indigo-600 hover:underline">查看全部</a>
            </div>
            <div class="divide-y">
                @forelse ($recentMarriages as $m)
                    <div class="px-5 py-3 flex items-center justify-between text-sm">
                        <div class="flex items-center gap-2">
                            <span class="text-lg">{{ $m->ringItem?->icon ?? '💍' }}</span>
                            <div>
                                <span class="font-bold">{{ $m->user?->username }}</span>
                                <span class="text-gray-400 mx-1">×</span>
                                <span class="font-bold">{{ $m->partner?->username }}</span>
                            </div>
                        </div>
                        <div class="text-right">
                            <div class="text-gray-500">{{ $m->married_at?->format('m/d') }}</div>
                            <div class="text-xs text-indigo-500">
                                {{ \App\Services\MarriageIntimacyService::levelName($m->level) }}</div>
                        </div>
                    </div>
                @empty
                    <div class="px-5 py-8 text-center text-gray-400">暂无已婚记录</div>
                @endforelse
            </div>
        </div>

        {{-- 最近离婚 --}}
        <div class="bg-white rounded-xl shadow-sm border overflow-hidden">
            <div class="px-5 py-4 flex justify-between items-center border-b bg-gray-50">
                <h3 class="font-bold text-gray-700">💔 最近离婚</h3>
                <a href="{{ route('admin.marriages.list', ['status' => 'divorced']) }}"
                    class="text-xs text-red-600 hover:underline">查看全部</a>
            </div>
            <div class="divide-y">
                @forelse ($recentDivorces as $m)
                    <div class="px-5 py-3 flex items-center justify-between text-sm">
                        <div>
                            <span class="font-bold">{{ $m->user?->username }}</span>
                            <span class="text-gray-400 mx-1">×</span>
                            <span class="font-bold">{{ $m->partner?->username }}</span>
                        </div>
                        <div class="text-right">
                            <span
                                class="text-xs px-2 py-0.5 rounded-full font-bold
                                {{ match ($m->divorce_type) {
                                    'forced' => 'bg-red-100 text-red-600',
                                    'auto' => 'bg-orange-100 text-orange-600',
                                    'admin' => 'bg-purple-100 text-purple-600',
                                    default => 'bg-gray-100 text-gray-600',
                                } }}">
                                {{ match ($m->divorce_type) {'forced' => '强制','auto' => '超时','admin' => '管理员',default => '协议'} }}
                            </span>
                            <div class="text-xs text-gray-400 mt-0.5">{{ $m->divorced_at?->format('m/d') }}</div>
                        </div>
                    </div>
                @empty
                    <div class="px-5 py-8 text-center text-gray-400">暂无离婚记录</div>
                @endforelse
            </div>
        </div>
    </div>

@endsection
