<?php $__env->startSection('content'); ?>
<?php
use App\Models\User;

if (!empty($_GET['search'])) 
{
   $neenoe = request()->query('search');
   
   $users = User::withCount('referrals')
    ->having('referrals_count', '>', 5)
    ->where('status', 'active')->where('name','like','%'.$neenoe.'%')->orWhere('email','like','%'.$neenoe.'%')
    ->orderByDesc('referrals_count')
    ->get();

}else 
{
    $users =  User::withCount('referrals')
    ->having('referrals_count', '>', 5)
    ->orderByDesc('referrals_count')
    ->get();
    
}


?>

    <div class="col-lg-7">
        <div class="page-header-title">
            <div class="d-inline">
                <div class="card-header">
                    <h5>List of Top Team Builders</h5>
                </div>
            </div>
        </div>
    </div>


    <div class="col-xl-12 col-md-12">
        <!-- DOM/Jquery table start -->
        <div class="card">
            <div class="card-block">
                <div class="table-responsive dt-responsive">
                    <table class="table table-hover table-borderless">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Users Invited</th>
                                <th>Username</th>
                                <th>Phone</th>
                                <th>Referrered by</th>
                                <th>Referer Phone</th>
                                <th>Commision Earned</th>
                            </tr>
                        </thead>
                        <tbody>

                         <?php if($users->count() > 0): ?>
                            <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($user->name); ?>

                                </td>
                                <td>
                                    <?php 
                                    $myTeam = DB::table('users')->where('upline', $user->username)->get()->count();
                                    $myActiveTeam = DB::table('users')->where('upline', $user->username)->where('status', 1)->get()->count();
                                    ?>
                                    <label class="label label-success"><?php echo e($myActiveTeam); ?>/<?php echo e($myTeam); ?></label>
                                </td>
                                <td><?php echo e($user->username); ?></td>
                                <td><?php echo e($user->phone); ?></td>
                                <td><?php echo e($user->upline); ?></td>
                                <td>
                                    <?php
                                        $up = DB::table('users')->where('username', $user->upline)->first();
                                    ?>
                                    <?php echo e($up->phone ?? 'empty'); ?>

                                </td>
                                <td>
                                    <label><?php echo e($user->wallet); ?></label>
                                </td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                        <?php else: ?>

                        <tr>
                            <td colspan="full">
                                <p>No Data found</p>
                            </td>
                        </tr>

                        <?php endif; ?>

                        </tbody>
                    </table>
                </div>
              
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/maxmallt/1ai.co.ke/resources/views/affiliates/active.blade.php ENDPATH**/ ?>