<?php $__env->startSection('page-title', 'Multimedia'); ?>

<?php $__env->startSection('content'); ?>
	<h1 class="headerSection">Multimedia</h1>


	<?php if(Auth::user()): ?>

	<div class="fixed-action-btn toolbar">
	  <span class="new badge blue badgeButtom" style="float:left;"> Agregar</span>
	  <a class="btn-floating btn-large blue z-depth-4">
	    <i class="large material-icons">library_add</i> 
	  </a>
	  <ul>
	    <li class="waves-effect waves-light">
	        <a href="<?php echo e(route('multimedia.create')); ?>"><i class="fa fa-user"></i> Registrar Multimedia</a>
	    </li> 
	  </ul>
	</div>
	<?php endif; ?>

	    <?php if(count($multimedia)): ?>
	        <?php foreach($multimedia as $resource): ?>               
				 
		      <div class="row <?php echo e($resource->status ?: 'despublicado'); ?>">
		        <div class="col s12 m7">
		          <div class="card">
		            <div class="card-image">
		              <div class="text-center">
		              	<?php 
		              	$sep = explode(' ', $resource->embed);
		              	$width = explode('"',$sep[1]); 
		              	echo str_replace($sep[1], 'width="100%"', $resource->embed);
		              	?>
		              </div>
		              <span class="card-title titlePrimary"><?php echo e($resource->title); ?></span>
		            </div><br>
		            <div class="col s6">
		            	 <div class="chip pull-right">
		              		<i class='fa fa-calendar' aria-hidden='true'></i> Publicado el:
		              		<?php echo e(date('d M Y',strtotime($resource->publish_up))); ?>

		              		<span class="new badge">
		              			<?php echo e(\Carbon\Carbon::now()->subMinutes( \Carbon\Carbon::now()->diffInMinutes( \Carbon\Carbon::parse($resource->publish_up)))->diffForHumans()); ?>

		              		</span>
		              	</div>
		            </div><br>
		            <div class="card-content">
		              
	
		              	<div class="text-justify"><?php echo $resource->description; ?></div>
		            </div>
		            <?php if(Auth::user()): ?>
		            	<div class="card-action teal darken-1">
		            
			              	<div class="">
				              	<a onclick="trash('<?php echo e($resource->id); ?>','<?php echo e($resource->title); ?>')" class="pull-right btn-floating waves-effect waves-light btn-small red">
				              		<i class="fa fa-trash" aria-hidden="true"></i>
				              	</a>
				              	<a href="<?php echo e(route('multimedia.edit',$resource->id)); ?>" class="pull-right btn-floating waves-effect waves-light btn-small blue">
				              		<i class="fa fa-pencil-square-o" aria-hidden="true"></i>
				              	</a>   
				            <?php if($resource->status): ?>
				              	<a onclick="statusChange('<?php echo e($resource->id); ?>','<?php echo e($resource->status); ?>','<?php echo e($resource->title); ?>')" class="pull-right btn-floating waves-effect waves-light btn-small green tooltipped" data-position="bottom" data-delay="50" data-tooltip="Este registro está PUBLICADO">
				              		<i class="fa fa-eye" aria-hidden="true"></i>
				              	</a>   	
				            <?php else: ?> 
				            	<a onclick="statusChange('<?php echo e($resource->id); ?>','<?php echo e($resource->status); ?>','<?php echo e($resource->title); ?>')" class="pull-right btn-floating waves-effect waves-light btn-small green tooltipped" data-position="bottom" data-delay="50" data-tooltip="Este registro está DESPUBLICADO">
				              		<i class="fa fa-eye-slash" aria-hidden="true"></i>
				              	</a>   	
				            <?php endif; ?>  				           
			              	</div>
			            </div>
			        <?php endif; ?>		            
		          </div>
		        </div>
		      </div>

	 
	        <?php endforeach; ?>
	    <?php else: ?>
	       <?php echo $__env->make('partials.noData', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
	    <?php endif; ?>
	    
	    <?php  $paginates=$multimedia;  ?>
	    <?php echo $__env->make('partials.paginate', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

<?php $__env->stopSection(); ?>
   <hr>
<?php $__env->startSection('scripts'); ?>

<script>
function trash(id,title){ 
    var ident = id;
    swal({
     text: 'Esta seguro de realizar esta Acción?',
     title: 'Si procede <span class="btn btn-danger">'+title+'</span> será eliminado!',
     type: 'warning',
     showCancelButton: true,
     confirmButtonColor: '#DD6B55',
     confirmButtonText: 'Eliminar!',
     cancelButtonText: 'Cancelar', 
     closeOnConfirm: false,
     closeOnCancel: false,
     html: true

   },
   function(isConfirm){
       if (isConfirm) { 
       //	console.log(id+'-'+title)
           $.ajax({
               url: '<?php echo e(url('/multimedia/delete')); ?>' + '/' + id, 
               type: "GET",  
               dataType: "JSON", 
               headers: {
                'X-CSRF-TOKEN': $('meta[title="token"]').attr('content')
            },
            success: function (res) {
                console.log(res);
            },
            error: function(res){
                console.log("Error :" + res );
            }
               }); 
               swal(title+' eliminado!', 'Este registro fue eliminado.', 'success');
               window.location.reload(true);

       }else {
           swal('Cancelado!', 'Este registro NO fue eliminado.', 'error');
       }
   });
}
</script>
<script>
function statusChange(id,status,title){
   $.ajax({
       url: '<?php echo e(url('/multimedia/statusChange')); ?>' + '/' + id + '/' + status,
       type: 'GET', 
       headers: {
           'X-CSRF-TOKEN': $('meta[title="token"]').attr('content')
       },
       dataType: "JSON",
       success: function (res) {
           console.log(res);
            if(res.now){
                swal(title+', modificado!', 'este registro está publicado.', 'success');
                window.location.reload(true);
            }else{
                swal(title+', modificado!', 'este registro está despublicado.', 'warning');
                window.location.reload(true);
            }
       },
       error: function(res){
           console.log("Error :" + res );
       }
   }); 
}
</script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.web', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>