

<?php $__env->startSection('page-title', 'Galería de Fotos - Albums'); ?>

<?php $__env->startSection('content'); ?>
	<h1 class="headerSection">Galería de Fotos</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('fotos.create')); ?>"><i class="fa fa-picture-o"></i> Registrar nueva Fotografía</a>
	    </li> 
	    <li class="waves-effect waves-light">
	        <a href="<?php echo e(route('albums.create')); ?>"><i class="fa fa-folder-open"></i> Registrar nuevo Album</a>
	    </li> 
	  </ul>
	</div>
	<?php endif; ?>
    <div class="row">
	    <?php if(count($albums)): ?> 
	        <?php foreach($albums as $album): ?>               
			    
                <div class="col-md-12  text-center <?php echo e($album->status ?: 'despublicado'); ?>">
                    <div class="card card-panel hoverable">
                        <div class="card-content">
                            
                            <div class="row">
                                <div class="col-xs-12 col-md-4"> 
                                    <a href="<?php echo e(route('fotos.index',['filter' => $album->id])); ?>">
                                     <img  class="img-fluid rounded" src="assets/fotos/<?php echo e(DB::table('fotos')->where('album_id', $album->id)->value('file')); ?>" alt="<?php echo e($album->album); ?>"/>  
                                    </a>
                                    <span class="new badge">
                                        <?php echo e(DB::table('fotos')->where('album_id', $album->id)->count()); ?> Fotos
                                    </span>
                                </div>    
                                <div class="col-xs-12 col-md-8">
                                    <a href="<?php echo e(route('fotos.index',['filter' => $album->id])); ?>">
                                        <h4 class="headerSection"><?php echo e($album->album); ?></h4>
                                    </a>
                                    <div class="text-justify">
                                        <?php echo $album->description; ?>

                                    </div>
                                </div> 
                        
                            </div>
                            
                            
                        </div>
                    
                    
                        <div class="card-action teal darken-1"> 
                            <div class="chip pull-right">
            		            <i class='fa fa-calendar' aria-hidden='true'></i> Publicado el:
            		            <?php echo e(date('d M Y',strtotime($album->publish_up))); ?>

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

            		            </span>
            		       	</div>
                              <div class="pull-left">
                              <?php if(Auth::user()): ?>
                                    <a onclick="trash('<?php echo e($album->id); ?>','<?php echo e($album->album); ?>')" 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('albums.edit',$album->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($album->status): ?>
                                    <a onclick="statusChange('<?php echo e($album->id); ?>','<?php echo e($album->status); ?>','<?php echo e($album->album); ?>')" 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($album->id); ?>','<?php echo e($album->status); ?>','<?php echo e($album->album); ?>')" 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; ?>                        
            
                            <?php endif; ?>
                            </div>
                        </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=$albums;  ?>
	    <?php echo $__env->make('partials.paginate', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    </div>
<?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('/albums/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('/albums/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>
    <script type="text/javascript">
$(document).ready(function(){
    $('.materialboxed').materialbox();
  });
        

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

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