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

$formas = $pdo->query("SELECT * FROM formas_pagamento ORDER BY nome ASC")->fetchAll();
$total = count($formas);
?>

<div class="page-header">
    <div>
        <h2>Formas de Pagamento</h2>
        <div class="subtitle"><?= $total ?> forma(s) cadastrada(s)</div>
    </div>
    <div class="d-flex gap-10">
        <a href="forma_pagamento_form.php" class="btn btn-novo">+ Nova Forma</a>
    </div>
</div>

<div class="card-premium">
<div class="table-responsive">
<table class="table-premium">
<thead>
<tr>
    <th>Nome</th>
    <th>Status</th>
    <th class="text-end">Acoes</th>
</tr>
</thead>
<tbody>
<?php if (empty($formas)): ?>
<tr><td colspan="3" class="text-center text-muted" style="padding:30px;">Nenhuma forma de pagamento encontrada</td></tr>
<?php else: ?>
<?php foreach ($formas as $f): ?>
<tr>
    <td><strong><?= sanitize($f['nome']) ?></strong></td>
    <td>
        <span class="badge <?= ($f['status'] ?? 'Ativo') === 'Ativo' ? 'badge-ativo' : 'badge-inativo' ?>">
            <?= sanitize($f['status'] ?? 'Ativo') ?>
        </span>
    </td>
    <td class="text-end">
        <a href="forma_pagamento_form.php?id=<?= intval($f['id']) ?>" class="btn btn-sm btn-info" title="Editar">&#9998;</a>
        <a href="forma_pagamento_status.php?id=<?= intval($f['id']) ?>" class="btn btn-sm btn-warning" title="Ativar/Inativar">&#9899;</a>
        <a href="forma_pagamento_excluir.php?id=<?= intval($f['id']) ?>" class="btn btn-sm btn-danger" title="Excluir" onclick="return confirm('Deseja excluir esta forma de pagamento?')">&#10005;</a>
    </td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>

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