<?php $__env->startSection('content'); ?>
<div class="page-content">
    <div class="container-fluid">
        <div class="page-content-inner">
            <div class="row">
                <div class="col-md-12">
                    <div class="portlet light">
                        <div class="portlet body">
                            <div class="row">
                                <div class="col-md-12">
                                    <span class="font-blue-madison title"><i class="fa fa-list-alt"></i> Clientes</span>
                                    <?php if(routeAcess('admin.customers.create')): ?>
                                    <a href="<?php echo e(route('admin.customers.create')); ?>" class="right btn green-jungle"><i class="fa fa-plus-circle"></i> Novo Cliente</a>
                                    <?php endif; ?> 
                                    <hr>
                                </div>
                            </div>
                        </div>
                        <div class="portlet-body">                                
                            <table class="table table-striped table-hover table-light" id="table">
                                <thead>
                                    <tr class="uppercase bg-blue-madison">
                                        <th class="font-white">Nome</th>
                                        <th class="font-white">Email</th>
                                        <th class="font-white">Plano</th>
                                        <th class="font-white col-md-2">Status</th>
                                        <th class="font-white col-md-3">Ações</th>
                                    </tr>
                                </thead>
                                <tbody> 
                                    <?php foreach($customers as $customer): ?>                                               
                                        <tr>
                                            <?php if(!empty($customer->name)): ?>
                                                <td><?php echo e($customer->name); ?></td>
                                            <?php else: ?>
                                                <td><?php echo e($customer->user_name); ?></td>
                                            <?php endif; ?>
                                            <td><?php echo e($customer->email); ?></td>
                                            <td><?php echo e($customer->plano); ?></td>
                                            <td>
                                                <?php if($customer->user_active == 'yes'): ?> 
                                                    <i class="fa fa-circle font-green-jungle popovers"> <?php echo e($customer->conta_status); ?>

                                                <?php else: ?>
                                                    <i class="fa fa-circle font-red popovers"> <?php echo e($customer->conta_status); ?>

                                                <?php endif; ?>
                                                    </i>
                                            </td>
                                            <td>
                                                <a class='btn btn-xs yellow-casablanca popovers fancybox fancybox.iframe' data-container="body" data-trigger="hover" data-placement="top" data-content="Clique aqui para visualizar mais informações do cliente" href="<?php echo e(route('admin.customers.details',['user_id' => $customer->user])); ?>">
                                                    <i class="glyphicon glyphicon-search"></i>
                                                </a>
                                                <?php if(routeAcess('admin.customers.acounts')): ?>
                                                    <a class='btn btn-xs grey popovers' data-container="body" data-trigger="hover" data-placement="top" data-content="Clique aqui para gerenciar as contas voip do cliente" href="<?php echo e(route('admin.customers.acounts', ['id' => $customer->user])); ?>">
                                                        <i class="fa fa-phone"></i>
                                                    </a>
                                                <?php endif; ?> 

                                                <?php if(routeAcess('admin.customers.logged')): ?>
                                                    <a class='btn btn-xs green popovers' data-container="body" data-trigger="hover" data-placement="top" data-content="Clique aqui para efetuar login na conta do cliente" onclick='loaderOnClick()' href="<?php echo e(route('admin.customers.logged', ['id' => $customer->user_id])); ?>">
                                                        <i class="fa fa-home"></i>
                                                    </a>
                                                <?php endif; ?> 

                                                <?php if(routeAcess('admin.customers.block_unblock')): ?>
                                                    <?php if($customer->user_active == 'no'): ?>
                                                        <a onclick="blockCustomer('<?php echo e($customer->user); ?>','desbloquear')" href="javascript:void(0);" class='btn btn-xs green-jungle popovers' data-container="body" data-trigger="hover" data-placement="top" data-content="Clique aqui para desbloquear a conta voip do cliente!">
                                                            <i class="fa fa-unlock"></i>
                                                        </a>
                                                    <?php else: ?>
                                                        <a onclick="blockCustomer('<?php echo e($customer->user); ?>','bloquear')" href="javascript:void(0);" class='btn btn-xs red-mint popovers' data-container="body" data-trigger="hover" data-placement="top" data-content="Atenção, esta ação bloqueia totalmente a conta voip do Cliente!">
                                                            <i class="fa fa-lock"></i>
                                                        </a>
                                                    <?php endif; ?>
                                                <?php endif; ?>

                                                <?php if(isset($customer->id)): ?>

                                                    <?php if(routeAcess('admin.customers.balance')): ?>
                                                        <a class='btn btn-xs green-seagreen popovers' data-container="body" data-trigger="hover" data-placement="top" data-content="Aqui você pode alterar o saldo de créditos do cliente." href="<?php echo e(route('admin.customers.balance', ['id' => $customer->id])); ?>" title="Alterar Saldo">
                                                            <i class="fa fa-money"></i>
                                                        </a>
                                                    <?php endif; ?>

                                                    <?php if(routeAcess('admin.customers.edit')): ?>
                                                        <a class='btn btn-xs blue-madison popovers' data-container="body" data-trigger="hover" data-placement="top" data-content="Aqui você pode editar a conta do cliente." href="<?php echo e(route('admin.customers.edit', ['id' => $customer->id])); ?>" title="Editar">
                                                            <i class="fa fa-edit"></i>
                                                        </a>
                                                    <?php endif; ?>
                                                <?php endif; ?> 
                                                <?php if(routeAcess('admin.customers.remove')): ?> 
                                                    <a  class='btn btn-xs red popovers' data-container="body" data-trigger="hover" data-placement="top" data-content="Atenção! Essa ação exclui permanentemente a conta do cliente e esse é um processo irreversível!!!" onclick="removeRegistro('remover-cliente/','<?php echo e($customer->user); ?>')">
                                                        <i class="fa fa-times"></i>
                                                    </a>
                                                <?php endif; ?>
                                                <?php if($customer->contrato > 0): ?>
                                                    <a class='btn btn-xs yellow-soft popovers' data-container="body" data-trigger="hover" data-placement="top" data-content="Visualizar contratos do cliente" href="<?php echo e(route('admin.customers.contratos', ['id' => $customer->user])); ?>">
                                                        <i class="fa fa-file"></i>
                                                    </a>
                                                <?php endif; ?>
                                                <?php if(routeAcess('admin.customers.historico')): ?> 
                                                    <a class='btn btn-xs yellow-gold popovers fancybox fancybox.iframe' data-container="body" data-trigger="hover" data-placement="top" data-content="Clique aqui para adicionar anotações do Cliente" href="<?php echo e(route('admin.customers.historico', ['id' => $customer->user])); ?>">
                                                        <i class="fa fa-exclamation-triangle"></i>
                                                    </a>
                                                <?php endif; ?>                                                    
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>                                       
                                </tbody>
                            </table>                        
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

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

<?php $__env->startSection('js-admin-customer'); ?>
<script src="<?php echo e(asset('/assets/global/scripts/app.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('/assets/global/plugins/fancybox/source/jquery.fancybox.js?v=2.1.5')); ?>" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<?php echo e(asset('/assets/global/plugins/fancybox/source/jquery.fancybox.css?v=2.1.5')); ?>" media="screen" />
<script src="<?php echo e(asset('/assets/global/plugins/datatables/datatables.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('/assets/global/plugins/datatables/plugins/bootstrap/datatables.bootstrap.js')); ?>" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready( function() {  
        $('.fancybox').fancybox();
            /**
             * Tabela padrão, com paginação, busca registros por página 
             */
             $('#table').DataTable({
                "aoColumnDefs": [
                {'bSortable': false, 'aTargets': ["no-sort"]}
                ],
                "iDisplayLength": 15,
                "language": {
                    "lengthMenu": "Exibir _MENU_",
                    "zeroRecords": "Nenhum registro",
                    "info": "Exibindo página(s) _PAGE_ de _PAGES_",
                    "infoEmpty": "Não há registros disponíveis",
                    "search" : "Pesquisar ",
                    "paginate": {
                        "first":    "Primeiro",
                        "previous": "Anterior",
                        "next":     "Próximo",
                        "last":     "Último"
                    }
                }
            });
         });

    function blockCustomer(id, action) {   
        swal({
          title: "Deseja realmente "+action+" a conta Voip ?",
          text: " ",
          type: "warning",
          showCancelButton: true,
          confirmButtonClass: "btn-danger",
          confirmButtonText: "Sim!",
          cancelButtonText: "Não",
          closeOnConfirm: false,
          closeOnCancel: true
        },
        function(isConfirm) {
            if (isConfirm) {
                window.location = "bloquear-desbloquear-cliente/"+id;
            }else{
                return false;
            } 
        });
    }
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('template', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>