<?php
require_once __DIR__ . '/../includes/header.php';
require_once __DIR__ . '/../config/conexao.php';

$sql = "SELECT * FROM pagamentos ORDER BY id DESC";
$pagamentos = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
?>

<style>
.topo-pagamentos {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.btn-novo {
    background: linear-gradient(45deg,#f7971e,#ffd200);
    border: none;
    padding: 10px 18px;
    color: #000;
    border-radius: 8px;
    font-weight: 600;
}

.card-premium {
    background: linear-gradient(145deg,#0d1b2a,#1b263b);
    border-radius: 15px;
    border: none;
}

.table thead {
    background: #0d1b2a;
}

.table tbody tr {
    border-bottom: 1px solid #415a77;
}
</style>

<div class="container-fluid mt-4">

    <!-- TOPO -->
    <div class="topo-pagamentos">
        <h3 class="text-white m-0">💳 Formas de Pagamento</h3>

        <a href="pagamento_form.php" class="btn-novo">
            + Nova Forma
        </a>
    </div>

    <!-- CARD -->
    <div class="card card-premium shadow-lg">

        <div class="card-body">

            <table class="table table-hover align-middle text-white">

                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Nome</th>
                        <th>Status</th>
                        <th class="text-end">Ações</th>
                    </tr>
                </thead>

                <tbody>

                <?php if(count($pagamentos) > 0): ?>
                    <?php foreach($pagamentos as $p): ?>
                        <tr>

                            <td><?= $p['id'] ?></td>

                            <td>
                                <strong><?= htmlspecialchars($p['nome']) ?></strong>
                            </td>

                            <td>
                                <?php if($p['status']=='ativo'): ?>
                                    <span class="badge bg-success">Ativo</span>
                                <?php else: ?>
                                    <span class="badge bg-secondary">Inativo</span>
                                <?php endif; ?>
                            </td>

                            <td class="text-end">

                                <a href="pagamento_form.php?id=<?= $p['id'] ?>"
                                   class="btn btn-sm btn-outline-info">✏️</a>

                                <a href="pagamento_status.php?id=<?= $p['id'] ?>"
                                   class="btn btn-sm btn-outline-warning">🔄</a>

                                <a href="pagamento_excluir.php?id=<?= $p['id'] ?>"
                                   class="btn btn-sm btn-outline-danger"
                                   onclick="return confirm('Deseja excluir?')">🗑️</a>

                            </td>

                        </tr>
                    <?php endforeach; ?>

                <?php else: ?>
                    <tr>
                        <td colspan="4" class="text-center text-muted py-4">
                            Nenhuma forma de pagamento cadastrada
                        </td>
                    </tr>
                <?php endif; ?>

                </tbody>

            </table>

        </div>
    </div>

</div>

<?php require_once __DIR__ . '/../includes/footer.php'; ?>