<?php $__env->startSection('contents'); ?>
    <div class="container-fluid mt-4">
        <h4 class="mb-4">Registered Users</h4>

        <div class="table-responsive">
            <table class="table table-bordered table-striped ">
            <thead class="table-dark">
                <tr>
                    <th>#</th>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Subscription Type</th>
                    <th>Start</th>
                    <th>End</th>
                    <th>Warnings</th>
                    <th>Status</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $sub = $subscriptions[$user->id] ?? null;
                    ?>
                    <tr id="user-row-<?php echo e($user->id); ?>">
                        <td><?php echo e($index + 1); ?></td>
                        <td><?php echo e($user->profile->real_name ?? 'User'); ?></td>
                        <td><?php echo e($user->email); ?></td>
                        <td><?php echo e($sub->subscription_type ?? '-'); ?></td>
                        <td><?php echo e($sub?->subscription_start ? \Carbon\Carbon::parse($sub->subscription_start)->format('Y-m-d') : '-'); ?>

                        </td>
                        <td><?php echo e($sub?->subscription_end ? \Carbon\Carbon::parse($sub->subscription_end)->format('Y-m-d') : '-'); ?>

                        </td>

                        <td><?php echo e($user->warnings_count); ?></td>
                        <td class="user-status"><?php echo e($user->is_active ? 'Active' : 'Inactive'); ?></td>
                        <td>
                            <button
                                class="btn btn-sm btn-toggle-status <?php echo e($user->is_active ? 'btn-danger' : 'btn-success'); ?>"
                                data-user-id="<?php echo e($user->id); ?>">
                                <?php echo e($user->is_active ? 'Deactivate' : 'Activate'); ?>

                            </button>

                            <button class="btn btn-sm btn-warning ms-2 btn-send-warning" data-user-id="<?php echo e($user->id); ?>">
                                Send Warning
                            </button>
                            <a href="<?php echo e(route('customerlist.details', $user->id)); ?>" class="btn btn-sm btn-primary ms-2">View</a>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
        </div>

    </div>

    <script>
        document.querySelectorAll('.btn-send-warning').forEach(button => {
            button.addEventListener('click', function() {
                const userId = this.getAttribute('data-user-id');

                if (confirm('Are you sure you want to send a warning to this user?')) {
                    fetch(`/backoffice/customers/${userId}/warning`, {
                            method: 'POST',
                            headers: {
                                'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>',
                                'Accept': 'application/json',
                                'Content-Type': 'application/json'
                            }
                        })
                        .then(res => res.json())
                        .then(data => {
                            alert(data.message);
                        })
                        .catch(err => {
                            console.error('Error:', err);
                            alert('An error occurred while sending the warning.');
                        });
                }
            });
        });
    </script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('backoffice.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home2/gccdemo/public_html/repositories/blinddate/resources/views/backoffice/customer/index.blade.php ENDPATH**/ ?>