@extends('admin.layouts.app')

@section('title', "双色球第 {$issue->issue_no} 期购买明细")

@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 }}">🎟️ 双色球第 {{ $issue->issue_no }} 期购买明细</h2>
                <p class="{{ $adminListHeaderSubtitleClass }}">
                    开奖时间：{{ $issue->draw_at?->format('Y-m-d H:i:s') ?? '未开奖' }}
                    @if ($issue->status === 'settled')
                        &nbsp;·&nbsp;开奖号码：
                        <span class="inline-flex items-center gap-1 font-semibold text-indigo-600">
                            <span class="rounded border border-red-200 bg-red-100 px-1.5 py-0.5 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-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-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-blue-600">{{ str_pad($issue->blue, 2, '0', STR_PAD_LEFT) }}</span>
                        </span>
                    @endif
                    &nbsp;·&nbsp;奖池：<span class="font-semibold text-amber-600">{{ number_format($issue->pool_amount ?? 0) }} 金币</span>
                </p>
            </div>
            <a href="{{ route('admin.game-history.lottery') }}" class="{{ $adminListSecondaryButtonClass }}">
                ← 返回期号列表
            </a>
        </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 }} 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-center">中奖等级</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-right">下注时间</th>
                        </tr>
                    </thead>
                    <tbody class="{{ $adminListTableBodyClass }}">
                        @forelse ($tickets as $ticket)
                            @php
                                $won = ($ticket->payout ?? 0) > 0;
                            @endphp
                            <tr class="{{ $adminListTableRowClass }} {{ $won ? 'bg-amber-50/50' : '' }}">
                                <td class="{{ $tableCellClass }} {{ $adminListPrimaryTextClass }}">
                                    {{ $ticket->user?->username ?? '已注销' }}
                                </td>
                                <td class="{{ $tableCellClass }} text-center {{ $adminListNumericTextClass }}">
                                    <div class="flex flex-wrap items-center justify-center gap-1">
                                        <span class="rounded border border-red-100 bg-red-50 px-1.5 py-0.5 text-xs text-red-500">{{ str_pad($ticket->red1, 2, '0', STR_PAD_LEFT) }}</span>
                                        <span class="rounded border border-red-100 bg-red-50 px-1.5 py-0.5 text-xs text-red-500">{{ str_pad($ticket->red2, 2, '0', STR_PAD_LEFT) }}</span>
                                        <span class="rounded border border-red-100 bg-red-50 px-1.5 py-0.5 text-xs text-red-500">{{ str_pad($ticket->red3, 2, '0', STR_PAD_LEFT) }}</span>
                                        <span class="rounded border border-blue-100 bg-blue-50 px-1.5 py-0.5 text-xs text-blue-500">{{ str_pad($ticket->blue, 2, '0', STR_PAD_LEFT) }}</span>
                                    </div>
                                </td>
                                <td class="{{ $tableCellClass }} text-center">
                                    @if ($ticket->is_quick_pick)
                                        <span class="{{ $badgeClass }} border-purple-200 bg-purple-100 text-purple-700">随机机选</span>
                                    @else
                                        <span class="{{ $badgeClass }} border-blue-200 bg-blue-100 text-blue-700">自选号码</span>
                                    @endif
                                </td>
                                <td class="{{ $tableCellClass }} text-right {{ $adminListNumericTextClass }} text-gray-700">
                                    {{ number_format($ticket->amount) }}
                                </td>
                                <td class="{{ $tableCellClass }} text-right {{ $adminListNumericTextClass }} {{ $won ? 'font-semibold text-emerald-600' : 'text-gray-400' }}">
                                    {{ $won ? '+' . number_format($ticket->payout) : '0' }}
                                </td>
                                <td class="{{ $tableCellClass }} text-center">
                                    @if ($issue->status === 'settled')
                                        @if ($won)
                                            <span class="{{ $badgeClass }} border-amber-200 bg-amber-100 text-amber-700">🎉 {{ $ticket->prize_level }}等奖</span>
                                        @else
                                            <span class="{{ $badgeClass }} border-gray-200 bg-gray-100 text-gray-500">未中奖</span>
                                        @endif
                                    @else
                                        <span class="{{ $adminListSecondaryTextClass }}">等待开奖</span>
                                    @endif
                                </td>
                                <td class="{{ $tableCellClass }} text-right {{ $adminListSecondaryTextClass }}">
                                    {{ $ticket->created_at->format('H:i:s') }}
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="7" class="{{ $adminListEmptyClass }}">本期暂无人购买</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

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