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

<?php $__env->startSection('content'); ?>
	<h1 class="headerSection">Autoridades</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('autoridades.create')); ?>"><i class="fa fa-user"></i> Registrar nueva Autoridad</a>
	    </li> 
	  </ul>
	</div>
	<?php endif; ?>

	    <?php if(count($authorities)): ?>
	        <?php foreach($authorities as $authority): ?>                 

		      <div class="row <?php echo e($authority->status ?: 'despublicado'); ?>">
		        <div class="col s12 m6">
		          <div class="card teal darken-1">
		            <div class="card-content white-text">
		              <span class="card-title">
		              	<i class="material-icons small dp48">account_circle</i> <?php echo e($authority->name); ?> <?php echo e($authority->lastname1); ?> <?php echo e($authority->lastname2); ?> 

		              	<?php if(Auth::user()): ?>
			              	<div class="actions">
				              	<a onclick="trash('<?php echo e($authority->id); ?>','<?php echo e($authority->name); ?>')" 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('autoridades.edit',$authority->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($authority->status): ?>
				              	<a onclick="statusChange('<?php echo e($authority->id); ?>','<?php echo e($authority->status); ?>','<?php echo e($authority->name); ?>')" 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($authority->id); ?>','<?php echo e($authority->status); ?>','<?php echo e($authority->name); ?>')" 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 class="badge green"><small>publicado el: <?php echo e($authority->publish_up); ?></small></div>
			              	</div>
			             <?php endif; ?>
		              </span>

		              <p><?php echo e($authority->position); ?> - <?php echo e($authority->community); ?></p>
		            </div>
		            <div class="card-action">

		              <?php if($authority->fb): ?>
		             	<a href="<?php echo e($authority->fb); ?>" target="_new"><i class="fa fa-facebook-official"></i>/<?php echo e($authority->name); ?></a>
		              <?php endif; ?>
		              <?php if($authority->email): ?>
		             	<a class="text-lowercase" href="mailto:<?php echo e($authority->email); ?>?subject=Web Machareti e Ivo" target="_new"><i class="fa fa-envelope fa4"></i> <?php echo e($authority->email); ?></a>
		              <?php endif; ?>
		              <?php if($authority->movil): ?>
		              	<a href="#" target="_new"><i class="fa fa-phone"></i> <?php echo e($authority->movil); ?></a>
		              <?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=$authorities;  ?>
	    <?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,name){ 
    var ident = id;
    swal({
     text: 'Esta seguro de realizar esta Acción?',
     title: 'Si procede <span class="btn btn-danger">'+name+'</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+'-'+name)
           $.ajax({
               url: '<?php echo e(url('/autoridades/delete')); ?>' + '/' + id, 
               type: "GET",  
               dataType: "JSON", 
               headers: {
                'X-CSRF-TOKEN': $('meta[name="token"]').attr('content')
            },
            success: function (res) {
                console.log(res);
            },
            error: function(res){
                console.log("Error :" + res );
            }
               }); 
               swal(name+' 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,name){
   $.ajax({
       url: '<?php echo e(url('/autoridades/statusChange')); ?>' + '/' + id + '/' + status,
       type: 'GET', 
       headers: {
           'X-CSRF-TOKEN': $('meta[name="token"]').attr('content')
       },
       dataType: "JSON",
       success: function (res) {
           console.log(res);
            if(res.now){
                swal(name+', modificado!', 'este registro está publicado.', 'success');
                window.location.reload(true);
            }else{
                swal(name+', 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(); ?>