<?php

$sql = $con->query("SELECT * FROM `episode` Order by id Desc");
?>
			<div class="content-box">
				<div class="action"><button class="add-user">Adicionar Episodio</button></div>
				<?php

				while($vid = $sql->fetch(PDO::FETCH_ASSOC)){
					$idVd = $vid['idf'];
					$sqli = $con->prepare("SELECT * FROM `filmes` WHERE tmdb= :id");
					$sqli->bindValue(':id', $idVd);
					$sqli->execute();
					$ft = $sqli->fetch(PDO::FETCH_ASSOC);

				?>

				<div class="video-card">
					<div class="shadow">
						<p class="title"><?=$ft['titulo']?> : <?=$vid['titulo']?> : T<?=$vid['temp']?></p>
						<button class="edit-video-btn" key="edit" idv="<?=$vid['id']?>"><i class="fas fa-pencil-alt"></i></button>
						<button class="edit-video-btn" key="remove" idv="<?=$vid['id']?>"><i class="fas fa-trash-alt"></i></button>
					</div>
					<div class="poster">
						<img src="<?=$vid['bg']?>">
					</div>
				</div>
				<?php
					}

				?>

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

					
				});

			</script>
			<script type="text/javascript">
				$('.edit-video-btn').click(function(){
					var key = $(this).attr('key');
					var id  = $(this).attr('idv');
					if(key == "remove"){
						$.ajax({
									  type: "POST",
									  url: 'function/api.php?action=removeEp',
									  data: {
									  	'idEp' : id,
									  	
										},
									  success: function(data,status){
									  	$('.loading').css('display','none');
										$('.loading').css('opacity','0');
										  	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(' Falha Ao Excluir.');
										  		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('Excluido Com Sucesso.');
										  		
										  		status_close();
										  	}
									  },
									  
									});
					}else if(key == "edit"){
						window.location.href="?action=epiEdit&id="+id;
						
					}

				});
			</script>