<?php $__env->startSection('title', 'Stock Management - ' . $product->name); ?>

<?php $__env->startSection('actions'); ?>
<div>
    <a href="<?php echo e(route('products.show', $product)); ?>" class="btn btn-info">
        <i class="fas fa-eye"></i> View Product
    </a>
    <a href="<?php echo e(route('products.index')); ?>" class="btn btn-secondary">
        <i class="fas fa-arrow-left"></i> Back
    </a>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-4">
            <!-- Product Info Card -->
            <div class="card mb-4">
                <div class="card-header">
                    <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i>Product Information</h5>
                </div>
                <div class="card-body">
                    <table class="table table-sm">
                        <tr>
                            <th>Name:</th>
                            <td><?php echo e($product->name); ?></td>
                        </tr>
                        <tr>
                            <th>Code:</th>
                            <td><?php echo e($product->code); ?></td>
                        </tr>
                        <tr>
                            <th>Category:</th>
                            <td><?php echo e($product->category->name ?? 'N/A'); ?></td>
                        </tr>
                        <tr>
                            <th>Current Stock:</th>
                            <td>
                                <span class="badge bg-<?php echo e($product->stock_quantity > $product->minimum_stock ? 'success' : 'danger'); ?> fs-6">
                                    <?php echo e($product->stock_quantity); ?> units
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <th>Minimum Stock:</th>
                            <td><?php echo e($product->minimum_stock); ?> units</td>
                        </tr>
                    </table>
                </div>
            </div>

            <!-- Update Stock Card -->
            <div class="card">
                <div class="card-header bg-warning">
                    <h5 class="mb-0"><i class="fas fa-edit me-2"></i>Update Stock</h5>
                </div>
                <div class="card-body">
                    <form action="<?php echo e(route('products.stock.update', $product)); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        
                        <div class="mb-3">
                            <label class="form-label">Action <span class="text-danger">*</span></label>
                            <div>
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="type" id="type_add" value="add" checked>
                                    <label class="form-check-label" for="type_add">Add Stock</label>
                                </div>
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="type" id="type_subtract" value="subtract">
                                    <label class="form-check-label" for="type_subtract">Remove Stock</label>
                                </div>
                            </div>
                        </div>

                        <div class="mb-3">
                            <label for="quantity" class="form-label">Quantity <span class="text-danger">*</span></label>
                            <input type="number" name="quantity" id="quantity" 
                                   class="form-control" min="1" required>
                        </div>

                        <div class="mb-3">
                            <label for="reason" class="form-label">Reason <span class="text-danger">*</span></label>
                            <select name="reason" id="reason" class="form-select" required>
                                <option value="">Select Reason</option>
                                <option value="purchase">New Purchase</option>
                                <option value="sale">Sale</option>
                                <option value="return">Customer Return</option>
                                <option value="damage">Damaged</option>
                                <option value="adjustment">Stock Adjustment</option>
                                <option value="transfer">Stock Transfer</option>
                                <option value="other">Other</option>
                            </select>
                        </div>

                        <button type="submit" class="btn btn-primary w-100">
                            <i class="fas fa-save me-2"></i>Update Stock
                        </button>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-md-8">
            <!-- Stock Movement History -->
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0"><i class="fas fa-history me-2"></i>Stock Movement History</h5>
                </div>
                <div class="card-body">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Date</th>
                                <th>Type</th>
                                <th>Quantity</th>
                                <th>Old Stock</th>
                                <th>New Stock</th>
                                <th>Reason</th>
                                <th>Updated By</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $movements; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $movement): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td><?php echo e($movement->created_at->format('Y-m-d H:i')); ?></td>
                                <td>
                                    <span class="badge bg-<?php echo e($movement->type == 'add' ? 'success' : 'danger'); ?>">
                                        <?php echo e(ucfirst($movement->type)); ?>

                                    </span>
                                </td>
                                <td><?php echo e($movement->quantity); ?></td>
                                <td><?php echo e($movement->old_quantity); ?></td>
                                <td><?php echo e($movement->new_quantity); ?></td>
                                <td><?php echo e($movement->reason); ?></td>
                                <td><?php echo e($movement->user->name ?? 'System'); ?></td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="7" class="text-center">No stock movements found.</td>
                            </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>

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

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/naowarin/walton.naowarinternational.my.id/resources/views/products/stock.blade.php ENDPATH**/ ?>