{{--
    文件功能：求婚记录页（含取消操作）

    @author   ChatRoom Laravel
    @version  1.0.0
--}}

@extends('admin.layouts.app')

@section('title', '求婚记录')

@section('content')
    @php require resource_path('views/admin/partials/list-theme.php'); @endphp

    <div class="{{ $adminListPageClass }}">
        <div class="{{ $adminListHeaderCardClass }}">
            <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
                <div>
                    <h2 class="{{ $adminListHeaderTitleClass }}">💌 求婚记录</h2>
                    <p class="{{ $adminListHeaderSubtitleClass }}">统一查看求婚进度，并保留婚姻状态语义色彩。</p>
                </div>
                <a href="{{ route('admin.marriages.index') }}" class="{{ $adminListSecondaryButtonClass }}">返回总览</a>
            </div>
        </div>

        <div class="{{ $adminListCardClass }}">
            <div class="{{ $adminListSectionHeadClass }}">
                <div>
                    <h3 class="{{ $adminListSectionTitleClass }}">求婚列表</h3>
                    <p class="{{ $adminListSectionDescClass }}">列表布局、表头、按钮与分页对齐后台统一风格。</p>
                </div>
            </div>
            <div class="{{ $adminListTableWrapClass }}">
                <table class="{{ $adminListTableClass }}">
                    <thead>
                        <tr class="{{ $adminListTableHeadRowClass }}">
                            <th class="{{ $adminListTableHeadCellClass }}">ID</th>
                            <th class="{{ $adminListTableHeadCellClass }}">发起方</th>
                            <th class="{{ $adminListTableHeadCellClass }}">目标</th>
                            <th class="{{ $adminListTableHeadCellClass }}">戒指</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-center">状态</th>
                            <th class="{{ $adminListTableHeadCellClass }}">求婚时间</th>
                            <th class="{{ $adminListTableHeadCellClass }}">过期时间</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-center">操作</th>
                        </tr>
                    </thead>
                    <tbody class="{{ $adminListTableBodyClass }}">
                        @forelse ($proposals as $p)
                            <tr class="{{ $adminListTableRowClass }}">
                                <td class="px-4 py-3 {{ $adminListSecondaryTextClass }} {{ $adminListNumericTextClass }}">{{ $p->id }}</td>
                                <td class="px-4 py-3 {{ $adminListPrimaryTextClass }}">{{ $p->user?->username }}</td>
                                <td class="px-4 py-3 {{ $adminListPrimaryTextClass }}">{{ $p->partner?->username }}</td>
                                <td class="px-4 py-3 {{ $adminListBodyTextClass }}">{{ $p->ringItem?->icon }} {{ $p->ringItem?->name ?? '—' }}</td>
                                <td class="px-4 py-3 text-center">
                                    <span
                                        class="{{ $adminListBadgeBaseClass }} {{ match ($p->status) {
                                            'pending' => 'border-amber-200 bg-amber-100 text-amber-700',
                                            'rejected' => 'border-red-200 bg-red-100 text-red-600',
                                            'expired' => 'border-gray-200 bg-gray-100 text-gray-500',
                                            'married' => 'border-emerald-200 bg-emerald-100 text-emerald-700',
                                            'divorced' => 'border-purple-200 bg-purple-100 text-purple-700',
                                            default => 'border-gray-200 bg-gray-100 text-gray-600',
                                        } }}">
                                        {{ ['pending' => '⏳ 等待中', 'rejected' => '❌ 已拒绝', 'expired' => '⏰ 已过期', 'married' => '✅ 已结婚', 'divorced' => '💔 已离婚'][$p->status] ?? $p->status }}
                                    </span>
                                </td>
                                <td class="px-4 py-3 {{ $adminListSecondaryTextClass }}">{{ $p->proposed_at?->format('Y-m-d H:i') }}</td>
                                <td class="px-4 py-3 text-xs {{ $p->expires_at?->isPast() ? 'text-red-400' : 'text-gray-500' }}">
                                    {{ $p->expires_at?->format('Y-m-d H:i') }}
                                    @if ($p->status === 'pending' && $p->expires_at?->isPast())
                                        <span class="text-red-500">（已超时）</span>
                                    @endif
                                </td>
                                <td class="px-4 py-3 text-center">
                                @if ($p->status === 'pending')
                                    <form action="{{ route('admin.marriages.cancel-proposal', $p->id) }}" method="POST"
                                        data-admin-confirm="确定取消该求婚吗？">
                                        @csrf
                                        <button type="submit"
                                            class="{{ $adminListActionButtonClass }} bg-amber-50 text-amber-600 hover:bg-amber-600 hover:text-white">
                                            取消求婚
                                        </button>
                                    </form>
                                @else
                                    <span class="text-gray-300 text-xs">—</span>
                                @endif
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="8" class="{{ $adminListEmptyClass }}">暂无求婚记录</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            @if ($proposals->hasPages())
                <div class="{{ $adminListPaginationClass }}">{{ $proposals->links() }}</div>
            @endif
        </div>
    </div>

@endsection
