<?php
require_once 'conexao.php';
require_once 'tenant_manager.php';
require_once 'plano_manager.php';

$tenantManager = new TenantManager($conn);
$planoManager = new PlanoManager($conn);
$tenants = $tenantManager->listarTenants();
?>

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <title>Dashboard de Licenças</title>
    <style>
        body { font-family: Arial, sans-serif; padding: 20px; }
        table { border-collapse: collapse; width: 100%; }
        th, td { padding: 8px 12px; border: 1px solid #ccc; }
        th { background-color: #f2f2f2; }
        .ativa { color: green; font-weight: bold; }
        .inativa { color: red; font-weight: bold; }
    </style>
</head>
<body>
    <h2>Dashboard de Licenças</h2>
    <table>
        <tr>
            <th>Tenant</th>
            <th>Licença</th>
            <th>Plano</th>
            <th>Início</th>
            <th>Fim</th>
        </tr>
        <?php foreach ($tenants as $tenant): 
            $licenca = $tenantManager->getLicencaAtual($tenant['tenant_id']);
            $plano = $licenca ? $planoManager->getPlano($licenca['plano_id']) : null;
            $status = $licenca ? '<span class="ativa">Ativa</span>' : '<span class="inativa">Inativa</span>';
        ?>
        <tr>
            <td><?= htmlspecialchars($tenant['nome']) ?></td>
            <td><?= $status ?></td>
            <td><?= $plano['nome'] ?? '-' ?></td>
            <td><?= $licenca['data_inicio'] ?? '-' ?></td>
            <td><?= $licenca['data_fim'] ?? '-' ?></td>
        </tr>
        <?php endforeach; ?>
    </table>
</body>
</html>
