

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

<?php $__env->startSection('content'); ?>
<section class="page-header">
	<div class="page-header__bg" style="background-image: url(<?php echo e(asset('assets/images/header.jpg')); ?>);"></div>
	<div class="container">
		<h2><?php echo e($category); ?> </h2>
		<ul class="thm-breadcrumb list-unstyled">
			<li class="text-white"><a href="<?php echo e(url('/')); ?>">Inicio</a></li>
		</ul>
	</div>
</section>

<?php if(Auth::user()): ?>
	<div class="row">
		<div class="container py-2">
			<div class="col text-right">
				<a href="<?php echo e(route('documentos.create')); ?>" class="thm-btn">
				<i class="fas fa-plus"></i>  
				Registrar nuevo Documento
				</a>
			</div>
		</div>
	</div>
<?php endif; ?>


	    <?php if(isset($documentos)): ?>
        <?php foreach($documentos as $documento): ?>               
				 


            <section class="about-one" <?php echo e($documento->status ?: 'despublicado'); ?>>
                <img src="assets/images/shapes/about-leaf-1-1.png" alt="" class="about-one__shape-1">
                <div class="container">
                    <div class="row">
                        <div class="col-md-12 col-lg-3">
                            <?php echo e(HTML::image('assets/img/logos/logo.jpg', 'a picture', array('class' => 'circle', 'width'=>'80%'))); ?>

                        </div><!-- /.col-md-12 -->
                        <div class="col-md-12 col-lg-9">
                            <div class="about-one__content">
                                <div class="block-title text-left">
                                    <div class="block-title__decor"></div><!-- /.block-title__decor -->
                                    <p><span class="new badge left"><?php echo e(date('d M Y',strtotime($documento->publish_up))); ?></span></p>
                                    <h3><?php echo e($documento->title); ?></h3>
                                    <p>Descargado: <?php echo e($documento->hits); ?> veces.</p>
                                </div><!-- /.block-title -->
                                <div>
                                    <?php echo $documento->description; ?>

                                </div>
                                <div class="row">
                                    <div class="secondary-content"> 
                                        <a target="_new" href="assets/documents/<?php echo e($documento->file); ?>" onclick="downloadAdd('<?php echo e($documento->id); ?>')" class="btn btn-success" data-position="bottom" data-delay="50" data-tooltip="Descargar:  <?php echo e($documento->title); ?>">
                                            <i class="fa fa-download" aria-hidden="true"></i>
                                        </a> 
                                        <?php if(Auth::user()): ?>
                                            <a onclick="trash('<?php echo e($documento->id); ?>','<?php echo e($documento->title); ?>')" class="btn btn-danger">
                                                <i class="fa fa-trash" aria-hidden="true"></i>
                                            </a>
                                            <a href="<?php echo e(route('documentos.edit',$documento->id)); ?>" class="btn btn-info">
                                                <i class="fa fa-edit" aria-hidden="true"></i>
                                            </a>   
                                        <?php if($documento->status): ?>
                                            <a onclick="statusChange('<?php echo e($documento->id); ?>','<?php echo e($documento->status); ?>','<?php echo e($documento->title); ?>')" class="btn btn-light" 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($documento->id); ?>','<?php echo e($documento->status); ?>','<?php echo e($documento->title); ?>')" class="btn btn-light" 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><!-- /.row -->
                            </div><!-- /.about-one__content -->
                        </div><!-- /.col-md-12 col-lg-6 -->
                    </div><!-- /.row -->
                </div><!-- /.container -->
            </section><!-- /.about-one -->
             
	 
        <?php endforeach; ?>
	    <?php else: ?>
	       <?php echo $__env->make('partials.noData', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
	    <?php endif; ?>
	    
        <?php  $paginates=$documentos;  ?>
        <div class="container list-unstyled d-flex justify-content-center py-4">
            <?php echo e($paginates->links()); ?>

        </div>

<?php $__env->stopSection(); ?>
<?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('/documento/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('/documento/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 );
       }
   }); 
}

function downloadAdd(id){
	console.log('down'+id);
   $.ajax({
       url: '<?php echo e(url('/documento/download')); ?>' + '/' + id,
       type: 'GET', 
       headers: {
           'X-CSRF-TOKEN': $('meta[title="token"]').attr('content')
       },
       dataType: "JSON",
       success: function (res) {
           console.log(res); 
       },
       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(); ?>