

<?php $__env->startSection('content'); ?>
    <div class="container-xxl flex-grow-1 container-p-y">
        <div class="card">
            <div class="card-header">
                <div class="row align-items-center">
                    <div class="col-8">
                        <h5 class="card-title mb-0">Stock Management</h5>
                    </div>
                    <div class="col-4 text-end">
                        <a href="<?php echo e(route('stocks.create')); ?>" class="btn btn-primary">
                            <i class="fas fa-plus me-2"></i>Add Stock
                        </a>
                    </div>
                </div>
                <hr />
            </div>

            <div class="card-body">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session('success')): ?>
                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                        <?php echo e(session('success')); ?>

                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                    </div>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

                <div class="table-responsive">
                     <table <?php if($stocks->count() > 0): ?> id="bookings-table"  <?php endif; ?> class="table table-bordered align-middle text-center">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Product</th>
                                <th>Status</th>
                                <th>Quantity</th>
                                <th>Approval</th>
                                <th>Next Arrival</th>
                                <th>Restock Date</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $stocks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stock): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td><?php echo e($stock->id); ?></td>
                                    <td>
                                        <strong><?php echo e($stock->product->name); ?></strong>
                                        
                                    </td>
                                    <td>
                                        <?php
                                            $statusColors = [
                                                'in_stock' => 'success',
                                                'out_of_stock' => 'danger',
                                                'arriving' => 'warning'
                                            ];
                                        ?>
                                        <span class="badge bg-<?php echo e($statusColors[$stock->availability_status] ?? 'secondary'); ?>">
                                            <?php echo e(str_replace('_', ' ', ucfirst($stock->availability_status))); ?>

                                        </span>
                                    </td>
                                    <td>
                                        <span class="fw-bold"><?php echo e($stock->quantity); ?></span>
                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($stock->quantity == 0): ?>
                                            <br><small class="text-danger">Out of stock</small>
                                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    </td>
                                    <td>
                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($stock->requires_approval): ?>
                                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($stock->is_approved): ?>
                                                <span class="badge bg-success">Approved</span>
                                            <?php else: ?>
                                                <span class="badge bg-warning">Pending</span>
                                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                        <?php else: ?>
                                            <span class="badge bg-info">No Approval Needed</span>
                                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    </td>
                                    <td>
                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($stock->next_arrival_date): ?>
                                            <?php echo e(date('M d, Y', strtotime($stock->next_arrival_date))); ?>

                                        <?php else: ?>
                                            <span class="text-muted">N/A</span>
                                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    </td>
                                    <td>
                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($stock->expected_restock_date): ?>
                                            <?php echo e(date('M d, Y', strtotime($stock->expected_restock_date))); ?>

                                        <?php else: ?>
                                            <span class="text-muted">N/A</span>
                                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    </td>
                                    <td>
                                        <div class="btn-group" role="group">
                                            
                                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('view stocks')): ?>
                                            <a href="<?php echo e(route('stocks.show', $stock)); ?>" 
                                            class="btn btn-sm btn-info" 
                                            title="View">
                                                <i class="fas fa-eye"></i>
                                            </a>
                                            <?php endif; ?>

                                            
                                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('update stock')): ?>
                                            <a href="<?php echo e(route('stocks.edit', $stock)); ?>" 
                                            class="btn btn-sm btn-warning" 
                                            title="Edit">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                            <?php endif; ?>

                                            
                                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('delete stock')): ?>
                                            <form action="<?php echo e(route('stocks.destroy', $stock)); ?>" 
                                                method="POST" 
                                                class="d-inline"
                                                onsubmit="return confirm('Are you sure you want to delete this stock record?');">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('DELETE'); ?>
                                                <button type="submit" class="btn btn-sm btn-danger" title="Delete">
                                                    <i class="fas fa-trash"></i>
                                                </button>
                                            </form>
                                            <?php endif; ?>
                                        </div>

                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="8" class="text-center">No stock records found.</td>
                                </tr>
                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </tbody>
                    </table>
                </div>

                <div class="mt-3">
                    <?php echo e($stocks->links()); ?>

                </div>

                <div class="mt-4">
                    <div class="row">
                        <div class="col-md-3">
                            <div class="card bg-success text-white">
                                <div class="card-body text-center">
                                    <h3 class="mb-0"><?php echo e($stocks->where('availability_status', 'in_stock')->count()); ?></h3>
                                    <p class="mb-0">In Stock</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card bg-danger text-white">
                                <div class="card-body text-center">
                                    <h3 class="mb-0"><?php echo e($stocks->where('availability_status', 'out_of_stock')->count()); ?></h3>
                                    <p class="mb-0">Out of Stock</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card bg-warning text-white">
                                <div class="card-body text-center">
                                    <h3 class="mb-0"><?php echo e($stocks->where('availability_status', 'arriving')->count()); ?></h3>
                                    <p class="mb-0">Arriving</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card bg-info text-white">
                                <div class="card-body text-center">
                                    <h3 class="mb-0"><?php echo e($stocks->where('is_approved', 0)->count()); ?></h3>
                                    <p class="mb-0">Pending Approval</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>



<?php $__env->startPush('script'); ?>
<script>
$(document).ready(function () {
    $('#bookings-table').DataTable({
        responsive: false, 
        scrollX: false,
        pageLength: 10,
        lengthMenu: [5, 10, 25, 50, 100],
        order: [[0, 'asc']], // first column # is sorted
        columnDefs: [
            { orderable: false, targets: -1 } // Actions column
        ]
    });
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH F:\xampp\htdocs\G_desizn\mfmsqatar\resources\views/stocks/index.blade.php ENDPATH**/ ?>