<?php echo $__env->make('admin.layouts.header', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
<?php echo $__env->make('admin.layouts.sidebar', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
        <!-- ============================================================== -->
        <!-- Start right Content here -->
        <!-- ============================================================== -->
        <div class="main-content">

            <div class="page-content">
                <div class="container-fluid">

                    <!-- start page title -->
                    <div class="row">
                        <div class="col-12">
                            <div class="page-title-box d-sm-flex align-items-center justify-content-between bg-galaxy-transparent">
                                <h4 class="mb-sm-0">Add Products</h4>

                                <div class="page-title-right">
                                    <ol class="breadcrumb m-0">
                                        <li class="breadcrumb-item"><a href="javascript: void(0);">Forms</a></li>
                                        <li class="breadcrumb-item active">Add Products</li>
                                    </ol>
                                </div>

                            </div>
                        </div>
                    </div>
                    <!-- end page title -->

                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1">Input Example</h4>
                                    
                                </div><!-- end card header -->
                                <form action="<?php echo e(route('product.update', $product->id)); ?>" method="post" enctype="multipart/form-data">
                                <?php echo csrf_field(); ?>
                                <div class="card-body">
                                    <div class="live-preview">
                                        <div class="row gy-4">
                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="categorySelect" class="form-label">Category</label>
                                                    <select name="category_id" class="form-select" id="categorySelect">
                                                        <option value="">Select Category</option>
                                                        <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <option value="<?php echo e($category->id); ?>" <?php echo e(old('category_id', $product->category_id ?? '') == $category->id ? 'selected' : ''); ?>><?php echo e($category->name); ?></option>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </select>
                                                    <?php if($errors->has('category_id')): ?>
                                                    <p class="text-danger"><?php echo e($errors->first('category_id')); ?></p>
                                                    <?php endif; ?>    
                                                </div>
                                            </div>
                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="subCategorySelect" class="form-label">Sub Category</label>
                                                    <select name="sub_category_id" class="form-select" id="subCategorySelect">
                                                        <option value="">Select Sub Category</option>
                                                        <?php $__currentLoopData = $subcategories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subcategory): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <option value="<?php echo e($subcategory->id); ?>" <?php echo e(old('sub_category_id', $product->sub_category_id ?? '') == $subcategory->id ? 'selected' : ''); ?>>
                                                                <?php echo e($subcategory->name); ?>

                                                            </option>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    
                                                    </select>   
                                                </div>
                                            </div>
                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="childCategorySelect" class="form-label">Child Category</label>
                                                    <select name="child_category_id" class="form-select" id="childCategorySelect">
                                                        <option value="">Select Child Category</option>
                                                        <?php $__currentLoopData = $childcategories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $childcategory): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <option value="<?php echo e($childcategory->id); ?>" <?php echo e(old('child_category_id', $product->child_category_id ?? '') == $childcategory->id ? 'selected' : ''); ?>>
                                                                <?php echo e($childcategory->name); ?>

                                                            </option>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>     
                                                    </select>   
                                                </div>
                                            </div>
                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="brandSelect" class="form-label">Brands</label>
                                                    <select name="brand_id" class="form-select" id="brandSelect">
                                                        <option value="">Select Brand</option>
                                                        <?php $__currentLoopData = $brands; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $brand): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <option value="<?php echo e($brand->id); ?>" <?php echo e(old('brand_id', $product->brand_id ?? '') == $brand->id ? 'selected' : ''); ?>><?php echo e($brand->name); ?></option>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </select>
                                                    <?php if($errors->has('brand_id')): ?>
                                                    <p class="text-danger"><?php echo e($errors->first('brand_id')); ?></p>
                                                    <?php endif; ?>   
                                                </div>
                                            </div>
                                            <!--end col-->
                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="name" class="form-label">Name</label>
                                                    <input type="text" name="name" class="form-control" id="name" placeholder="Enter Name" value="<?php echo e($product->name); ?>">
                                                    <?php if($errors->has('name')): ?>
                                                    <p class="text-danger"><?php echo e($errors->first('name')); ?></p>
                                                    <?php endif; ?> 
                                                </div>
                                            </div>
                                            <!--end col-->
                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="mrp" class="form-label">MRP</label>
                                                    <input type="number" name="mrp" class="form-control" id="placeholderInput" placeholder="Enter MRP" value="<?php echo e($product->mrp); ?>">
                                                    <?php if($errors->has('mrp')): ?>
                                                    <p class="text-danger"><?php echo e($errors->first('mrp')); ?></p>
                                                    <?php endif; ?> 
                                                </div>
                                            </div>
                                            <!--end col-->
                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="discount" class="form-label">Discount</label>
                                                    <input type="number" name="discount" class="form-control" step="0.01" id="discount" placeholder="Enter Discount" value="<?php echo e(rtrim(rtrim(number_format($product->discount, 2, '.', ''), '0'), '.')); ?>">
                                                </div>
                                            </div>
                                            <!--end col-->
                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="selling_price" class="form-label">Selling Price</label>
                                                    <input type="number" name="selling_price" class="form-control" step="0.01" id="selling_price" placeholder="Enter Selling Price" value="<?php echo e(rtrim(rtrim(number_format($product->selling_price, 2, '.', ''), '0'), '.')); ?>">
    
                                                </div>
                                            </div>
                                            <!--end col-->
                                    
                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="size" class="form-label">Size</label>
                                                    <input type="text" name="size" class="form-control" id="size" placeholder="Enter Size" value="<?php echo e($product->size); ?>">
                                                    <?php if($errors->has('size')): ?>
                                                    <p class="text-danger"><?php echo e($errors->first('size')); ?></p>
                                                    <?php endif; ?> 
                                                </div>
                                            </div>

                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="color" class="form-label">Color</label>
                                                    <input type="text" name="color" class="form-control" id="color" placeholder="Enter Color" value="<?php echo e($product->color); ?>">
                                                    <?php if($errors->has('color')): ?>
                                                    <p class="text-danger"><?php echo e($errors->first('color')); ?></p>
                                                    <?php endif; ?> 
                                                </div>
                                            </div>

                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="sku" class="form-label">SKU ID</label>
                                                    <input type="text" name="sku" class="form-control" id="sku" placeholder="Enter SKU ID" value="<?php echo e($product->sku); ?>">
                                                </div>
                                            </div>

                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="hsn_code" class="form-label">HSN Code</label>
                                                    <input type="number" name="hsn_code" class="form-control" id="hsn_code" placeholder="Enter HSN Code" value="<?php echo e($product->hsn_code); ?>">
                                                </div>
                                            </div>

                                            <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="stock" class="form-label">Stock</label>
                                                    <input type="number" name="stock" class="form-control" id="stock" placeholder="Enter Stock" value="<?php echo e($product->stock); ?>">
                                                    
                                                </div>
                                            </div>

                                            <!-- <input type="hidden" name="product_variant_type_id" id="selected_variant_type_id" value="<?php echo e(old('product_variant_type_id', $product->product_variant_type_id)); ?>">
                                            <div class="dropdown col-xxl-3 col-md-6" style = "margin-top: 50px">
                                                <button class="btn btn btn-light text-dark w-100 dropdown-toggle" type="button" id="variantDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                                                    Select Variant Type
                                                </button>
                                                <ul class="dropdown-menu" aria-labelledby="variantDropdown" id="variant_type_menu">
                                                    <?php $__currentLoopData = $variantTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $variant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <li>
                                                            <a class="dropdown-item variant-option" href="#" data-id="<?php echo e($variant->id); ?>" data-input-type="<?php echo e($variant->input_type); ?>">
                                                                <?php echo e($variant->variation_type); ?>

                                                            </a>
                                                        </li>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    <li><hr class="dropdown-divider"></li>
                                                    <li class="px-3">
                                                        <input type="text" id="variant_value_input" class="form-control mb-2" placeholder="variant value">
                                                        <button class="btn btn-primary w-100" id="save_variant_value">Save Variant Value</button>
                                                    </li>
                                                </ul>
                                            </div> -->

                                        <div class="row gy-4">
                                            <div class="col-xxl-6 col-md-6">
                                                <div>
                                                    <label for="product_highlights" class="form-label">Product Highlights</label>
                                                    <textarea name="product_highlights" class="form-control ck-editor" id="product_highlights" placeholder="Product Highlights" ><?php echo e($product->product_highlights); ?></textarea>
                                                </div>
                                            </div>

                                            <div class="col-xxl-6 col-md-6">
                                                <div>
                                                    <label for="product_description" class="form-label">Product Description</label>
                                                    <textarea name="product_description" class="form-control ck-editor" id="product_description" placeholder="Product Description" ><?php echo e($product->product_description); ?></textarea>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- </div> -->

                                            <div class="row gy-4">
                                                
                                                <h4 style="margin-top: 46px">Dimensions</h4>
                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="iconInput" class="form-label">Length</label>
                                                        <div class="form-icon">
                                                            <input type="number" step="0.01" name="length" class="form-control form-control-icon" id="iconInput" placeholder="Length (cm)" value="<?php echo e($product->length); ?>">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="iconInput" class="form-label">Breadth</label>
                                                        <div class="form-icon">
                                                            <input type="number" step="0.01" name="breadth" class="form-control form-control-icon" id="breadth" placeholder="Breadth (cm)" value="<?php echo e($product->breadth); ?>"> 
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="iconInput" class="form-label">Height</label>
                                                        <div class="form-icon">
                                                            <input type="number" step="0.01" name="height" class="form-control form-control-icon" id="height" placeholder="Height (cm)" value="<?php echo e($product->height); ?>">
                                                            
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="iconInput" class="form-label">Weight</label>
                                                        <div class="form-icon">
                                                            <input type="number" step="0.01" name="weight" class="form-control form-control-icon" id="weight" placeholder="Weight (g)" value="<?php echo e($product->weight); ?>">
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <hr>
                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="country_of_origin" class="form-label">Country Of Origin</label>
                                                        <select name="country_of_origin" class="form-select" id="country_of_origin">
                                                            <option value="">Select Country Of Origin</option>
                                                            <option value="India" <?php echo e(old('country_of_origin', $product->country_of_origin) == 'India' ? 'selected' : ''); ?>>India</option>
                                                            <option value="USA" <?php echo e(old('country_of_origin', $product->country_of_origin) == 'USA' ? 'selected' : ''); ?>>USA</option>
                                                               
                                                        </select>  
                                                        <?php if($errors->has('country_of_origin')): ?>
                                                        <p class="text-danger"><?php echo e($errors->first('country_of_origin')); ?></p>
                                                        <?php endif; ?>  
                                                    </div>
                                                </div>

                                                
                                                <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="manufacturer_details" class="form-label">Manufacturer's Details</label>
                                                    <textarea name="manufacturer_details" class="form-control" id="manufacturer_details" placeholder="Manufacturer's Details"><?php echo e($product->manufacturer_details); ?></textarea>
                                                </div>
                                                </div>

                                                <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="importer_details" class="form-label">Importer's Details</label>
                                                    <textarea name="importer_details" class="form-control" id="importer_details" placeholder="Importer's Details"><?php echo e($product->importer_details); ?></textarea>
                                                </div>
                                                </div>

                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="packer_details" class="form-label">Packer's Details</label>
                                                        <textarea name="packer_details" class="form-control" id="packer_details" placeholder="Packer's Details"><?php echo e($product->packer_details); ?></textarea>
                                                    </div>
                                                </div>



                                                <hr>

                                                <h4>SEO Terms</h4>
                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="meta_title" class="form-label">Meta Title</label>
                                                        <div class="form-icon">
                                                            <input type="text" name="meta_title" class="form-control form-control-icon" id="weight" placeholder="Meta Title" value="<?php echo e($product->meta_title); ?>">
                                                            <?php if($errors->has('meta_title')): ?>
                                                            <p class="text-danger"><?php echo e($errors->first('meta_title')); ?></p>
                                                            <?php endif; ?> 
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="meta_description" class="form-label">Meta Description</label>
                                                        <textarea name="meta_description" class="form-control" id="meta_description" placeholder="Meta Description"><?php echo e($product->meta_description); ?></textarea>
                                                    </div>
                                                </div>

                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="meta_keywords" class="form-label">Meta Keywords</label>
                                                        <textarea name="meta_keywords" class="form-control" id="meta_keywords" placeholder="Meta Keywords"><?php echo e($product->meta_keywords); ?></textarea>
                                                    </div>
                                                </div>

                                                <hr>
                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="meta_title" class="form-label">Product Tags</label>
                                                        <div class="form-icon">
                                                            <input type="text" name="tags" class="form-control form-control-icon" id="weight" placeholder="Product Tags (comma-separated)" value="<?php echo e($product->tags); ?>">
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="note" class="form-label">Note</label>
                                                        <textarea name="note" class="form-control" id="note" placeholder="Note" value="<?php echo e($product->note); ?>"></textarea>
                                                    </div>
                                                </div>

                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="statusSelect" class="form-label">Status</label>
                                                        <select name="status" class="form-select" id="statusSelect">
                                                            <option value="">Select Status</option>
                                                            <option value="active" <?php echo e(old('status', $product->status) == 'active' ? 'selected' : ''); ?>>Active</option>
                                                            <option value="inactive" <?php echo e(old('status', $product->status) == 'inactive' ? 'selected' : ''); ?>>Inactive</option>
                                                        </select>
                                                        <?php if($errors->has('status')): ?>
                                                        <p class="text-danger"><?php echo e($errors->first('status')); ?></p>
                                                        <?php endif; ?>    
                                                    </div>
                                                </div>

                                                <div class="col-xxl-3 col-md-6">
                                                <div>
                                                    <label for="featured_image" class="form-label">Featured Image</label>
                                                    <input type="file" name="featured_image" class="form-control" id="featured_image" value="<?php echo e(old('featured_image')); ?>">
                                                    <?php if($errors->has('featured_image')): ?>
                                                    <p class="text-danger"><?php echo e($errors->first('featured_image')); ?></p>
                                                    <?php endif; ?>
                                                </div>
                                                <?php if($product->featured_image): ?>
                                                <div class="mt-2">
                                                    <img src="<?php echo e(asset('uploads/products/' . $product->featured_image)); ?>" 
                                                        alt="Current Image" width="50">
                                                </div>
                                                <?php endif; ?>
                                                </div>

                                                <div class="col-xxl-3 col-md-6">
                                                    <div>
                                                        <label for="bulk_images" class="form-label">Bulk Images</label>
                                                        <input type="file" name="bulk_images[]" class="form-control" id="bulk_images" multiple>
                                                        <?php if($errors->has('bulk_images')): ?>
                                                        <p class="text-danger"><?php echo e($errors->first('bulk_images')); ?></p>
                                                        <?php endif; ?>
                                                    </div>

                                                    <?php if(!empty($product->bulk_images) && is_array(json_decode($product->bulk_images, true))): ?>
                                                        <div class="mt-2 d-flex flex-wrap gap-2">
                                                            <?php $__currentLoopData = json_decode($product->bulk_images); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $image): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <div style="position: relative; width: 50px;">
                                                                    <img src="<?php echo e(asset('uploads/products/' . $image)); ?>" alt="Bulk Image" width="50">
                                                                </div>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                        </div>
                                                    <?php endif; ?>
                                                </div>
                                                
                                                <div style="text-align: center;">
                                                    <button type="submit" class="btn btn-primary">Submit</button>
                                                </div>
                                            </div>                                            
                            
                                        </div>
                                        <!--end row-->
                                    </div>
                                    
                                </div>
                                </form>
                            </div>
                        </div>
                        <!--end col-->
                    </div>
                    <!--end row-->
                    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
                    <script>
                        const BASE_URL = "<?php echo e(env('APP_URL')); ?>";
                    $(document).ready(function () {
                        $('select[name="category_id"]').on('change', function () {
                            let categoryId = $(this).val();
                            if (categoryId) {
                                $.get(`${BASE_URL}/get-subcategories/${categoryId}`, function (data) {
                                    $('select[name="sub_category_id"]').empty().append('<option value="">-- Select --</option>');
                                    $.each(data, function (id, name) {
                                        $('select[name="sub_category_id"]').append(`<option value="${id}">${name}</option>`);
                                    });
                                    $('select[name="child_category_id"]').empty().append('<option value="">-- Select --</option>');
                                });
                            }
                        });

                        $('select[name="sub_category_id"]').on('change', function () {
                            let subcatId = $(this).val();
                            if (subcatId) {
                                $.get(`${BASE_URL}/get-childcategories/${subcatId}`, function (data) {
                                    $('select[name="child_category_id"]').empty().append('<option value="">-- Select --</option>');
                                    $.each(data, function (id, name) {
                                        $('select[name="child_category_id"]').append(`<option value="${id}">${name}</option>`);
                                    });
                                });
                            }
                        });
                    });
                    </script>

                    <script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/ckeditor.js"></script>
                    <script>
                        document.querySelectorAll('.ck-editor').forEach(editorElement => {
                            ClassicEditor
                                .create(editorElement)
                                .catch(error => {
                                    console.error(error);
                                });
                        });
                    </script>

<!------- for amount calculation  -->

<script>
    document.addEventListener('DOMContentLoaded', function () {
        const mrpInput = document.querySelector('input[name="mrp"]');
        const discountInput = document.querySelector('input[name="discount"]');
        const sellingPriceInput = document.querySelector('input[name="selling_price"]');

        function calculateSellingPrice() {
            const mrp = parseFloat(mrpInput.value);
            const discount = parseFloat(discountInput.value);
            if (!isNaN(mrp) && !isNaN(discount)) {
                const sellingPrice = mrp - (mrp * discount / 100);
                sellingPriceInput.value = sellingPrice.toFixed(2);
            }
        }

        function calculateDiscount() {
            const mrp = parseFloat(mrpInput.value);
            const sellingPrice = parseFloat(sellingPriceInput.value);
            if (!isNaN(mrp) && !isNaN(sellingPrice) && mrp !== 0) {
                const discount = ((mrp - sellingPrice) / mrp) * 100;
                discountInput.value = discount.toFixed(2);
            }
        }

        // Event listeners
        mrpInput.addEventListener('input', function () {
            if (discountInput.value) {
                calculateSellingPrice();
            } else if (sellingPriceInput.value) {
                calculateDiscount();
            }
        });

        discountInput.addEventListener('input', function () {
            if (mrpInput.value) {
                calculateSellingPrice();
            }
        });

        sellingPriceInput.addEventListener('input', function () {
            if (mrpInput.value) {
                calculateDiscount();
            }
        });
    });
</script>

<?php echo $__env->make('admin.layouts.footer', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>                   <?php /**PATH /home/hubto/public_html/griffin/resources/views/admin/products/product-edit.blade.php ENDPATH**/ ?>