<?php
$r=new \Plugin\ReferralSystem\ReferralSystem();
echo '<h2>Referrals — '.htmlspecialchars(NexoraRealm::label(),ENT_QUOTES,'UTF-8').'</h2>';
$sections=array(2=>'Registro pendiente',0=>'En progreso',1=>'Recompensados',3=>'Expirados / no verificados');
foreach($sections as $status=>$title) {
    echo '<h3>'.htmlspecialchars($title,ENT_QUOTES,'UTF-8').'</h3>';
    $rows=$r->getReferralListByStatus($status);
    if(!is_array($rows)){ message('warning','No hay resultados.'); continue; }
    echo '<div class="table-responsive"><table class="table table-bordered table-hover"><thead><tr><th>Invitador</th><th>Personaje</th><th>Referido</th><th>Personaje referido</th><th>Registro</th><th>Última revisión</th><th>Completado</th><th>Recompensado</th></tr></thead><tbody>';
    foreach($rows as $row) {
        echo '<tr>';
        foreach(array('referral_username','referral_character','referred_username','referred_character','referred_registration_date','referred_last_check','referred_complete_date','rewarded_date') as $key) echo '<td>'.htmlspecialchars((string)($row[$key]??''),ENT_QUOTES,'UTF-8').'</td>';
        echo '</tr>';
    }
    echo '</tbody></table></div>';
}
