<?php
$roulette=new \Plugin\NexoraRoulette\NexoraRoulette();
$status=isset($_GET['status'])?preg_replace('/[^a-z_]/','',(string)$_GET['status']):'';
$allowed=array('','awarded','pending_item','claimed','pending_manual','manual_delivered'); if(!in_array($status,$allowed,true)) $status='';
$rows=$roulette->adminSpins(500,$status);
$rarities=\Plugin\NexoraRoulette\NexoraRoulette::rarityLabels();
?>
<h1 class="page-header">Historial de Ruleta <small><?php echo htmlspecialchars($roulette->getRealmLabel(),ENT_QUOTES,'UTF-8'); ?></small></h1>
<div class="btn-group" style="margin-bottom:16px"><a class="btn btn-default <?php echo $status===''?'active':''; ?>" href="<?php echo admincp_base('nexoraroulette&page=logs'); ?>">Todos</a><a class="btn btn-default <?php echo $status==='awarded'?'active':''; ?>" href="<?php echo admincp_base('nexoraroulette&page=logs&status=awarded'); ?>">Acreditados</a><a class="btn btn-default <?php echo $status==='pending_item'?'active':''; ?>" href="<?php echo admincp_base('nexoraroulette&page=logs&status=pending_item'); ?>">Ítems pendientes</a><a class="btn btn-default <?php echo $status==='pending_manual'?'active':''; ?>" href="<?php echo admincp_base('nexoraroulette&page=logs&status=pending_manual'); ?>">Manual pendiente</a></div>
<div class="table-responsive"><table class="table table-striped table-hover"><thead><tr><th>ID</th><th>Cuenta</th><th>Costo</th><th>Premio</th><th>Rareza</th><th>Estado</th><th>Roll</th><th>Pity</th><th>Saldo</th><th>Fecha</th></tr></thead><tbody>
<?php if(!$rows){ ?><tr><td colspan="10" class="text-muted">Sin giros registrados para este filtro.</td></tr><?php } ?>
<?php foreach($rows as $row){ ?><tr>
<td>#<?php echo (int)$row['id']; ?><br><small><?php echo htmlspecialchars($row['spin_token'],ENT_QUOTES,'UTF-8'); ?></small></td>
<td><?php echo htmlspecialchars($row['account_username'],ENT_QUOTES,'UTF-8'); ?><br><small><?php echo htmlspecialchars($row['ip_address'],ENT_QUOTES,'UTF-8'); ?></small></td>
<td><?php echo !empty($row['used_free_spin'])?'<span class="label label-primary">Giro gratis</span>':number_format((int)$row['cost']); ?></td>
<td><strong><?php echo htmlspecialchars($row['prize_name'],ENT_QUOTES,'UTF-8'); ?></strong><br><small><?php echo htmlspecialchars($row['prize_type'],ENT_QUOTES,'UTF-8'); ?><?php if((int)$row['prize_amount']>0) echo ' · '.number_format((int)$row['prize_amount']); ?></small></td>
<td><?php echo htmlspecialchars($rarities[$row['rarity']]??$row['rarity'],ENT_QUOTES,'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['status'],ENT_QUOTES,'UTF-8'); ?></td>
<td><?php echo number_format((int)$row['roll_value']).' / '.number_format((int)$row['total_weight']); ?></td>
<td><?php echo (int)$row['pity_before'].' → '.(int)$row['pity_after']; ?></td>
<td><?php echo $row['balance_before']===null?'—':number_format((int)$row['balance_before']); ?> → <?php echo $row['balance_after']===null?'—':number_format((int)$row['balance_after']); ?></td>
<td><?php echo htmlspecialchars((string)$row['created_at'],ENT_QUOTES,'UTF-8'); ?></td>
</tr><?php } ?>
</tbody></table></div>
<p class="text-muted">Se muestran hasta 500 registros recientes del reino operativo.</p>
