<?php
/** Replay animado público baseado em métricas; o vídeo original não é armazenado. */
require_once __DIR__.'/../config/config.php';
require_once __DIR__.'/../config/database.php';
require_once __DIR__.'/../includes/functions.php';
require_once __DIR__.'/../includes/match_functions.php';
$token=strtolower(preg_replace('/[^a-f0-9]/','',(string)($_GET['t']??'')));
$p=afBuscarResultadoPublico($pdo,$token);
if($p && !afCanPublishUserContent($pdo,(int)$p['usuario_id']))$p=null;
if(!$p){http_response_code(404);}
$eventos=[];
if($p){
 afRegistrarVisitaViral($pdo,(int)$p['id'],null,'replay');
 $st=$pdo->prepare("SELECT tipo,valor,dados,criado_em FROM af_partida_eventos WHERE partida_id=? AND tipo IN ('pose','combo','movimento_especial','combo_sequencia','perfect_chain','evolucao_aura','aura_maxima','like','super_like','fim') ORDER BY id ASC LIMIT 80");
 $st->execute([(int)$p['id']]);$eventos=$st->fetchAll();
}
$payload=$p?['player'=>['nome'=>$p['nome'],'aura_id'=>$p['aura_id'],'avatar'=>urlAvatar($p['foto_perfil']??null,$p['foto_externa']??null)],'score'=>(float)$p['pontuacao_total'],'aura'=>(float)$p['aura_gerada'],'likes'=>(int)$p['likes_recebidos'],'superlikes'=>(int)$p['superlikes_recebidos'],'combo'=>(int)$p['combo_maximo'],'grade'=>(string)($p['combo_nota']??'D'),'rank'=>(int)($p['ranking_global_posicao']??0),'events'=>$eventos,'share'=>SITE_URL.'/pages/compartilhar.php?t='.$token]:[];
?><!DOCTYPE html><html lang="pt-BR"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><title>Replay de Aura | Aura Farming</title><meta name="app-base-url" content="<?=esc(SITE_URL)?>"><link rel="stylesheet" href="<?=SITE_URL?>/assets/css/style.css?v=11.0"></head><body class="replay-body"><div class="particles"></div>
<main class="replay-shell"><?php if(!$p):?><section class="viral-public-card"><h1>REPLAY NÃO ENCONTRADO</h1><a class="btn btn-primary" href="<?=SITE_URL?>">ABRIR AURA FARMING</a></section><?php else:?><section class="replay-stage" data-replay-stage><canvas width="1080" height="1920" data-replay-canvas></canvas><div class="replay-controls"><button class="btn btn-primary" data-replay-start>▶ REPRODUZIR</button><button class="btn btn-outline-cyan" data-replay-record>🎬 GERAR VÍDEO-RESUMO</button><a class="btn btn-secondary" href="<?=esc($payload['share'])?>">VER CARD COMPLETO</a></div><div class="share-feedback" data-replay-feedback></div></section><script type="application/json" id="replay-data"><?=json_encode($payload,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)?></script><script src="<?=SITE_URL?>/assets/js/replay.js?v=11.0"></script><?php endif;?></main></body></html>
