<?php $__env->startSection('title', $product->exists ? 'Edit Product' : 'Add Product'); ?>
<?php $__env->startSection('content'); ?>
<div class="page-head"><div><h1 class="page-title"><?php echo e($product->exists ? 'Edit Product' : 'Add Product'); ?></h1><div class="page-subtitle">Use clean master data, barcode, and pricing so stock and reports stay accurate.</div></div><a href="<?php echo e(route('admin.products.index')); ?>" class="btn btn-outline-primary">Back to List</a></div>
<form method="POST" action="<?php echo e($product->exists ? route('admin.products.update',$product) : route('admin.products.store')); ?>" enctype="multipart/form-data">
<?php echo csrf_field(); ?> <?php if($product->exists): ?> <?php echo method_field('PUT'); ?> <?php endif; ?>
<div class="row g-4">
<div class="col-lg-8"><div class="card card-body"><div class="row g-3">
<div class="col-md-6"><label class="form-label">Product Name</label><input class="form-control" name="product_name" value="<?php echo e(old('product_name',$product->product_name)); ?>" required></div>
<div class="col-md-3"><label class="form-label">Product Code</label><input class="form-control" name="product_code" value="<?php echo e(old('product_code',$product->product_code)); ?>" required></div>
<div class="col-md-3"><label class="form-label">Barcode</label><input class="form-control" name="barcode" value="<?php echo e(old('barcode',$product->barcode)); ?>"></div>
<div class="col-md-4"><label class="form-label">Category</label><select class="form-select" name="category_id" id="category_id"><option value="">Select</option><?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($item->id); ?>" data-name="<?php echo e($item->name); ?>" <?php if(old('category_id',$product->category_id)==$item->id || old('category',$product->category)==$item->name): echo 'selected'; endif; ?>><?php echo e($item->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select><input type="hidden" name="category" id="category_name" value="<?php echo e(old('category',$product->category)); ?>"></div>
<div class="col-md-4"><label class="form-label">Brand</label><select class="form-select" name="brand_id" id="brand_id"><option value="">Select</option><?php $__currentLoopData = $brands; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($item->id); ?>" data-name="<?php echo e($item->name); ?>" <?php if(old('brand_id',$product->brand_id)==$item->id || old('brand',$product->brand)==$item->name): echo 'selected'; endif; ?>><?php echo e($item->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select><input type="hidden" name="brand" id="brand_name" value="<?php echo e(old('brand',$product->brand)); ?>"></div>
<div class="col-md-4"><label class="form-label">Supplier</label><select class="form-select" name="supplier_id" id="supplier_id"><option value="">Select</option><?php $__currentLoopData = $suppliers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($item->id); ?>" data-name="<?php echo e($item->name); ?>" <?php if(old('supplier_id',$product->supplier_id)==$item->id || old('supplier_name',$product->supplier_name)==$item->name): echo 'selected'; endif; ?>><?php echo e($item->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select><input type="hidden" name="supplier_name" id="supplier_name" value="<?php echo e(old('supplier_name',$product->supplier_name)); ?>"></div>
<div class="col-md-4"><label class="form-label">Size</label><select class="form-select" name="size_id" id="size_id"><option value="">Select</option><?php $__currentLoopData = $sizes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($item->id); ?>" data-name="<?php echo e($item->name); ?>" <?php if(old('size_id',$product->size_id)==$item->id || old('size',$product->size)==$item->name): echo 'selected'; endif; ?>><?php echo e($item->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select><input type="hidden" name="size" id="size_name" value="<?php echo e(old('size',$product->size)); ?>"></div>
<div class="col-md-4"><label class="form-label">Color</label><select class="form-select" name="color_id" id="color_id"><option value="">Select</option><?php $__currentLoopData = $colors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($item->id); ?>" data-name="<?php echo e($item->name); ?>" <?php if(old('color_id',$product->color_id)==$item->id || old('color',$product->color)==$item->name): echo 'selected'; endif; ?>><?php echo e($item->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select><input type="hidden" name="color" id="color_name" value="<?php echo e(old('color',$product->color)); ?>"></div>
<div class="col-md-4"><label class="form-label">Unit</label><select class="form-select" name="unit_id" id="unit_id"><option value="">Select</option><?php $__currentLoopData = $units; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($item->id); ?>" data-name="<?php echo e($item->name); ?>" <?php if(old('unit_id',$product->unit_id)==$item->id || old('unit',$product->unit)==$item->name): echo 'selected'; endif; ?>><?php echo e($item->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select><input type="hidden" name="unit" id="unit_name" value="<?php echo e(old('unit',$product->unit)); ?>"></div>
<div class="col-md-3"><label class="form-label">Opening Stock</label><input class="form-control" type="number" min="0" name="stock_quantity" value="<?php echo e(old('stock_quantity',$product->stock_quantity ?? 0)); ?>"></div>
<div class="col-md-3"><label class="form-label">Pack Size</label><input class="form-control" name="units" value="<?php echo e(old('units',$product->units)); ?>" placeholder="e.g. 1 Pc"></div>
<div class="col-md-3"><label class="form-label">Cost Price</label><input class="form-control" type="number" step="0.01" min="0" name="original_price" value="<?php echo e(old('original_price',$product->original_price ?? 0)); ?>"></div>
<div class="col-md-3"><label class="form-label">Selling Price</label><input class="form-control" type="number" step="0.01" min="0" name="selling_price" value="<?php echo e(old('selling_price',$product->selling_price ?? 0)); ?>"></div>
<div class="col-md-6"><label class="form-label">Image</label><input class="form-control" type="file" name="image"></div>
<div class="col-md-3"><label class="form-label">Status</label><select class="form-select" name="status"><option value="Active" <?php if(old('status',$product->status ?? 'Active')==='Active'): echo 'selected'; endif; ?>>Active</option><option value="Inactive" <?php if(old('status',$product->status)==='Inactive'): echo 'selected'; endif; ?>>Inactive</option></select></div>
<div class="col-12"><label class="form-label">Description</label><textarea class="form-control" rows="4" name="description"><?php echo e(old('description',$product->description)); ?></textarea></div>
</div></div></div>
<div class="col-lg-4"><div class="card card-body"><h5>Preview</h5><?php if($product->image): ?><img src="<?php echo e(asset('storage/'.$product->image)); ?>" style="width:100%;max-height:240px;object-fit:cover;border-radius:18px;margin-bottom:12px"><?php endif; ?><div class="summary-box"><div style="font-weight:800"><?php echo e(old('product_name',$product->product_name ?: 'Product name')); ?></div><div style="font-size:13px;color:#667085">Code: <?php echo e(old('product_code',$product->product_code ?: 'Auto/Manual')); ?></div><div style="font-size:13px;color:#667085">Barcode: <?php echo e(old('barcode',$product->barcode ?: 'Will use product code if empty')); ?></div><hr><div>Keep master names clean so reporting stays accurate.</div></div><div class="mt-3 d-grid gap-2"><button class="btn btn-primary"><?php echo e($product->exists ? 'Update Product' : 'Save Product'); ?></button><a href="<?php echo e(route('admin.products.index')); ?>" class="btn btn-outline-primary">Cancel</a></div></div></div>
</div></form>
<script>
function syncSelect(selectId, hiddenId){const el=document.getElementById(selectId);const hidden=document.getElementById(hiddenId);if(!el||!hidden)return;const apply=()=>{hidden.value=el.options[el.selectedIndex]?.dataset?.name||hidden.value||''};el.addEventListener('change',apply);apply();}
['category','brand','supplier','size','color','unit'].forEach(k=>syncSelect(k+'_id',k+'_name'));
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH J:\xampp\htdocs\pos\resources\views/admin/products/form.blade.php ENDPATH**/ ?>