@extends('public.resultados.layout')
@section('title', 'Records por Categoria')
@section('content')

<div class="stats">
    <div class="stat">
        <div class="stat-num">{{ $total }}</div>
        <div class="stat-lbl">Categorias</div>
    </div>
    <div class="stat gold">
        <div class="stat-num">{{ $quebrados }}</div>
        <div class="stat-lbl">Novos Records</div>
    </div>
</div>

<div class="card">
    <form method="GET" action="{{ route('public.resultados.records') }}" class="search-bar">
        <input type="text" name="q" value="{{ $busca }}"
               placeholder="Buscar categoria ou callsign...">
        <button type="submit">🔍 Buscar</button>
        @if($busca)
            <a href="{{ route('public.resultados.records') }}"
               style="padding:.45rem .8rem;color:#666;text-decoration:none;font-size:.88rem">✕ Limpar</a>
        @endif
    </form>

    <table>
        <thead>
            <tr>
                <th>Categoria</th>
                <th>Campeão Anterior</th>
                <th style="text-align:right">Score Anterior</th>
                <th>Campeão Atual</th>
                <th style="text-align:right">Score Atual</th>
                <th style="text-align:center">Situação</th>
            </tr>
        </thead>
        <tbody>
            @foreach($records as $r)
                @php
                    $novo = ($r->final_score_atu_display ?? 0) > ($r->final_score_ant ?? 0);
                @endphp
                <tr class="{{ $novo ? 'ouro' : '' }}">
                    <td style="font-weight:600;font-size:.8rem">{{ $r->category }}</td>
                    <td class="call" style="font-size:.82rem">
                        {{ $r->callsign_ant ?? '—' }}
                        @if($r->name_ant) <span style="font-weight:normal;color:#666"> — {{ $r->name_ant }}</span> @endif
                    </td>
                    <td class="score" style="color:#555">
                        {{ $r->final_score_ant ? number_format($r->final_score_ant) : '—' }}
                    </td>
                    <td class="call" style="font-size:.82rem">
                        @if($r->callsign_atu_display)
                            <a href="{{ route('public.resultados.callsign', ['callsign' => $r->callsign_atu_display]) }}"
                               style="color:#1B4F8C;text-decoration:none">{{ $r->callsign_atu_display }}</a>
                            @if($r->name_atu_display) <span style="font-weight:normal;color:#666"> — {{ $r->name_atu_display }}</span> @endif
                        @else
                            —
                        @endif
                    </td>
                    <td class="score" style="color:{{ $novo ? '#2E7D32' : '#555' }};font-weight:{{ $novo ? '900' : '400' }}">
                        {{ $r->final_score_atu_display ? number_format($r->final_score_atu_display) : '—' }}
                    </td>
                    <td style="text-align:center">
                        @if($novo)
                            <span class="badge-novo">🏆 NOVO RECORDE</span>
                        @elseif($r->final_score_atu_display)
                            <span style="font-size:.75rem;color:#888">Mantido</span>
                        @else
                            <span style="font-size:.75rem;color:#ccc">—</span>
                        @endif
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
</div>
@endsection
