

<?php $__env->startSection('title', 'Inventory'); ?>
<?php $__env->startSection('page-title', 'Inventory Management'); ?>

<?php $__env->startSection('content'); ?>
<div class="bg-white rounded-lg shadow">
    <div class="p-6 border-b border-gray-200">
        <h3 class="text-lg font-semibold text-gray-800">Inventory</h3>
    </div>

    <div class="p-6">
        <!-- Filters -->
        <form method="GET" class="mb-4 flex gap-4">
            <input type="text" name="search" value="<?php echo e(request('search')); ?>" placeholder="Search products..." 
                   class="border rounded px-4 py-2 flex-1">
            <?php if(request('low_stock')): ?>
                <input type="hidden" name="low_stock" value="1">
            <?php endif; ?>
            <button type="submit" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded">
                Search
            </button>
            <?php if(!request('low_stock')): ?>
            <a href="<?php echo e(route('admin.inventory.index', ['low_stock' => 1])); ?>" class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
                Show Low Stock Only
            </a>
            <?php endif; ?>
        </form>

        <!-- Inventory Table -->
        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50">
                    <tr>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Product</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Variant</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">SKU</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Current Stock</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Min Level</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Actions</th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    <?php $__empty_1 = true; $__currentLoopData = $variants; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $variant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr class="<?php echo e($variant->isLowStock() ? 'bg-red-50' : ''); ?>">
                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                            <?php echo e($variant->product->name); ?>

                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?php echo e($variant->name); ?></td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?php echo e($variant->sku ?? '-'); ?></td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm font-semibold <?php echo e($variant->isLowStock() ? 'text-red-600' : 'text-gray-900'); ?>">
                            <?php echo e($variant->stock_quantity); ?>

                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?php echo e($variant->min_stock_level); ?></td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="px-2 py-1 text-xs rounded-full <?php echo e($variant->is_active ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'); ?>">
                                <?php echo e($variant->is_active ? 'Active' : 'Inactive'); ?>

                            </span>
                            <?php if($variant->isLowStock()): ?>
                                <span class="ml-2 px-2 py-1 text-xs rounded-full bg-red-100 text-red-800">Low Stock</span>
                            <?php endif; ?>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                            <button onclick="showUpdateStockModal(<?php echo e($variant->id); ?>, '<?php echo e($variant->product->name); ?>', '<?php echo e($variant->name); ?>', <?php echo e($variant->stock_quantity); ?>)" 
                                    class="text-blue-600 hover:text-blue-900 mr-3">
                                <i class="fas fa-edit"></i> Update
                            </button>
                            <a href="<?php echo e(route('admin.inventory.history', $variant)); ?>" class="text-green-600 hover:text-green-900">
                                <i class="fas fa-history"></i> History
                            </a>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="7" class="px-6 py-8 text-center text-gray-500">No inventory items found</td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>

        <!-- Pagination -->
        <div class="mt-4">
            <?php echo e($variants->links()); ?>

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

<!-- Update Stock Modal -->
<div id="stockModal" class="hidden fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50">
    <div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
        <div class="mt-3">
            <h3 class="text-lg font-medium text-gray-900 mb-4">Update Stock</h3>
            <form id="stockForm" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>
                <div class="mb-4">
                    <label class="block text-sm font-medium text-gray-700">Product</label>
                    <p id="modal-product" class="text-sm text-gray-600"></p>
                </div>
                <div class="mb-4">
                    <label class="block text-sm font-medium text-gray-700">Variant</label>
                    <p id="modal-variant" class="text-sm text-gray-600"></p>
                </div>
                <div class="mb-4">
                    <label class="block text-sm font-medium text-gray-700">Current Stock</label>
                    <p id="modal-current" class="text-sm text-gray-600"></p>
                </div>
                <div class="mb-4">
                    <label for="quantity" class="block text-sm font-medium text-gray-700">New Quantity *</label>
                    <input type="number" name="quantity" id="quantity" required min="0"
                           class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3">
                </div>
                <div class="mb-4">
                    <label for="type" class="block text-sm font-medium text-gray-700">Update Type *</label>
                    <select name="type" id="type" required
                            class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3">
                        <option value="adjustment">Adjustment (Set to quantity)</option>
                        <option value="in">Stock In (Add to current)</option>
                        <option value="out">Stock Out (Subtract from current)</option>
                    </select>
                </div>
                <div class="mb-4">
                    <label for="notes" class="block text-sm font-medium text-gray-700">Notes</label>
                    <textarea name="notes" id="notes" rows="2"
                              class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3"></textarea>
                </div>
                <div class="flex justify-end space-x-4">
                    <button type="button" onclick="closeStockModal()" class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded">
                        Cancel
                    </button>
                    <button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
                        Update Stock
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<?php $__env->startPush('scripts'); ?>
<script>
function showUpdateStockModal(variantId, productName, variantName, currentStock) {
    document.getElementById('modal-product').textContent = productName;
    document.getElementById('modal-variant').textContent = variantName;
    document.getElementById('modal-current').textContent = currentStock;
    document.getElementById('stockForm').action = `/admin/inventory/${variantId}/stock`;
    document.getElementById('stockModal').classList.remove('hidden');
}

function closeStockModal() {
    document.getElementById('stockModal').classList.add('hidden');
}
</script>
<?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\laragon\www\ReactNative\grocery-api\resources\views/admin/inventory/index.blade.php ENDPATH**/ ?>