<?php
  include("../protecao_admin.php");
  include("../../conectar_db.php");

  // Consulta para listar os tipos já cadastrados
  $consulta_tipo_busca = "SELECT * FROM imoveis_tipos ORDER BY titulo ASC";
  $con_tipo_busca = mysqli_query($conn, $consulta_tipo_busca);
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Configurações - Tipos de Imóveis</title>
    
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">

    <style>
        body { background-color: #f4f7f6; font-family: 'Inter', sans-serif; }
        .card-custom { border: none; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
        .btn-save { background-color: #28a745; color: white; border: none; font-weight: 600; transition: 0.3s; }
        .btn-save:hover { background-color: #218838; transform: translateY(-2px); }
        .list-group-item { border-left: none; border-right: none; display: flex; justify-content: space-between; align-items: center; transition: 0.2s; }
        .list-group-item:hover { background-color: #f8f9fa; }
        .delete-icon { color: #dc3545; transition: 0.2s; }
        .delete-icon:hover { transform: scale(1.2); color: #a71d2a; }
        .header-section { background: #1a1a1a; color: white; padding: 30px 0; margin-bottom: 40px; }
    </style>
</head>
<body>

<header class="header-section shadow">
    <div class="container d-flex justify-content-between align-items-center">
        <h3 class="m-0">Configurações de Sistema</h3>
        <a href="tela_cadastro_imoveis.php" class="btn btn-outline-light btn-sm"><i class="fas fa-chevron-left me-2"></i>Voltar</a>
    </div>
</header>

<div class="container">
    <div class="row g-4">
        
        <div class="col-md-5">
            <div class="card card-custom p-4">
                <h5 class="fw-bold mb-4 text-primary"><i class="fas fa-plus-circle me-2"></i>Novo Tipo de Imóvel</h5>
                <form action="cadastro_tipo_imoveis.php" method="post">
                    <div class="mb-3">
                        <label class="form-label small fw-bold">Nome do Tipo</label>
                        <input name="tipo_imoveis" type="text" id="tipo_imoveis" class="form-control" placeholder="Ex: Apartamento, Sobrado..." required>
                    </div>
                    <button type="submit" class="btn btn-save w-100 py-2">
                        <i class="fas fa-save me-2"></i>Cadastrar Tipo
                    </button>
                </form>
            </div>
        </div>

        <div class="col-md-7">
            <div class="card card-custom p-4">
                <h5 class="fw-bold mb-4 text-dark"><i class="fas fa-list me-2"></i>Tipos Cadastrados</h5>
                
                <div class="list-group list-group-flush">
                    <?php if(mysqli_num_rows($con_tipo_busca) > 0): ?>
                        <?php while($rows_dado_tipo = mysqli_fetch_array($con_tipo_busca)): ?>
                            <div class="list-group-item px-0 py-3">
                                <div>
                                    <span class="fw-semibold text-secondary"><?= $rows_dado_tipo['titulo']; ?></span>
                                </div>
                                <a href="delete_tipo_imoveis_cad.php?id=<?= $rows_dado_tipo['id']; ?>" 
                                   class="delete-icon" 
                                   onclick="return confirm('Deseja realmente excluir este tipo de imóvel?')">
                                    <i class="fas fa-trash-alt fa-lg"></i>
                                </a>
                            </div>
                        <?php endwhile; ?>
                    <?php else: ?>
                        <div class="text-center py-4 text-muted">
                            <i class="fas fa-folder-open fa-3x mb-3 opacity-25"></i>
                            <p>Nenhum tipo cadastrado até o momento.</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
<?php mysqli_close($conn); ?>