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

$id = intval($_GET['id'] ?? 0);
$f = ['nome'=>''];

if ($id > 0) {
    $stmt = $pdo->prepare("SELECT * FROM formas_pagamento WHERE id = :id");
    $stmt->execute(['id' => $id]);
    $f = $stmt->fetch() ?: $f;
}
$titulo = $id > 0 ? 'Editar Forma de Pagamento' : 'Nova Forma de Pagamento';
?>

<div class="page-header">
    <div><h2><?= $titulo ?></h2><div class="subtitle">Preencha os dados</div></div>
    <div><a href="formas_pagamento.php" class="btn btn-secondary">Voltar</a></div>
</div>

<form method="POST" action="forma_pagamento_salvar.php">
<input type="hidden" name="id" value="<?= $id ?>">

<div class="card-premium" style="padding:25px;margin-bottom:20px;">
    <h3 style="color:var(--accent);margin-bottom:15px;border-bottom:1px solid var(--border);padding-bottom:10px;">Dados da Forma de Pagamento</h3>
    <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(300px,1fr));gap:15px;">
        <div class="form-group"><label>Nome *</label><input name="nome" value="<?= sanitize($f['nome']) ?>" required></div>
    </div>
</div>

<div style="display:flex;gap:10px;justify-content:flex-end;margin-bottom:30px;">
    <a href="formas_pagamento.php" class="btn btn-secondary">Cancelar</a>
    <button type="submit" class="btn btn-novo">Salvar</button>
</div>
</form>

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