
<?php $__env->startSection('content'); ?>
    <!-- begin::main content -->
    <main class="main-content">
        <div class="container">
            <!-- begin::page header -->
            <div class="page-header">
                <h3>Category Management</h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="<?php echo e(asset('dashboard')); ?>"><?php echo e(__('message.dashboard')); ?></a></li>
                        <li class="breadcrumb-item active" aria-current="page">Categories</li>
                    </ol>
                </nav>
            </div>
            <!-- end::page header -->
            
            <div class="card">
            <?php if (isset($component)) { $__componentOriginal8a5ba9c90b64d384232e9948b1023e746ba08e74 = $component; } ?>
<?php $component = $__env->getContainer()->make(App\View\Components\FlashMessage::class, []); ?>
<?php $component->withName('flashMessage'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes([]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal8a5ba9c90b64d384232e9948b1023e746ba08e74)): ?>
<?php $component = $__componentOriginal8a5ba9c90b64d384232e9948b1023e746ba08e74; ?>
<?php unset($__componentOriginal8a5ba9c90b64d384232e9948b1023e746ba08e74); ?>
<?php endif; ?>
                <div class="card-header">
                    <div class="row mt-3">
                        <div class="col-md-5">
                            <form action="<?php echo e(asset('account/category')); ?>" method="get">
                                <div class="input-group">
                                    <input type="search" value="<?php echo e(request('search')); ?>" name="search" placeholder="Search categories..." class="form-control border-right-0 seach-input">
                                    <button class="btn border border-left-0" type="submit">
                                        <i class="ti ti-search fa-lg"></i>
                                    </button>
                                    <a class="btn btn-white border" href="<?php echo e(asset('account/category')); ?>">
                                        <i class="ti ti-reload fa-lg"></i>
                                    </a>
                                </div>
                            </form>
                        </div>
                        <div class="col-md-4"></div>
                        <div class="col-md-3 d-flex justify-content-end">
                            <button class="btn btn-primary" data-toggle="modal" data-target="#addCategoryModal">
                                <i class="ti ti-plus fa-lg"></i> Add Category
                            </button>
                        </div>
                    </div>
                </div>

                <div class="card-body">
                    <?php if($categories->count() > 0): ?>
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>S.NO</th>
                                        <th>NAME</th>
                                        <th>DESCRIPTION</th>
                                        <th>ACTION</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td><?php echo e(++$key); ?></td>
                                            <td><?php echo e($category->name); ?></td>
                                            <td><?php echo e(Str::limit($category->description, 50)); ?></td>
                                                                                        
                                            <td>
                                                <div class="btn-group">
                                                    <button class="btn btn-sm btn-outline-primary edit-category-btn" 
                                                        data-id="<?php echo e($category->id); ?>"
                                                        data-name="<?php echo e($category->name); ?>"
                                                        data-description="<?php echo e($category->description); ?>"
                                                        >
                                                        <i class="fa fa-edit"></i>
                                                    </button>
                                                    <button class="btn btn-sm btn-outline-danger delete-category-btn" 
                                                        cat_id="<?php echo e($category->id); ?>">
                                                        <i class="ti ti-trash fa-lg"></i>
                                                    </button>
                                                </div>
                                            </td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                        
                        <div class="mt-3 d-flex justify-content-center">
                            <?php echo e($categories->links('pagination::bootstrap-4')); ?>

                        </div>
                    <?php else: ?>
                        <div class="alert alert-info">No categories found. Add your first category!</div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <!-- Add Category Modal -->
        <div class="modal fade" id="addCategoryModal" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Add New Category</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <form action="<?php echo e(asset('account/add-category')); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        <div class="modal-body">
                            <div class="form-group">
                                <label>Category Name *</label>
                                <input type="text" name="name" class="form-control" required>
                            </div>
                            <div class="form-group">
                                <label>Description</label>
                                <textarea name="description" class="form-control" rows="3"></textarea>
                            </div>
                            
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <button type="submit" class="btn btn-primary">Save Category</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <!-- Edit Category Modal -->
        <div class="modal fade" id="editCategoryModal" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Edit Category</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <form action="<?php echo e(asset('account/add-category')); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="category_id" id="category_id">
                        <div class="modal-body">
                            <div class="form-group">
                                <label>Category Name *</label>
                                <input type="text" name="name" id="editCategoryName" class="form-control" required>
                            </div>
                            <div class="form-group">
                                <label>Description</label>
                                <textarea name="description" id="editCategoryDescription" class="form-control" rows="3"></textarea>
                            </div>
                            
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <button type="submit" class="btn btn-primary">Update Category</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </main>
    <!-- end::main content -->
<?php $__env->stopSection(); ?>

<?php $__env->startPush('footer-script'); ?>
    <script>
        $(document).ready(function() {
            // Edit Category Button Click
            $('.edit-category-btn').click(function() {
                var categoryId = $(this).data('id');
                var categoryName = $(this).data('name');
                var categoryDescription = $(this).data('description');
                
                
                $('#category_id').val(categoryId);
                $('#editCategoryName').val(categoryName);
                $('#editCategoryDescription').val(categoryDescription);
                
                
                $('#editCategoryModal').modal('show');
            });

            // Delete Category Button Click
            $('.delete-category-btn').click(function() {
                var category_id = $(this).attr('cat_id');
                
                
                swal({
                    title: 'Are you sure?',
                    text: 'All items in this category will be moved to uncategorized!',
                    icon: 'warning',
                    dangerMode: true,
                    buttons: ["Cancel", "Delete"],
                }).then(function(value) {
                    if (value) {
                        $.ajax({
                            url: "<?php echo e(asset('account/delete-category')); ?>",
                            type: 'post',
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            data: {
                                "category_id":category_id
                            },
                            success: function(result) {
                                swal("Success!", "Category deleted successfully!", "success");
                                setTimeout(function() {
                                    window.location.reload();
                                }, 1000);
                            },
                            error: function(xhr) {
                                swal("Error!", "Failed to delete category!", "error");
                            }
                        });
                    }
                });
            });

            
        });
    </script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\blurb_erp\resources\views/accounting/category/list.blade.php ENDPATH**/ ?>