@extends('layouts.app') @section('title','Rankings - GIGAX ARENA') @section('page_title','Rankings') @php use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Route; $groups = [ 'fila'=>['open'=>'OPEN','ranked'=>'RANKED','liga'=>'LIGA'], 'modalidades'=>['custom_x1'=>'X1','custom_x2'=>'X2','custom_x3'=>'X3','custom_x4'=>'X4','custom_x5'=>'X5','custom_x6'=>'X6','custom_x7'=>'X7','custom_x8'=>'X8','team_5l'=>'5L','c1s'=>'C1S / DM','awp'=>'AWP','mf'=>'MF'], 'progresso'=>['xp'=>'XP MENSAL'], ]; $all = array_merge(...array_values($groups)); $chosen = strtolower(trim((string) request()->query('rank','open'))); if(!array_key_exists($chosen,$all)) $chosen='open'; $group = in_array($chosen,array_keys($groups['modalidades']),true)?'modalidades':($chosen==='xp'?'progresso':'fila'); $isMode=$group==='modalidades'; $rows=collect(); $error=null; $scoreLabel=$isMode?'PTS':'XP'; try { if (!Schema::hasTable('users')) throw new \RuntimeException('Tabela users indisponível'); if($isMode) { if(!Schema::hasTable('gigax_player_mode_stats')) throw new \RuntimeException('Ranking da modalidade ainda não configurado'); $rows=DB::table('gigax_player_mode_stats as s') ->join('users as u','u.id','=','s.user_id') ->where('s.mode_code',$chosen) ->select('u.id','u.nickname','u.avatar_url','u.skill_level','s.points as score','s.matches_played as matches','s.wins','s.losses','s.kills','s.deaths','s.current_streak') ->orderByDesc('s.points')->orderByDesc('s.wins')->orderBy('u.nickname') ->limit(100)->get(); } else { if(!Schema::hasTable('gx_player_experience')) throw new \RuntimeException('Ranking mensal ainda não configurado'); $rows=DB::table('gx_player_experience as x') ->join('users as u','u.id','=','x.user_id') ->where('x.monthly_xp','>',0) ->select('u.id','u.nickname','u.avatar_url','u.skill_level','x.monthly_xp as score') ->orderByDesc('x.monthly_xp')->orderBy('u.nickname')->limit(100)->get(); } } catch(\Throwable $e) { \Illuminate\Support\Facades\Log::warning('GIGAX Ranking Hub: consulta indisponivel',['rank'=>$chosen,'error'=>$e->getMessage()]); $error='Classificação temporariamente indisponível.'; } $myId=(int)(auth()->id()??0); $myPosition=$rows->search(fn($p)=>(int)$p->id===$myId); $myPlayer=$myPosition!==false?$rows->get($myPosition):null; @endphp @push('styles') @endpush @section('content')