<?php

$us = $con->query("SELECT * FROM `user` ORDER BY id DESC");
?>
			<div class="confirm-question" style="display: none;" idMB="">
				<div class="container-question">
					Deseja realmente excluir o membro #<span class="idUser"></span>
					<button class="Confirm">Sim</button><button class="Nega">Não</button>
				</div>
			</div>
					
			<div class="content-box">
				<button class="add-user">Adicionar Usuario</button>
				<table class="table-user" cellpadding="0" cellspacing="0">
					<thead>
						<tr class="tr-table table-header">
							<td>#</td>
							<td>E-mail</td>
							<td>Nome</td>
							<td>Ações</td>
						</tr>
					</thead>
					<tbody>
						<?php
						while($user = $us->fetch(PDO::FETCH_ASSOC)){
							$idUs = $user['id'];
						?>
						<tr class="tr-table">
							<td><?=$user['id']?></td>
							<td><?=$user['email']?></td>
							<td><?=$user['username']?></td>
							<td><button class="edit-user-btn" idmb="<?=$user['id']?>">Editar</button> <button class="exl-user-btn" idmb="<?=$user['id']?>" >Apagar</button></td>
						</tr>
						<? } ?>

					</tbody>
				</table>
				
			</div>	
			
			<script type="text/javascript">
				$('.add-user').click(function(){
				 	
						$('.loading').css('display','block');
						$('.loading').css('opacity','1');
						$('.conteudo').load('pages/users-add.php',function(){
							setTimeout(function(){
								$('.header-content h2').html('Usuario');
								$('.loading').css('display','none');
								$('.loading').css('opacity','0');
							},500);
						});

					
				});
				$('.exl-user-btn').click(function(){
					var idUser = $(this).attr('idmb');
					$('.idUser').html(idUser);
					$('.confirm-question').attr('idMB',idUser);
					$('.confirm-question').css('display','block');
				});
				$('.Confirm').click(function(){
					var idmb = $('.confirm-question').attr('idMB');
					
					$.ajax({
					  type: "POST",
					  url: 'function/api.php?action=usersexl',
					  data: {
					  	'idMB' : idmb
						},
					  success: function(data){
					  	console.log(data);
					  	if(data == 'E1'){
					  		$('.status').css('display','block');
					  		$('.status').css('color','white');
					  		$('.status').css('background','rgba(215,50,50,1)');
					  		$('.status p').html('Usuario Não Encotrado.');
					  		status_close();
					  	}else if(data == 'S1'){
					  		$('.status').css('display','block');
					  		$('.status').css('color','white');
					  		$('.status').css('background','rgba(50,215,50,1)');
					  		$('.status p').html('Excluido com sucesso.');
					  		status_close();
					  	}
					  },
					  
					});
					$('.confirm-question').css('display','none');
				});
				$('.Nega').click(function(){
					$('.confirm-question').css('display','none');
				});

				$('.edit-user-btn').click(function(){
					var idUser = $(this).attr('idmb');

					window.location.href="?action=usersEdit&id="+idUser;
				});
			</script>