@extends('admin.layouts.app')

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

@section('content')
    <div class="space-y-6">

        {{-- 页头 --}}
        <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6 flex justify-between items-center">
            <div>
                <h2 class="text-lg font-bold text-gray-800">🎟️ 双色球 第 {{ $issue->issue_no }} 期购买明细</h2>
                <p class="text-xs text-gray-500 mt-1">
                    开奖时间：{{ $issue->draw_at?->format('Y-m-d H:i:s') ?? '未开奖' }}
                    @if ($issue->status === 'settled')
                        &nbsp;·&nbsp;开奖号码：
                        <span class="font-bold text-indigo-600">
                            <span
                                class="bg-red-100 text-red-600 px-1 rounded">{{ str_pad($issue->red1, 2, '0', STR_PAD_LEFT) }}</span>
                            <span
                                class="bg-red-100 text-red-600 px-1 rounded">{{ str_pad($issue->red2, 2, '0', STR_PAD_LEFT) }}</span>
                            <span
                                class="bg-red-100 text-red-600 px-1 rounded">{{ str_pad($issue->red3, 2, '0', STR_PAD_LEFT) }}</span>
                            <span
                                class="bg-blue-100 text-blue-600 px-1 rounded">{{ str_pad($issue->blue, 2, '0', STR_PAD_LEFT) }}</span>
                        </span>
                    @endif
                    &nbsp;·&nbsp;奖池：<span class="font-bold text-amber-600">{{ number_format($issue->pool_amount ?? 0) }}
                        金币</span>
                </p>
            </div>
            <a href="{{ route('admin.game-history.lottery') }}"
                class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg text-sm font-bold hover:bg-gray-200 transition">
                ← 返回期号列表
            </a>
        </div>

        {{-- 购买明细表 --}}
        <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
            <table class="w-full text-sm">
                <thead class="bg-gray-50 border-b border-gray-100">
                    <tr>
                        <th class="px-4 py-3 text-left text-xs font-bold text-gray-500 uppercase">玩家</th>
                        <th class="px-4 py-3 text-center text-xs font-bold text-gray-500 uppercase">投注号码</th>
                        <th class="px-4 py-3 text-center text-xs font-bold text-gray-500 uppercase">彩票类型</th>
                        <th class="px-4 py-3 text-right text-xs font-bold text-gray-500 uppercase">花费</th>
                        <th class="px-4 py-3 text-right text-xs font-bold text-gray-500 uppercase">奖金获得</th>
                        <th class="px-4 py-3 text-center text-xs font-bold text-gray-500 uppercase">中奖等级</th>
                        <th class="px-4 py-3 text-right text-xs font-bold text-gray-500 uppercase">下注时间</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-50">
                    @forelse ($tickets as $ticket)
                        @php
                            $won = ($ticket->payout ?? 0) > 0;
                        @endphp
                        <tr class="hover:bg-gray-50 transition {{ $won ? 'bg-amber-50/50' : '' }}">
                            <td class="px-4 py-3 font-medium text-gray-800">
                                {{ $ticket->user?->username ?? '已注销' }}
                            </td>
                            <td class="px-4 py-3 text-center font-mono">
                                <div class="flex items-center justify-center gap-1 flex-wrap">
                                    <span
                                        class="text-xs bg-red-50 text-red-500 px-1 rounded shadow-sm border border-red-100">{{ str_pad($ticket->red1, 2, '0', STR_PAD_LEFT) }}</span>
                                    <span
                                        class="text-xs bg-red-50 text-red-500 px-1 rounded shadow-sm border border-red-100">{{ str_pad($ticket->red2, 2, '0', STR_PAD_LEFT) }}</span>
                                    <span
                                        class="text-xs bg-red-50 text-red-500 px-1 rounded shadow-sm border border-red-100">{{ str_pad($ticket->red3, 2, '0', STR_PAD_LEFT) }}</span>
                                    <span
                                        class="text-xs bg-blue-50 text-blue-500 px-1 rounded shadow-sm border border-blue-100">{{ str_pad($ticket->blue, 2, '0', STR_PAD_LEFT) }}</span>
                                </div>
                            </td>
                            <td class="px-4 py-3 text-center">
                                @if ($ticket->is_quick_pick)
                                    <span
                                        class="px-2 py-0.5 rounded-full text-xs font-bold bg-purple-100 text-purple-700">随机机选</span>
                                @else
                                    <span
                                        class="px-2 py-0.5 rounded-full text-xs font-bold bg-blue-100 text-blue-700">自选号码</span>
                                @endif
                            </td>
                            <td class="px-4 py-3 text-right font-mono text-sm text-gray-700">
                                {{ number_format($ticket->amount) }}
                            </td>
                            <td
                                class="px-4 py-3 text-right font-mono text-sm {{ $won ? 'text-emerald-600 font-bold' : 'text-gray-400' }}">
                                {{ $won ? '+' . number_format($ticket->payout) : '0' }}
                            </td>
                            <td class="px-4 py-3 text-center">
                                @if ($issue->status === 'settled')
                                    @if ($won)
                                        <span
                                            class="px-2 py-0.5 rounded-full text-xs font-bold bg-amber-100 text-amber-700">
                                            🎉 {{ $ticket->prize_level }}等奖
                                        </span>
                                    @else
                                        <span
                                            class="px-2 py-0.5 rounded-full text-xs font-bold bg-gray-100 text-gray-500">未中奖</span>
                                    @endif
                                @else
                                    <span class="text-xs text-gray-400">等待开奖</span>
                                @endif
                            </td>
                            <td class="px-4 py-3 text-right text-xs text-gray-400">
                                {{ $ticket->created_at->format('H:i:s') }}
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="7" class="px-4 py-10 text-center text-gray-400 text-sm">本期暂无人购买</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>

            @if ($tickets->hasPages())
                <div class="px-4 py-3 border-t border-gray-100">
                    {{ $tickets->links() }}
                </div>
            @endif
        </div>
    </div>
@endsection
