<?php
require 'session.php';
require 'db.php';

$usuario = $_SESSION['usuario'];

if ($usuario['permissao'] === 'superadmin') {
    $stmt = $pdo->query("SELECT * FROM clientes");
} else {
    $stmt = $pdo->prepare("SELECT * FROM clientes WHERE tenant_id = ?");
    $stmt->execute([$usuario['tenant_id']]);
}

$clientes = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>

<h2>Clientes</h2>
<ul>
<?php foreach ($clientes as $c): ?>
    <li><?= htmlspecialchars($c['Nome_Cliente']) ?> (tenant_id: <?= $c['tenant_id'] ?>)</li>
<?php endforeach; ?>
</ul>

<?php if ($usuario['permissao'] === 'superadmin'): ?>
    <a href="admin/create_tenant.php">Criar novo tenant</a>
<?php endif; ?>
