@extends('admin.layouts.app')

@section('title', '双色球彩票开奖记录')

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

    @php
        $tableCellClass = 'px-4 py-3';
        $badgeClass = $adminListBadgeBaseClass;
    @endphp

    <div class="{{ $adminListPageClass }}">
        <div class="{{ $adminListHeaderCardClass }} flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
            <div>
                <h2 class="{{ $adminListHeaderTitleClass }}">🎟️ 双色球彩票历史记录</h2>
                <p class="{{ $adminListHeaderSubtitleClass }}">查询各期双色球的开奖结果及购买明细。</p>
            </div>
            <a href="{{ route('admin.game-configs.index') }}" class="{{ $adminListSecondaryButtonClass }}">
                ⚙️ 游戏配置
            </a>
        </div>

        <div class="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4">
            <div class="rounded-xl border border-gray-100 bg-white p-5 shadow-sm">
                <div class="text-2xl font-bold text-indigo-600">{{ number_format($summary['total_issues']) }}</div>
                <div class="mt-1 text-xs text-gray-500">历史总期数</div>
            </div>
            <div class="rounded-xl border border-gray-100 bg-white p-5 shadow-sm">
                <div class="text-2xl font-bold text-emerald-600">{{ number_format($summary['drawn_count']) }}</div>
                <div class="mt-1 text-xs text-gray-500">已开奖期数</div>
            </div>
            <div class="rounded-xl border border-gray-100 bg-white p-5 shadow-sm">
                <div class="text-2xl font-bold text-amber-600">{{ number_format($summary['total_tickets']) }}</div>
                <div class="mt-1 text-xs text-gray-500">历史售出彩票</div>
            </div>
            <div class="rounded-xl border border-gray-100 bg-white p-5 shadow-sm">
                <div class="text-2xl font-bold text-rose-600">{{ number_format($summary['total_pool']) }}</div>
                <div class="mt-1 text-xs text-gray-500">历史开奖总奖池</div>
            </div>
        </div>

        <div class="{{ $adminListCardClass }}">
            <div class="{{ $adminListSectionHeadClass }}">
                <div class="{{ $adminListSectionTitleClass }}">期数列表</div>
                <div class="{{ $adminListSectionDescClass }}">统一开奖记录列表结构，保留双色球号码配色和开奖状态语义。</div>
            </div>

            <div class="{{ $adminListTableWrapClass }}">
                <table class="{{ $adminListTableClass }}">
                    <thead>
                        <tr class="{{ $adminListTableHeadRowClass }}">
                            <th class="{{ $adminListTableHeadCellClass }}">期号</th>
                            <th class="{{ $adminListTableHeadCellClass }}">开奖时间</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-center">状态</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-center">开奖号码</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-right">售出票数</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-right">期奖池</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-right">操作</th>
                        </tr>
                    </thead>
                    <tbody class="{{ $adminListTableBodyClass }}">
                        @forelse ($issues as $issue)
                            <tr class="{{ $adminListTableRowClass }}">
                                <td class="{{ $tableCellClass }} {{ $adminListPrimaryTextClass }} font-mono">第 {{ $issue->issue_no }} 期</td>
                                <td class="{{ $tableCellClass }} {{ $adminListBodyTextClass }}">
                                    {{ $issue->draw_at ? $issue->draw_at->format('m-d H:i') : '—' }}
                                </td>
                                <td class="{{ $tableCellClass }} text-center">
                                    @if ($issue->status === 'settled')
                                        <span class="{{ $badgeClass }} border-emerald-200 bg-emerald-100 text-emerald-700">已开奖</span>
                                    @else
                                        <span class="{{ $badgeClass }} border-amber-200 bg-amber-100 text-amber-700">销售中</span>
                                    @endif
                                </td>
                                <td class="{{ $tableCellClass }} text-center {{ $adminListNumericTextClass }}">
                                    @if ($issue->status === 'settled')
                                        <div class="flex flex-wrap items-center justify-center gap-1">
                                            <span class="rounded border border-red-200 bg-red-100 px-1.5 py-0.5 text-xs text-red-600">{{ str_pad($issue->red1, 2, '0', STR_PAD_LEFT) }}</span>
                                            <span class="rounded border border-red-200 bg-red-100 px-1.5 py-0.5 text-xs text-red-600">{{ str_pad($issue->red2, 2, '0', STR_PAD_LEFT) }}</span>
                                            <span class="rounded border border-red-200 bg-red-100 px-1.5 py-0.5 text-xs text-red-600">{{ str_pad($issue->red3, 2, '0', STR_PAD_LEFT) }}</span>
                                            <span class="rounded border border-blue-200 bg-blue-100 px-1.5 py-0.5 text-xs text-blue-600">{{ str_pad($issue->blue, 2, '0', STR_PAD_LEFT) }}</span>
                                        </div>
                                    @else
                                        <span class="{{ $adminListSecondaryTextClass }}">等待开奖</span>
                                    @endif
                                </td>
                                <td class="{{ $tableCellClass }} text-right {{ $adminListNumericTextClass }} font-semibold text-indigo-600">
                                    {{ number_format($issue->total_tickets) }}
                                </td>
                                <td class="{{ $tableCellClass }} text-right {{ $adminListNumericTextClass }} font-semibold text-amber-600">
                                    {{ number_format($issue->pool_amount) }}
                                </td>
                                <td class="{{ $tableCellClass }} text-right">
                                    <a href="{{ route('admin.game-history.lottery.issue', $issue->id) }}"
                                        class="{{ $adminListActionButtonClass }} bg-indigo-50 text-indigo-700 hover:bg-indigo-100">
                                        购买明细
                                    </a>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="7" class="{{ $adminListEmptyClass }}">暂无记录</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            @if ($issues->hasPages())
                <div class="{{ $adminListPaginationClass }}">
                    {{ $issues->links() }}
                </div>
            @endif
        </div>
    </div>
@endsection
