

<?php $__env->startSection('section'); ?>
    <div class="page-body">
        <div class="container-fluid">
            <div class="row page-title">
                <div class="col-sm-6">
                    <h3>Category List</h3>
                </div>
                <div class="col-sm-6 text-end">
                    <a class="btn btn-primary" href="<?php echo e(route('category.add')); ?>">
                        <svg class="feather">
                            <use href="<?php echo e(asset('assets/svg/feather-icons/dist/feather-sprite.svg#plus-square')); ?>"></use>
                        </svg>
                        Add New Category
                    </a>
                </div>
            </div>
        </div>

        <div class="container-fluid list-products mt-3">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive theme-scrollbar product-table">
                        <table class="display table table-bordered" id="basic-3">
                            <thead>
                                <tr>
                                    <th>S.No</th>
                                    <th>Name</th>
                                    <th>Details</th>
                                    <th>Status</th>
                                    <th>Created By</th>
                                    <th>Created At</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td><?php echo e($loop->iteration); ?></td>
                                        <td><?php echo e($category->name); ?></td>
                                        <td><?php echo e(Str::limit($category->description, 50)); ?></td>
                                        <td><span
                                            class="badge rounded-pill toggle-status <?php echo e($category->status ? 'bg-success' : 'bg-danger'); ?>"
                                            data-id="<?php echo e($category->id); ?>" style="cursor: pointer;">
                                            <?php echo e($category->status ? 'Active' : 'Inactive'); ?>

                                        </span>
                                    </td>

                                        <td><?php echo e($category->createdBy->name ?? 'N/A'); ?></td>
                                        <td><?php echo e($category->created_at->format('Y-m-d')); ?></td>
                                        <td>
                                            <a href="<?php echo e(route('edit.category', $category->id)); ?>" class="btn btn-sm btn-primary"
                                                title="Edit">
                                                Edit
                                            </a>
                                            <form action="<?php echo e(route('delete.category', $category->id)); ?>" method="POST"
                                                class="d-inline-block"
                                                onsubmit="return confirm('Are you sure you want to delete this category?');">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('DELETE'); ?>
                                                <button type="submit" class="btn btn-sm btn-danger"
                                                    title="Delete">Delete</button>
                                            </form>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="7" class="text-center">No categories found.</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="<?php echo e(asset('assets/js/vendors/simple-datatables/dist/umd/simple-datatables.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/js/product/product-list-custom.js')); ?>"></script>
    <script>
       
        document.addEventListener("DOMContentLoaded", function () {
            const statusButtons = document.querySelectorAll('.toggle-status');

            statusButtons.forEach(button => {
                button.addEventListener('click', function () {
                    const categoryId = this.getAttribute('data-id');

                    fetch("<?php echo e(route('category.changeStatusAjax')); ?>", {
                        method: 'POST',
                        headers: {
                            'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>',
                            'Content-Type': 'application/json'
                        },
                        body: JSON.stringify({ id: categoryId })
                    })
                        .then(response => response.json())
                        .then(data => {
                            if (data.success) {
                                this.classList.toggle('bg-success', data.status == 1);
                                this.classList.toggle('bg-danger', data.status == 0);
                                this.textContent = data.status == 1 ? 'Active' : 'Inactive';
                            }
                        })
                        .catch(error => console.error('Error:', error));
                });
            });
        });
    </script>


    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.main', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\NEWXAMP\htdocs\newssite.com\resources\views/admin/Category/list.blade.php ENDPATH**/ ?>