@extends('base.base')
@section('base')

<div class="main-panel">
    <div class="content-wrapper">
        <div class="page-header">
            <h3 class="page-title">
                <span class="page-title-icon bg-gradient-primary text-white mr-2">
                    <i class="mdi mdi-trophy"></i>
                </span>
                游戏输赢排行榜
            </h3>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="#">数据管理</a></li>
                    <li class="breadcrumb-item active" aria-current="page">游戏输赢排行榜</li>
                </ol>
            </nav>
        </div>

        <div class="col-lg-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <!-- 搜索表单 -->
                    <form method="GET" action="/admin/game_data/winlose_rank" class="forms-sample">
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="game_id">选择游戏</label>
                                    <select class="form-control" id="game_id" name="game_id" required>
                                        <option value="">请选择游戏</option>
                                        @foreach($games as $id => $name)
                                            <option value="{{ $id }}" {{ $gameId == $id ? 'selected' : '' }}>
                                                {{ $name }}
                                            </option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="date">查询日期</label>
                                    <input type="date" class="form-control" id="date" name="date" 
                                           value="{{ $date }}" required>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="type">排行类型</label>
                                    <select class="form-control" id="type" name="type">
                                        <option value="win" {{ $type == 'win' ? 'selected' : '' }}>赢分榜（≥100元）</option>
                                        <option value="lose" {{ $type == 'lose' ? 'selected' : '' }}>输分榜（≤-100元）</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group" style="margin-top: 30px;">
                                    <button type="submit" class="btn btn-gradient-primary mr-2">查询</button>
                                    <button type="reset" class="btn btn-light" onclick="resetForm()">重置</button>
                                </div>
                            </div>
                        </div>
                    </form>

                    @if(!empty($rankData))
                    <!-- 结果统计 -->
                    <div class="row mb-3">
                        <div class="col-md-12">
                            <div class="alert alert-info">
                                <strong>查询结果：</strong>
                                {{ count($rankData) }} 个用户符合条件 
                                （{{ $games[$gameId] ?? '未知游戏' }} - {{ $date }} - 
                                {{ $type == 'win' ? '赢分榜' : '输分榜' }}）
                            </div>
                        </div>
                    </div>

                    <!-- 排行榜表格 -->
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>排名</th>
                                    <th>用户ID</th>
                                    <th>昵称</th>
                                    <th>渠道</th>
                                    <th>注册日期</th>
                                    <th>最后登录</th>
                                    <th>输赢金额（元）</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($rankData as $item)
                                <tr>
                                    <td>
                                        @if($item['rank'] <= 3)
                                            <span class="badge badge-{{ $item['rank'] == 1 ? 'warning' : ($item['rank'] == 2 ? 'secondary' : 'info') }}">
                                                {{ $item['rank'] }}
                                            </span>
                                        @else
                                            {{ $item['rank'] }}
                                        @endif
                                    </td>
                                    <td>{{ $item['game_id'] }}</td>
                                    <td>{{ $item['nick_name'] }}</td>
                                    <td>{{ $item['channel'] }}</td>
                                    <td>{{ $item['register_date'] }}</td>
                                    <td>{{ $item['last_logon_date'] }}</td>
                                    <td>
                                        <span class="badge badge-{{ $item['raw_amount'] > 0 ? 'success' : 'danger' }}">
                                            {{ $item['total_amount'] }}
                                        </span>
                                    </td>
                                    <td>
                                        <a href="/admin/global/id_find?UserID={{ $item['user_id'] }}" 
                                           class="btn btn-sm btn-gradient-primary" target="_blank">
                                            查看详情
                                        </a>
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    @else
                    <div class="alert alert-warning">
                        <strong>提示：</strong>请选择游戏和日期进行查询
                    </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>

<script>
function resetForm() {
    document.getElementById('game_id').value = '';
    document.getElementById('date').value = '{{ date("Y-m-d") }}';
    document.getElementById('type').value = 'win';
}
</script>

<style>
.table th {
    background-color: #f8f9fa;
    font-weight: 600;
    border-top: none;
}

.badge-warning {
    background-color: #ffc107 !important;
}

.badge-secondary {
    background-color: #6c757d !important;
}

.badge-info {
    background-color: #17a2b8 !important;
}

.alert {
    border-radius: 10px;
}

.card {
    border-radius: 15px;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
}
</style>

@endsection 