

<?php $__env->startSection('content'); ?>
    <?php
        $url = Request::getRequestUri();
    ?>
    <h1 class="h3 mb-3">Search Students</h1>

    <div class="card mb-4">
        <div class="card-header">
            <form action="" method="get">
                <div class="row mb-3">
                    <div class="col-8">
                        <input type="text" name="search" class="form-control" placeholder="Search by ID or phone number"
                            value="<?php echo e(request('search')); ?>">
                    </div>
                    <div class="col-3">
                        <button type="button" class="btn btn-primary">Search</button>
                    </div>
                </div>
            </form>
            <form action="" method="get">
                <div class="row">
                    <div class="col-md-3 col-6">
                        <label class="form-label">Status</label>
                        <select name="status" class="form-select" required>
                            <option value="pending" <?php echo e(request('status') == 'pending' ? 'selected' : ''); ?>>Pending</option>
                            <option value="active" <?php echo e(request('status') == 'active' ? 'selected' : ''); ?>>Active</option>
                        </select>
                    </div>
                    <div class="col-md-3 col-6">
                        <label class="form-label">From</label>
                        <input type="date" name="from" value="<?php echo e(request('from')); ?>" class="form-control" required>
                    </div>
                    <div class="col-md-3 col-6">
                        <label class="form-label">To</label>
                        <input type="date" name="to" value="<?php echo e(request('to')); ?>" class="form-control" required>
                    </div>
                    <div class="col-md-3 col-6 mt-4">
                        <button type="submit" class="btn btn-success">Filter</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="card-body table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>Image</th>
                        <th>Details</th>
                        <th>Status</th>
                        <th>Balance</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td>
                                <img src="<?php echo e(img($user->avatar)); ?>" width="60" class="rounded-circle">
                            </td>
                            <td>
                                ID: <?php echo e($user->id); ?><br>
                                Name: <?php echo e($user->name); ?><br>
                                Email: <?php echo e($user->email); ?><br>
                                Phone: <?php echo e($user->phone); ?> <br>
                                Refer By: <?php echo e($user->referer?->name); ?>(<?php echo e($user->referer?->id); ?>) <br>
                                <a href="https://wa.me/<?php echo e($user->phone); ?>?text=<?php echo e(wp_msg($user)); ?>" target="_blank"
                                    class="btn btn-sm btn-dark">WhatsApp</a>
                            </td>
                            <td>
                                <?php if($user->verified_at): ?>
                                    <?php if($user->status): ?>
                                        <span class="badge bg-success">Active</span>
                                    <?php else: ?>
                                        <span class="badge bg-danger">Blocked</span>
                                    <?php endif; ?>
                                <?php else: ?>
                                    <span class="badge bg-warning">Pending</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <span>৳<?php echo e($user->balance); ?></span> <br>
                                <button class="btn btn-sm btn-info"
                                    onclick="loadModal(<?php echo e($user->id); ?>)">Wallet</button>
                            </td>
                            <td>
                                <div class="btn-group">
                                    <?php if($user->verified_at): ?>
                                        <a href="<?php echo e(route('users.edit', ['user' => $user->id, 'source' => $url])); ?>"
                                            class="btn btn-sm btn-primary">
                                            <i data-feather="edit"></i>
                                        </a>
                                        <a href="<?php echo e(route('users.show', ['user' => $user->id, 'source' => $url])); ?>"
                                            class="btn btn-sm btn-warning">
                                            <i data-feather="eye"></i>
                                        </a>
                                    <?php else: ?>
                                        <a href="<?php echo e(route('users.edit', ['user' => $user->id, 'source' => $url])); ?>"
                                            class="btn btn-sm btn-primary">
                                            Approved
                                        </a>
                                    <?php endif; ?>
                                    <button class="btn btn-sm btn-danger" onclick="deleteData(<?php echo e($user->id); ?>)">
                                        <i data-feather="trash-2"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>

            <div class="p-3">
                <?php echo e($users->links('pagination::bootstrap-5')); ?>

            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="addModal" tabindex="-1" aria-labelledby="addModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <form action="<?php echo e(route('users.create')); ?>" method="get">
                <div class="modal-content">
                    <div class="modal-header">
                        <h1 class="modal-title fs-5" id="addModalLabel">Select Role</h1>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">
                        <select name="role" class="form-select" required>
                            <option value="student" selected>Student</option>
                            <option value="counselor">Counselor</option>
                            <option value="manager">Account Manager</option>
                            <option value="teacher">Teacher</option>
                            <option value="trainer">Trainer</option>
                            <option value="tl">Team Leader</option>
                            <option value="stl">Senior Team Lead</option>
                            <option value="admin">Admin</option>
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Next</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="walletModal" tabindex="-1" aria-labelledby="walletModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <form action="<?php echo e(route('updateBalance')); ?>" method="post">
                <?php echo csrf_field(); ?>
                <div class="modal-content">
                    <div class="modal-header">
                        <h1 class="modal-title fs-5" id="walletModalLabel">Update Balance</h1>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">
                        <input type="hidden" name="id" id="user_id">
                        <input name="amount" type="number" step="any" min="1" class="mb-3 form-control"
                            required placeholder="amount">
                        <select name="type" class="mb-3 form-select" required>
                            <option value="credit">Cash in</option>
                            <option value="debit">Cash out</option>
                        </select>
                        <input name="details" type="text" class="mb-3 form-control" placeholder="details" required>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Save</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    
    <form action="#" method="post" id="delete-form">
        <?php echo csrf_field(); ?>
        <?php echo method_field('DELETE'); ?>
    </form>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
    <script>
        function deleteData(id) {
            let ask = confirm("Deleted file can't be restored!")
            if (ask) {
                $("#delete-form").attr('action', `<?php echo e(route('users.index')); ?>/${id}`);
                $("#delete-form").submit();
            }
        }
        const myModal = new bootstrap.Modal("#walletModal")

        function loadModal(id) {
            $("#user_id").val(id)
            myModal.show()
        }
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.backend.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/easyecommeplatm/public_html/resources/views/backend/users/search.blade.php ENDPATH**/ ?>