<?php
include '../config.php'; 
include '../header.php'; 

// LÓGICA PARA EXCLUIR
if(isset($_GET['del'])) {
    $id = intval($_GET['del']);
    $conn->query("DELETE FROM lista_desejos WHERE id = $id");
    echo "<script>window.location.href='desistencias.php';</script>";
    exit;
}

$result = $conn->query("SELECT * FROM lista_desejos WHERE status = 'Desistência' ORDER BY id DESC");
?>

<style>
    /* Aplica cor preta apenas nas células de dados (corpo da tabela) */
    .table tbody td, .table tbody td small { color: #000000 !important; }
    h6 { color: #000000 !important; }
</style>

<div class="container mt-2" style="max-width: 600px;">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h6>❌ LISTA DE DESISTÊNCIAS</h6>
        <a href="pedidos.php" class="btn btn-dark btn-sm">VOLTAR</a>
    </div>

    <table class="table table-sm table-striped bg-white shadow-sm small">
        <thead class="thead-dark">
            <tr>
                <th>QUEM</th>
                <th>ITEM</th>
                <th>MOTIVO</th>
                <th class="text-center">AÇÃO</th>
            </tr>
        </thead>
        <tbody>
            <?php while($row = $result->fetch_assoc()): ?>
            <tr>
                <td class="font-weight-bold"><?php echo strtoupper($row['responsavel']); ?></td>
                <td><?php echo $row['item']; ?></td>
                <td>
                    <small><?php echo !empty($row['observacao']) ? $row['observacao'] : 'Não informado'; ?></small>
                </td>
                <td class="text-center">
                    <a href="desistencias.php?del=<?php echo $row['id']; ?>" class="text-danger" onclick="return confirm('Excluir permanentemente?')">
                        <i class="fas fa-trash"></i>
                    </a>
                </td>
            </tr>
            <?php endwhile; ?>
        </tbody>
    </table>
</div>

<?php include '../footer.php'; ?>