<?php require_once ("includes/topo.php"); 


$query = $pdo->query("SELECT COUNT(*) as total FROM leads");
$resultado = $query->fetch(PDO::FETCH_ASSOC);
$total_registros = $resultado['total'];

?>
<link href="vendor/datatables/css/jquery.dataTables.min.css" rel="stylesheet">

<div class="content-body">
    <div class="container-fluid">
        <div class="row">
            <div class="col-xl-12">
                <div class="row">
                    
                    <div class="col-xl-3  col-lg-6 col-sm-6">
						<div class="widget-stat card">
							<div class="card-body p-4">
								<div class="media ai-icon">
									<span class="me-3 bgl-primary text-primary">
										<!-- <i class="ti-user"></i> -->
										<i class="bi bi-people-fill"></i>
									</span>
									<div class="media-body">
										<p class="mb-1">Leads cadastrados</p>
										<h4 class="mb-0"><?php echo $total_registros; ?></h4>
									</div>
								</div>
							</div>
						</div>
                    </div>
                
                <div class="col-lg-12">



                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title">Leads</h4>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table id="example3" class="display" style="min-width: 845px">
                                        <thead>
                                            <tr>
                                                <th></th>
                                                <th>Id</th>
                                                <th>Nome</th>
                                                <th>Telefone</th>
                                                <th>E-mail</th>
                                                <th>Mensagem</th>
                                                <th></th>
                                            </tr>
                                        </thead>
                                        <tbody>

                                            <?php
                                                //PÁGINAS
                                                $query = $pdo->query("SELECT * FROM leads order by id desc");
                                                $lead_entra = $query->fetchAll(PDO::FETCH_ASSOC);
                                                for($i=0; $i < @count($lead_entra); $i++){
                                                foreach ($lead_entra[$i] as $key => $value){}

                                            ?>
                                            <tr>
                                                <td>-</td>
                                                <td><strong><?php echo $lead_entra[$i]['id'] ?></strong></td>
                                                <td>
                                                    <span class="w-space-no"><?php echo $lead_entra[$i]['nome'] ?></span>
                                                </td>
                                                <td>
                                                    <?php echo $lead_entra[$i]['telefone'] ?>
                                                </td>
                                                <td>
                                                    <?php echo $lead_entra[$i]['email'] ?>
                                                </td>
                                                <td>
                                                    <?php echo $lead_entra[$i]['produto'] ?>
                                                </td>
                                                <td>
                                                    <?php echo $lead_entra[$i]['criado_em'] ?>											
												</td>												
                                            </tr>
                                            <?php } ?>
                                            
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    
                        
                    </div>
                    
                    
                    
                    
                    
                </div>
            </div>
            
        </div>
    </div>
</div>

<?php require_once ("includes/rodape.php"); ?>
<script src="vendor/datatables/js/jquery.dataTables.min.js"></script>
<script src="js/plugins-init/datatables.init.js"></script>


<?php if(!empty($_GET['adicionado']) == "ok" ) { ?>           		
<script>
	window.onload = function() {
		swal({
			title: 'Sucesso',
			text: ("Produto criado com sucesso!"),
			type: 'success',
			confirmButtonText: 'Fechar'
		})
	};
</script>
<?php } ?>

<?php if(!empty($_GET['apagou']) == "ok" ) { ?>           		
<script>
	window.onload = function() {
		swal({
			title: 'Produto apagado!',
			text: ("Produto apagado com sucesso!"),
			type: 'success',
			confirmButtonText: 'Fechar'
		})
	};
</script>
<?php } ?>