<?php
$title = 'Panel Cliente';
require_once __DIR__ . '/../templates/header.php';
require_role('client');
$u = current_user();

$expires_at = $u['expires_at'] ?? null;
$days_left = null;

if ($expires_at) {
    $now = new DateTime();
    $expires = new DateTime($expires_at);
    $diff = $now->diff($expires);
    $days = ($expires >= $now) ? $diff->days : 0;

    if ($days > 0) {
       $days_left = 'Te quedan ' . $days . ' días de suscripción';


    } else {
        $days_left = "Hoy finaliza tu suscripción";
    }
}
?>
<div class="my-4 text-start px-3">
  <h3>Bienvenido: <?= e($u['name'] ?? 'Usuario') ?></h3>
  <?php if ($expires_at): ?>
    <div style="font-size: 1rem; font-weight: normal; margin-top: 10px;">
      <?= e($days_left) ?>
    </div>
  <?php endif; ?>
</div>
<div class="row g-3">
  <div class="col-md-4">
    <div class="card shadow-sm">
      <div class="card-body">
        <h5>Consultar</h5>
        <p class="text-muted small">Elige plataforma e ingresa el correo de la cuenta.</p>
        <a class="btn btn-primary btn-sm" href="request_code.php">Abrir</a>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <div class="card shadow-sm">
      <div class="card-body">
        <h5>Resumen de cuentas</h5>
        <p class="text-muted small">Protegido con PIN.</p>
        <a class="btn btn-primary btn-sm" href="assigned_summary.php">Abrir</a>
      </div>
    </div>
  </div>
</div>
<?php require_once __DIR__ . '/../templates/footer.php'; ?>
