{{--
    文件功能：婚礼仪式记录页（含红包分发详情链接）

    @author   ChatRoom Laravel
    @version  1.0.0
--}}

@extends('admin.layouts.app')

@section('title', '婚礼红包记录')

@section('content')

    <div class="flex items-center justify-between mb-5">
        <h2 class="text-xl font-bold text-gray-800">🎊 婚礼红包记录</h2>
        <a href="{{ route('admin.marriages.index') }}" class="text-sm text-indigo-600 hover:underline">← 返回总览</a>
    </div>

    <div class="bg-white rounded-xl shadow-sm border overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-sm">
                <thead class="bg-gray-50 text-gray-600 text-xs uppercase">
                    <tr>
                        <th class="px-4 py-3 text-left">ID</th>
                        <th class="px-4 py-3 text-left">新人</th>
                        <th class="px-4 py-3 text-left">档位</th>
                        <th class="px-4 py-3 text-center">总金额</th>
                        <th class="px-4 py-3 text-center">在线人数</th>
                        <th class="px-4 py-3 text-center">领取进度</th>
                        <th class="px-4 py-3 text-center">状态</th>
                        <th class="px-4 py-3 text-left">时间</th>
                        <th class="px-4 py-3 text-center">详情</th>
                    </tr>
                </thead>
                <tbody class="divide-y">
                    @forelse ($ceremonies as $c)
                        <tr class="hover:bg-gray-50">
                            <td class="px-4 py-3 text-gray-400 font-mono text-xs">{{ $c->id }}</td>
                            <td class="px-4 py-3">
                                <span class="font-bold">{{ $c->marriage?->user?->username }}</span>
                                <span class="text-gray-400 mx-1">×</span>
                                <span class="font-bold">{{ $c->marriage?->partner?->username }}</span>
                            </td>
                            <td class="px-4 py-3">
                                {{ $c->tier?->icon }} {{ $c->tier?->name ?? '—' }}
                            </td>
                            <td class="px-4 py-3 text-center font-bold text-amber-600">
                                {{ number_format($c->total_amount) }} 金
                            </td>
                            <td class="px-4 py-3 text-center text-gray-600">
                                {{ $c->online_count ?? '—' }}
                            </td>
                            <td class="px-4 py-3 text-center">
                                @if ($c->total_amount > 0)
                                    <div class="text-xs text-gray-600">
                                        {{ $c->claimed_count }} / {{ $c->online_count ?? '?' }} 人
                                    </div>
                                    <div class="text-xs text-emerald-600 font-bold">
                                        {{ number_format($c->claimed_amount) }} / {{ number_format($c->total_amount) }}
                                    </div>
                                @else
                                    <span class="text-gray-300 text-xs">无红包</span>
                                @endif
                            </td>
                            <td class="px-4 py-3 text-center">
                                <span
                                    class="px-2 py-0.5 rounded-full text-xs font-bold
                                    {{ match ($c->status) {
                                        'completed' => 'bg-green-100 text-green-700',
                                        'active' => 'bg-blue-100 text-blue-700',
                                        'pending' => 'bg-amber-100 text-amber-700',
                                        'expired' => 'bg-gray-100 text-gray-500',
                                        'cancelled' => 'bg-red-100 text-red-600',
                                        default => 'bg-gray-100 text-gray-600',
                                    } }}">
                                    {{ ['completed' => '已完成', 'active' => '进行中', 'pending' => '待触发', 'expired' => '已过期', 'cancelled' => '已取消'][$c->status] ?? $c->status }}
                                </span>
                            </td>
                            <td class="px-4 py-3 text-xs text-gray-500">
                                {{ $c->ceremony_at?->format('Y-m-d H:i') }}
                            </td>
                            <td class="px-4 py-3 text-center">
                                @if ($c->total_amount > 0)
                                    <a href="{{ route('admin.marriages.claim-detail', $c->id) }}"
                                        class="text-xs text-indigo-600 hover:underline font-bold">明细</a>
                                @else
                                    <span class="text-gray-300 text-xs">—</span>
                                @endif
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="9" class="px-4 py-12 text-center text-gray-400">暂无婚礼记录</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if ($ceremonies->hasPages())
            <div class="px-4 py-4 border-t">{{ $ceremonies->links() }}</div>
        @endif
    </div>

@endsection
