<?php
session_start();
if (!isset($_SESSION['usuario_id'])) {
	header('Location: index.php');
	exit;
}

require_once __DIR__ . '/../app/Core/Database.php';
require_once __DIR__ . '/../app/Controllers/ReporteController.php';

$db = (new Database())->conn;
$controlador = new ReporteController($db);
$reportes = $controlador->mostrarReportesPorUsuario($_SESSION['usuario_id']);
?>
<!DOCTYPE html>
<html lang="es">
<head>
	<meta charset="UTF-8">
	<title>Mis reportes</title>
	<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
	<h2>Reportes disponibles</h2>
	<a href="logout.php" class="btn btn-danger btn-sm float-end">Cerrar sesión</a>
	<table class="table table-bordered mt-4">
		<thead>
			<tr>
				<th>Nombre</th>
				<th>Enlace</th>
			</tr>
		</thead>
		<tbody>
			<?php while($r = $reportes->fetch_assoc()): ?>
			<tr>
				<td><?= htmlspecialchars($r['fullname']) ?></td>
				<td><a href="<?= htmlspecialchars($r['url']) ?>" target="_blank">Ver reporte</a></td>
			</tr>
			<?php endwhile; ?>
		</tbody>
	</table>
</div>
</body>
</html>
