<?php $__env->startSection('title', 'Product List'); ?>

<?php $__env->startPush('css'); ?>
    <!-- DataTables -->
    <link rel="stylesheet" href="/assets/plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
    <link rel="stylesheet" href="/assets/plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
    <link rel="stylesheet" href="/assets/plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
<?php $__env->stopPush(); ?>

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



    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>Product List</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="<?php echo e(routeHelper('dashboard')); ?>">Home</a></li>
                        <li class="breadcrumb-item active">Product List</li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>


    <?php if(setting('ALL_PRODUCTS_LOAD_SINGLE_DB_REQ') != "1"): ?>
        <section class="container-fluid">
            <div class="row">
                <div class="col-12 col-md-12">
                    <input id="SearchProducts" class="border border-info rounded py-2 px-3" type="text" placeholder="Search product name">
                </div>
                <ul class="col-12 col-md-12" id="searchResults"></ul>
            </div>
        </section>
        <?php $__env->startPush('js'); ?>
        <script>
            // Search URL
            var searchUrl = "<?php echo route('admin.product.search'); ?>";
            
            // Search Event
            $('#SearchProducts').keyup(function(e){
                
                // Search Keyword
                var keyword = this.value;
        
                if(keyword != ""){
                    $.ajax({
                        url: searchUrl,
                        method: "GET",
                        data: { keyword: keyword },
                        success: function(response) {
                            if(response.status === 'success') {
                                let products = response.Data;
                                // console.log(products);

                                // Clear any previous results
                                $('#searchResults').empty();
        
                                // Append the new results
                                products.forEach(function(product) {
                                    $('#searchResults').append(`
                                        <li class="bg-white border border-info mt-1 py-1 px-2">
                                            <a href="/admin/product/order/${product.id}" title="Order Product" class="btn btn-primary btn-sm">
                                                <i class="fab fa-jedi-order"></i>
                                            </a>
                                            <a href="/admin/product/${product.id}/edit" title="Edit Product" class="btn btn-primary btn-sm">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                            ${product.status == 0 ? 
                                                `<a title="Active" href="/admin/product/status/${product.id}" class="btn btn-warning btn-sm">
                                                    <i class="fas fa-thumbs-down"></i>
                                                </a>` : 
                                                `<a title="Disable" href="/admin/product/status/${product.id}" class="btn btn-success btn-sm">
                                                    <i class="fas fa-thumbs-up"></i>
                                                </a>`
                                            } 
                                            &nbsp;&nbsp;${product.title}&nbsp;&nbsp;|&nbsp;&nbsp;<span class="text-sm">${product.shop_info.name}</span>
                                        </li>
                                    `);
                                });
                            } else {
                                console.error('Search failed:', response);
                            }
                        },
                        error: function(xhr, status, error) {
                            console.error('An error occurred:', error);
                        }
                    });
                } else {
                    // Clear results if the input is empty
                    $('#searchResults').empty();
                }
            });
        </script>
        <?php $__env->stopPush(); ?>
    <?php endif; ?>




    <!-- Main content -->
    <section class="content">

        <div class="card">
            <div class="card-header">
                <div class="row">
                    <div class="col-sm-6">
                        <h3 class="card-title">Product List</h3>
                    </div>
                    <div class="col-sm-6 text-right">
                        <a href="<?php echo e(routeHelper('product/create')); ?>" class="btn btn-success">
                            <i class="fas fa-plus-circle"></i>
                            Add Product
                        </a>
                    </div>
                </div>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
                <table id="example1" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Image</th>
                            <th>Title</th>
                            <th>RP</th>
                            <th>DP</th>
                            <th>Stock</th>
                            <th>Brand</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($data->id); ?></td>
                                <td>
                                    <img src="<?php echo e(asset('uploads/product/' . $data->image)); ?>" alt="Product Image"
                                        width="60px">
                                </td>
                                <td>
                                    <?php echo e($data->title); ?>

                                    <?php
                                        $user = App\Models\User::find($data->user_id);
                                    ?>
                                    <?php if($user && ($user->role_id == 1 || $user->id == $data->user_id && isset($data->shop_info->name))): ?>
                                    <br>
                                    <small>
                                        <?php if($data->user_id == 1): ?>
                                            <?php echo e($data->shop_info->name ?? ''); ?>

                                        <?php else: ?>
                                            <a href="<?php echo e(routeHelper('vendor/'.$data->user_id)); ?>" class="text-primary">
                                                Vendor: <?php echo e($data->shop_info->name ?? ''); ?>

                                            </a>
                                        <?php endif; ?>
                                        <?php echo e(($data->sku) ? ', SKU: ' . $data->sku : ''); ?>

                                    </small>
                                    <?php endif; ?>
                                </td>
                                <td><?php echo e($data->regular_price); ?></td>
                                <td><?php echo e($data->discount_price); ?></td>
                                <td>
                                    <?php echo e($data->quantity); ?>

                                    <?php if($data->quantity > 0): ?>
                                        <span class="badge badge-success">Available</span>
                                    <?php else: ?>
                                        <span class="badge badge-danger">Unavailable</span>
                                    <?php endif; ?>
                                </td>
                                <td><?php echo e($data->brand->name ?? ''); ?></td>
                                <td>
                                    <?php if($data->status): ?>
                                        <span class="badge badge-success">Active</span>
                                    <?php else: ?>
                                        <span class="badge badge-danger">Disable</span>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <div class="btn-group">
                                        <a href="<?php echo e(route('admin.product.order', $data->id)); ?>" title="Order Product"
                                            class="btn btn-primary btn-sm">
                                            <i class="fab fa-jedi-order"></i>
                                        </a>
                                        <?php if($data->status): ?>
                                            <a title="Disable" href="<?php echo e(routeHelper('product/status/' . $data->id)); ?>"
                                                class="btn btn-success btn-sm">
                                                <i class="fas fa-thumbs-up"></i>
                                            </a>
                                        <?php else: ?>
                                            <a title="Active" href="<?php echo e(routeHelper('product/status/' . $data->id)); ?>"
                                                class="btn btn-warning btn-sm">
                                                <i class="fas fa-thumbs-down"></i>
                                            </a>
                                        <?php endif; ?>
                                        <a href="<?php echo e(routeHelper('product/' . $data->id)); ?>" class="btn btn-primary btn-sm">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                        <a href="<?php echo e(routeHelper('product/' . $data->id . '/edit')); ?>"
                                            class="btn btn-info btn-sm">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                        <?php if($data->sku): ?>
                                        <a href="<?php echo e(routeHelper('product/' . $data->id . '/barcode')); ?>"
                                            class="btn btn-primary btn-sm">
                                                <i class="fas fa-barcode"></i>
                                            </a>
                                        <?php endif; ?>
                                        <?php if(auth()->user()->desig != 3): ?>
                                            <a href="javascript:void(0)" data-id="<?php echo e($data->id); ?>" id="deleteData"
                                                class="btn btn-danger btn-sm">
                                                <i class="nav-icon fas fa-trash-alt"></i>
                                            </a>
                                        <?php endif; ?>
                                        <form id="delete-data-form-<?php echo e($data->id); ?>"
                                            action="<?php echo e(routeHelper('product/' . $data->id)); ?>" method="POST">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                        </form>
                                    </div><br>
                                    <div class="btn-group">
                                        <?php if(auth()->user()->desig != 3): ?>
                                            <?php if($data->status_landing_page == 1): ?>    
                                                <a title="Status: Active to Inactive" href="<?php echo e(routeHelper('product/status_landing_page?id=' . $data->id . '&status=null')); ?>" class="btn btn-success btn-sm">
                                                    <svg style="width: 1rem;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="size-4">
                                                        <path fill-rule="evenodd" d="M11.986 3H12a2 2 0 0 1 2 2v6a2 2 0 0 1-1.5 1.937V7A2.5 2.5 0 0 0 10 4.5H4.063A2 2 0 0 1 6 3h.014A2.25 2.25 0 0 1 8.25 1h1.5a2.25 2.25 0 0 1 2.236 2ZM10.5 4v-.75a.75.75 0 0 0-.75-.75h-1.5a.75.75 0 0 0-.75.75V4h3Z" clip-rule="evenodd" />
                                                        <path fill-rule="evenodd" d="M2 7a1 1 0 0 1 1-1h7a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V7Zm6.585 1.08a.75.75 0 0 1 .336 1.005l-1.75 3.5a.75.75 0 0 1-1.16.234l-1.75-1.5a.75.75 0 0 1 .977-1.139l1.02.875 1.321-2.64a.75.75 0 0 1 1.006-.336Z" clip-rule="evenodd" />
                                                    </svg>                                                                                                            
                                                </a>
                                                <a title="View Landing Page" target="_blank" href="<?php echo e(url('/product/landing/' . $data->slug)); ?>" class="btn btn-success btn-sm">
                                                    <svg style="width: 1rem;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="size-4">
                                                        <path fill-rule="evenodd" d="M11.986 3H12a2 2 0 0 1 2 2v6a2 2 0 0 1-1.5 1.937V7A2.5 2.5 0 0 0 10 4.5H4.063A2 2 0 0 1 6 3h.014A2.25 2.25 0 0 1 8.25 1h1.5a2.25 2.25 0 0 1 2.236 2ZM10.5 4v-.75a.75.75 0 0 0-.75-.75h-1.5a.75.75 0 0 0-.75.75V4h3Z" clip-rule="evenodd" />
                                                        <path fill-rule="evenodd" d="M3 6a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1h7a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1H3Zm1.75 2.5a.75.75 0 0 0 0 1.5h3.5a.75.75 0 0 0 0-1.5h-3.5ZM4 11.75a.75.75 0 0 1 .75-.75h3.5a.75.75 0 0 1 0 1.5h-3.5a.75.75 0 0 1-.75-.75Z" clip-rule="evenodd" />
                                                    </svg>
                                                </a>
                                            <?php elseif($data->status_landing_page == null || $data->status_landing_page == 'null'): ?>
                                                <a title="Status: Inactive to Active" href="<?php echo e(routeHelper('product/status_landing_page?id=' . $data->id . '&status=1')); ?>" class="btn btn-warning btn-sm">
                                                    <svg style="width: 1rem;" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
                                                        <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />
                                                    </svg>                                                      
                                                </a>
                                            <?php elseif($data->status_landing_page == 0): ?>
                                                <a title="Status: Cancel the pending request - Landing Page" href="<?php echo e(routeHelper('product/status_landing_page?id=' . $data->id . '&status=null')); ?>" class="btn btn-danger btn-sm">
                                                    <svg style="width: 1rem;" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
                                                        <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />
                                                    </svg>
                                                </a>
                                                <a title="Status: Active the pending request - Landing Page" href="<?php echo e(routeHelper('product/status_landing_page?id=' . $data->id . '&status=1')); ?>" class="btn btn-success btn-sm">
                                                    <svg style="width: 1rem;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="size-4">
                                                        <path fill-rule="evenodd" d="M11.986 3H12a2 2 0 0 1 2 2v6a2 2 0 0 1-1.5 1.937V7A2.5 2.5 0 0 0 10 4.5H4.063A2 2 0 0 1 6 3h.014A2.25 2.25 0 0 1 8.25 1h1.5a2.25 2.25 0 0 1 2.236 2ZM10.5 4v-.75a.75.75 0 0 0-.75-.75h-1.5a.75.75 0 0 0-.75.75V4h3Z" clip-rule="evenodd" />
                                                        <path fill-rule="evenodd" d="M2 7a1 1 0 0 1 1-1h7a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V7Zm6.585 1.08a.75.75 0 0 1 .336 1.005l-1.75 3.5a.75.75 0 0 1-1.16.234l-1.75-1.5a.75.75 0 0 1 .977-1.139l1.02.875 1.321-2.64a.75.75 0 0 1 1.006-.336Z" clip-rule="evenodd" />
                                                    </svg>                                                                                                            
                                                </a>
                                            <?php else: ?>
                                                <a title="Status: Inactive to Active" href="<?php echo e(routeHelper('product/status_landing_page?id=' . $data->id . '&status=1')); ?>" class="btn btn-warning btn-sm">
                                                    <svg style="width: 1rem;" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
                                                        <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />
                                                    </svg>                                                      
                                                </a>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                    </tbody>
                    <tfoot>
                        <tr>
                            <th>SL</th>
                            <th>Image</th>
                            <th>Title</th>
                            <th>RP</th>
                            <th>DP</th>
                            <th>Stock</th>
                            <th>Brand</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </tfoot>
                </table>

                
                <?php if(setting('ALL_PRODUCTS_LOAD_SINGLE_DB_REQ') != "1"): ?>
                    <?php echo $__env->make('components.paginate', ['paginate' => $products], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                <?php endif; ?>
                


            </div>
            <!-- /.card-body -->
        </div>
        <!-- /.card -->

    </section>
    <!-- /.content -->

<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
    <!-- DataTables  & Plugins -->
    <script src="/assets/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="/assets/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
    <script src="/assets/plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
    <script src="/assets/plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
    <script src="/assets/plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
    <script src="/assets/plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
    <script src="/assets/plugins/jszip/jszip.min.js"></script>
    <script src="/assets/plugins/pdfmake/pdfmake.min.js"></script>
    <script src="/assets/plugins/pdfmake/vfs_fonts.js"></script>
    <script src="/assets/plugins/datatables-buttons/js/buttons.html5.min.js"></script>
    <script src="/assets/plugins/datatables-buttons/js/buttons.print.min.js"></script>
    <script src="/assets/plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
    <script>
        
        $(function() {
            $("#example1").DataTable({
                "responsive": true,
                "lengthChange": true,
                "paging": <?php echo (setting('ALL_PRODUCTS_LOAD_SINGLE_DB_REQ') == "1") ? 'true' : 'false'; ?>, // This will be true or false based on your condition
                "info": false, // Hide information element
                "searching": <?php echo (setting('ALL_PRODUCTS_LOAD_SINGLE_DB_REQ') == "1") ? 'true' : 'false'; ?>, // This will be true or false based on your condition
                "autoWidth": false,
                "pageLength": <?php echo setting('ALL_PRODUCTS_PER_PAGE') ?? 10; ?>, // Set page length based on setting, default to 10
                "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"],
                "order": [[0, 'desc']], // Default sorting by the first column in descending order
                "columnDefs": [
                    { "orderable": true, "targets": "_all" }, // Ensure all columns are sortable
                ]
            }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
        })
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.admin.e-commerce.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/apleusbj/shopping.apleefix.com/resources/views/admin/e-commerce/product/index.blade.php ENDPATH**/ ?>