@extends($baseLayout ?? 'layouts.app-admin')
@section('content')
@php
$data = $report->report_data ?? [];
$score = is_array($data['score_cognitivo'] ?? null) ? $data['score_cognitivo'] : [];
$semaforo = is_array($data['semaforo'] ?? null) ? $data['semaforo'] : [];
$variables = is_array($data['variables_clave'] ?? null) ? $data['variables_clave'] : [];
$diasPeores = is_array($data['ranking_dias_peores'] ?? null) ? $data['ranking_dias_peores'] : [];
$predictivo = is_array($data['modelo_predictivo'] ?? null) ? $data['modelo_predictivo'] : [];
$perfil = is_array($data['perfil_cognitivo'] ?? null) ? $data['perfil_cognitivo'] : [];
$patron = is_array($data['patron_temporal'] ?? null) ? $data['patron_temporal'] : [];
$resumen = $data['resumen_ejecutivo'] ?? '';
$scoreValor = (int) ($score['valor'] ?? 0);
$semaforoColor = $semaforo['color'] ?? 'verde';
$semBg = match($semaforoColor) { 'amarillo'=>'#F59E0B','rojo'=>'#EF4444',default=>'#10B981' };
$semText = match($semaforoColor) { 'amarillo'=>'Fatiga incipiente','rojo'=>'Mal dΓa cognitivo',default=>'Buen rendimiento' };
$semEmoji= match($semaforoColor) { 'amarillo'=>'β οΈ','rojo'=>'π΄',default=>'β
' };
$desglose = is_array($score['desglose'] ?? null) ? $score['desglose'] : [];
$rendVal = (int)(($desglose['rendimiento']['valor'] ?? 0));
$tiempVal= (int)(($desglose['tiempos']['valor'] ?? 0));
$movVal = (int)(($desglose['movimiento']['valor'] ?? 0));
$diasSemana = ['','Lun','Mar','MiΓ©','Jue','Vie','SΓ‘b','Dom'];
$diasSemanaFull = ['','Lunes','Martes','MiΓ©rcoles','Jueves','Viernes','SΓ‘bado','Domingo'];
@endphp
{{-- TOPBAR --}}
Volver
Informe generado el {{ $report->created_at->format('d/m/Y \a \l\a\s H:i') }}
{{-- HERO ββββββββββββββββββββββββββββββββββββββββ --}}
{{-- Datos jugador + resumen --}}
AnΓ‘lisis Cognitivo β KOR
{{ $user->first_name }} {{ $user->last_name }}
{{ $user->association ?? '' }}{{ ($user->position) ? ' Β· '.$user->position : '' }}
@if($resumen)
{{ $resumen }}
@endif
{{-- Score ring --}}
{{-- Semaforo --}}
@if($semaforoColor === 'verde') π’ @elseif($semaforoColor === 'amarillo') π‘ @else π΄ @endif
{{ strtoupper($semText) }}
@if(!empty($semaforo['titulo']))
{{ $semaforo['titulo'] }}
@endif
{{-- ESTADO ACTUAL + TENDENCIA + RECOMENDACION ββββ --}}
@php
$estadoActual = is_array($data['estado_actual'] ?? null) ? $data['estado_actual'] : [];
$tendenciaReciente= is_array($data['tendencia_reciente'] ?? null) ? $data['tendencia_reciente'] : [];
$calendarioOptimo = is_array($data['calendario_optimo'] ?? null) ? $data['calendario_optimo'] : [];
$recomendacionIA = is_array($data['recomendacion_ia'] ?? null) ? $data['recomendacion_ia'] : [];
$eaSem = $estadoActual['semaforo'] ?? '';
$eaBg = match($eaSem){ 'amarillo'=>'#F59E0B','rojo'=>'#EF4444',default=>'#10B981' };
$eaBgLight = match($eaSem){ 'amarillo'=>'#fffbeb','rojo'=>'#fef2f2',default=>'#f0fdf4' };
$tendDir = $tendenciaReciente['direccion'] ?? '';
$tendColor = match($tendDir){ 'empeorando'=>'#EF4444','estable'=>'#6B7280',default=>'#10B981' };
// Iconos compatibles con Font Awesome 5 (fa-arrow-trend-* es solo FA6)
$tendIcon = match($tendDir){ 'empeorando'=>'fa-long-arrow-alt-down','estable'=>'fa-minus',default=>'fa-long-arrow-alt-up' };
$recAccion = $recomendacionIA['accion'] ?? '';
$recUrgencia= $recomendacionIA['urgencia'] ?? 'baja';
$recBg = match($recUrgencia){ 'alta'=>'#fef2f2','media'=>'#fffbeb',default=>'#f0fdf4' };
$recColor = match($recUrgencia){ 'alta'=>'#EF4444','media'=>'#F59E0B',default=>'#10B981' };
$recIcon = match($recAccion){
'descanso' => 'fa-bed',
'competicion' => 'fa-trophy',
'precaucion' => 'fa-exclamation-triangle',
default => 'fa-check-circle',
};
@endphp
{{-- Fila: Estado actual + Tendencia + RecomendaciΓ³n --}}
{{-- Usamos flex-wrap para que si solo hay 1 o 2 tarjetas no queden huecos --}}
@if(!empty($estadoActual) || !empty($tendenciaReciente) || !empty($recomendacionIA))
{{-- Estado actual HOY --}}
@if(!empty($estadoActual))
Estado actual
@if(!empty($estadoActual['basado_en']))
β ΓΊltimos {{ $estadoActual['basado_en'] }} tests
@endif
{{ $estadoActual['titulo'] ?? strtoupper($eaSem) }}
@if(!empty($estadoActual['comparativa']))
{{ $estadoActual['comparativa'] }}
@endif
@if(!empty($estadoActual['descripcion']))
{{ $estadoActual['descripcion'] }}
@endif
@endif
{{-- Tendencia reciente --}}
@if(!empty($tendenciaReciente) && !empty($tendenciaReciente['direccion']))
Tendencia ΓΊltimas 2 semanas
{{ ucfirst($tendDir) }}
@if(!empty($tendenciaReciente['cambio_rendimiento_pct']))
Rendimiento: {{ $tendenciaReciente['cambio_rendimiento_pct'] > 0 ? '+' : '' }}{{ $tendenciaReciente['cambio_rendimiento_pct'] }}%
@if(!empty($tendenciaReciente['cambio_tiempo_pct']))
Β· Tiempo: {{ $tendenciaReciente['cambio_tiempo_pct'] > 0 ? '+' : '' }}{{ $tendenciaReciente['cambio_tiempo_pct'] }}%
@endif
@endif
@if(!empty($tendenciaReciente['descripcion']))
{{ $tendenciaReciente['descripcion'] }}
@endif
@endif
{{-- RecomendaciΓ³n IA --}}
@if(!empty($recomendacionIA))
RecomendaciΓ³n IA
{{ strtoupper($recUrgencia) }}
{{ $recomendacionIA['titulo'] ?? ucfirst($recAccion) }}
@if(!empty($recomendacionIA['descripcion']))
{{ $recomendacionIA['descripcion'] }}
@endif
@endif
@endif
{{-- CALENDARIO SEMANAL --}}
@if(!empty($calendarioOptimo) && !empty($calendarioOptimo['rendimiento_por_dia']))
CuΓ‘ndo rinde mejor β Calendario semanal Γ³ptimo
@if(!empty($calendarioOptimo['recomendacion_horaria']))
{{ $calendarioOptimo['recomendacion_horaria'] }}
@endif
@foreach(range(1,7) as $d)
@php
$dVal = (int)(($calendarioOptimo['rendimiento_por_dia'][$d] ?? $calendarioOptimo['rendimiento_por_dia'][(string)$d] ?? 0));
$dColor = $dVal >= 80 ? '#10B981' : ($dVal >= 65 ? '#F59E0B' : '#EF4444');
$isBest = ($calendarioOptimo['mejor_dia'] ?? null) == $d;
$isWorst= ($calendarioOptimo['peor_dia'] ?? null) == $d;
@endphp
{{ $diasSemana[$d] }}
@if($isBest) β
@endif
@if($isWorst) β @endif
{{ $dVal > 0 ? $dVal : 'β' }}
@endforeach
@if(!empty($calendarioOptimo['mejor_dia']))
β
Mejor dΓa:
{{ $diasSemanaFull[$calendarioOptimo['mejor_dia']] ?? '' }}
@endif
@if(!empty($calendarioOptimo['peor_dia']))
β Peor dΓa:
{{ $diasSemanaFull[$calendarioOptimo['peor_dia']] ?? '' }}
@endif
@if(!empty($calendarioOptimo['mejor_franja']))
Mejor franja:
{{ ucfirst($calendarioOptimo['mejor_franja']) }}
@endif
@endif
{{-- DESGLOSE SCORE + RADAR ββββββββββββββββββββββ --}}
{{-- Barras de desglose --}}
Desglose del Score Cognitivo
@foreach($desglose as $key => $item)
@php
$val = (int)($item['valor'] ?? 0);
$peso = round(($item['peso'] ?? 0) * 100);
$barColor = match($key) { 'rendimiento'=>'#3699FF','tiempos'=>'#10B981','movimiento'=>'#8B5CF6',default=>'#6B7280' };
$icon = match($key){ 'rendimiento'=>'fa-trophy','tiempos'=>'fa-clock','movimiento'=>'fa-running',default=>'fa-chart-bar' };
@endphp
{{ ucfirst($key) }}
peso {{ $peso }}%
{{ $val }}/100
@if(!empty($item['descripcion']))
{{ $item['descripcion'] }}
@endif
@endforeach
@if(!empty($semaforo['descripcion']))
{{ $semaforo['descripcion'] }}
@endif
{{-- GrΓ‘fica radar --}}
{{-- EVOLUCION TEMPORAL ββββββββββββββββββββββββββ --}}
EvoluciΓ³n temporal del rendimiento
@if(!empty($data['evolucion']['tendencia']))
@php
$tend = $data['evolucion']['tendencia'] ?? '';
$tendColor = match($tend){ 'mejorando'=>'#10B981','empeorando'=>'#EF4444',default=>'#6B7280' };
$tendIcon = match($tend){ 'mejorando'=>'fa-long-arrow-alt-up','empeorando'=>'fa-long-arrow-alt-down',default=>'fa-minus' };
@endphp
{{ ucfirst($tend) }}
@endif
{{-- SEMAFORO + VARIABLES CLAVE βββββββββββββββββββ --}}
{{-- Variables clave --}}
Variables clave para este jugador
@forelse($variables as $var)
@php
$imp = $var['impacto'] ?? '';
$impColor = match($imp){ 'alto'=>'#EF4444','medio'=>'#F59E0B',default=>'#3699FF' };
$impBg = match($imp){ 'alto'=>'#fef2f2','medio'=>'#fffbeb',default=>'#eff6ff' };
@endphp
{{ strtoupper($imp) }}
{{ $var['variable'] ?? '' }}
{{ $var['descripcion'] ?? '' }}
@empty
Sin datos.
@endforelse
{{-- Semaforo detalle --}}
Verde β Alto rendimiento, tiempos bajos, poco movimiento
Amarillo β Tiempo sube, rendimiento se mantiene
Rojo β Tiempo alto + movimiento + rendimiento cae
{{-- MODELO PREDICTIVO ββββββββββββββββββββββββββ --}}
@if(!empty($predictivo))
Modelo Predictivo β Detectar fatiga ANTES del fallo
PREDICCIΓN TEMPRANA
@if(!empty($predictivo['predictor_principal']))
Predictor principal
{{ ucfirst($predictivo['predictor_principal']) }}
@endif
@if(!empty($predictivo['descripcion']))
{{ $predictivo['descripcion'] }}
@endif
@if(!empty($predictivo['descripcion_prediccion']))
{{ $predictivo['descripcion_prediccion'] }}
@endif
@if(!empty($predictivo['seΓ±ales_alerta_temprana']))
SeΓ±ales de alerta
@foreach($predictivo['seΓ±ales_alerta_temprana'] as $senal)
{{ $senal }}
@endforeach
@endif
@if(!empty($predictivo['umbral_tiempo_alerta']) || !empty($predictivo['umbral_rotacion_alerta']))
@if(!empty($predictivo['umbral_tiempo_alerta']))
Umbral tiempo
{{ $predictivo['umbral_tiempo_alerta'] }}s
respuesta media
@endif
@if(!empty($predictivo['umbral_rotacion_alerta']))
Umbral rotaciΓ³n
{{ $predictivo['umbral_rotacion_alerta'] }}%
tiempo cabeza
@endif
@endif
@endif
{{-- PATRON TEMPORAL + PEORES DIAS βββββββββββββββ --}}
{{-- Patron temporal --}}
@if(!empty($patron))
Mejor dΓa
{{ $diasSemanaFull[$patron['mejor_dia_semana'] ?? 0] ?? 'N/A' }}
Peor dΓa
{{ $diasSemanaFull[$patron['peor_dia_semana'] ?? 0] ?? 'N/A' }}
Mejor hora
{{ ucfirst($patron['mejor_hora'] ?? 'N/A') }}
@if(!empty($patron['descripcion']))
{{ $patron['descripcion'] }}
@endif
@endif
{{-- Peores dΓas --}}
@if(!empty($diasPeores))
@foreach($diasPeores as $i => $dia)
@php
try { $fd = isset($dia['fecha']) ? \Carbon\Carbon::parse($dia['fecha'])->format('d/m/Y') : 'N/A'; }
catch(\Exception $e) { $fd = 'N/A'; }
$ds = isset($dia['fecha']) ? \Carbon\Carbon::parse($dia['fecha'])->dayOfWeekIso : null;
@endphp
{{ $i+1 }}
{{ $fd }}
@if($ds) {{ $diasSemana[$ds] ?? '' }} @endif
{{ $dia['motivo'] ?? '' }}
{{ $dia['score'] ?? '?' }}/100
@endforeach
@endif
{{-- PERFIL COGNITIVO ββββββββββββββββββββββββββββ --}}
@if(!empty($perfil))
@foreach(is_array($perfil['fortalezas'] ?? null) ? $perfil['fortalezas'] : [] as $f)
{{ $f }}
@endforeach
@foreach(is_array($perfil['areas_mejora'] ?? null) ? $perfil['areas_mejora'] : [] as $a)
{{ $a }}
@endforeach
@if(!empty($perfil['descripcion_general']))
{{ $perfil['descripcion_general'] }}
@endif
@endif
{{-- ββ CHAT FLOTANTE ββββββββββββββββββββββββββββββββββββββ --}}