<?php

$video = $con->query("SELECT * FROM `filmes` Order by id Desc");
	?>
			<div class="content-box">
				<div class="action"><button class="add-user">Adicionar Video</button></div>
				
<?php
while ($vid = $video->fetch(PDO::FETCH_ASSOC)) {
?>
				<div class="video-card">
					<div class="shadow">
						<p class="title"><?=$vid['titulo']?></p>
						<button class="edit-video-btn edit-vid" idVid="<?=$vid['id']?>"><i class="fas fa-pencil-alt"></i></button>
						<button class="edit-video-btn exl-vid" idVid="<?=$vid['id']?>"><i class="fas fa-trash-alt"></i></button>
					</div>
					<div class="poster">
						<img src="<?=$vid['bg']?>">
					</div>
				</div>
<? } ?>

			</div>	
			<script type="text/javascript">
				$('.add-user').click(function(){
				 	
						$('.loading').css('display','block');
						$('.loading').css('opacity','1');
						$('.conteudo').load('pages/vid-add.php',function(){
							$('.loading').css('display','none');
						});
				});
				$('.exl-vid').click(function(){
					var idVid = $(this).attr('idVid');
					$.ajax({
						  type: "POST",
						  url: 'function/api.php?action=exlVid',
						  data: {
						  	'idVid' : idVid,
						  	
							},
						  success: function(data,status){
						  	
						  	if(data == 'E1'){
						  		$('.loading').css('display','none');
								$('.loading').css('opacity','0');
						  		$('.status').css('display','block');
					  			$('.status').css('color','white');
					  			$('.status').css('background','rgba(215,50,50,1)');
						  		$('.status p').html('Erro ao Exluir.');
						  		status_close();

						  	}else if(data == 'S1'){
						  		$('.loading').css('display','none');
								$('.loading').css('opacity','0');
						  		$('.status').css('display','block');
						  		$('.status').css('color','white');
					  			$('.status').css('background','rgba(50,215,50,1)');
						  		$('.status p').html('Exluido Com Sucesso.');
						  		status_close();
						  	}
						  },
						  
						});
					$('.loading').css('display','block');
						$('.loading').css('opacity','1');
						$('.conteudo').load('pages/vid.php',function(){
							setTimeout(function(){
							$('.header-content h2').html('Videos');
							$('.loading').css('display','none');
							$('.loading').css('opacity','0');
						},500);
						});
				});
				$('.edit-vid').click(function(){
					var edit = $(this).attr('idVid');
					window.location.href="?action=filmEdit&id="+edit;
				});
			</script>