<?php $__env->startSection('title'); ?>
    Add Product
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <style>
        .active {
            background-color: #007BFF !important;
            color: white !important;
        }
    </style>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-12">

                        <div class="card card-box-shadow mt-5">

                            <div class="card-header">
                                <h3 class="card-title">Add Product</h3>
                                <a href="<?php echo e(route('admin.product.index')); ?>">
                                    <button id="submit_btn" class="btn btn-primary custom_btn_sm_back custom_btn btn-sm float-right">
                                        <i class="fas fa-arrow-circle-left"></i>
                                        Back
                                    </button>
                                </a>
                            </div>

                            <!-- /.card-header -->
                            <div class="card-body">
                                <form action="<?php echo e(route('admin.product.store')); ?>" method="POST" enctype="multipart/form-data">
                                    <?php echo csrf_field(); ?>
                                    <div class="row">

                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label for="Name">Product Name:</label>
                                                <input type="text" class="form-control form__field" name="product_name" placeholder="Enter Product Name" required>
                                                <small class="text-danger">
                                                    <?php $__errorArgs = ['product_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo e($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                </small>
                                            </div>
                                        </div>

                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label for="category">Select Category:</label>
                                                <select id="category" class="form-control form__field" name="category_name" required>
                                                    <option value="" selected disabled>Select Category</option>
                                                    <?php $__empty_1 = true; $__currentLoopData = $get_categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                                        <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                                        <option>Category Not Found</option>
                                                    <?php endif; ?>
                                                </select>
                                                <small class="text-danger">
                                                    <?php $__errorArgs = ['category_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo e($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                </small>
                                            </div>
                                        </div>

                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label for="Name">Product Price:</label>
                                                <input type="number" class="form-control form__field" name="price" placeholder="Enter Price" required>
                                                <small class="text-danger">
                                                    <?php $__errorArgs = ['price'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo e($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                </small>
                                            </div>
                                        </div>

                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label for="Name">Product Discount Price:</label>
                                                <input type="number" class="form-control form__field" name="discount" placeholder="Enter Discount Price" oninput="this.value = this.value.replace(/[^0-9]/g, '')">
                                                <small class="text-danger">
                                                    <?php $__errorArgs = ['discount'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo e($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                </small>
                                            </div>
                                        </div>

                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label for="Name">Product Stock:</label>
                                                <input type="number" class="form-control form__field" name="stock" placeholder="Enter Product Stock" oninput="this.value = this.value.replace(/[^0-9]/g, '')">
                                                <small class="text-danger">
                                                    <?php $__errorArgs = ['stock'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo e($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                </small>
                                            </div>
                                        </div>

                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label>Product Best Sale:</label>
                                                <input type="checkbox" data-toggle="toggle" data-on="Sale" data-off="Off" data-onstyle="success" data-offstyle="danger" name="best_sale">
                                                <label>OUR EXCLUSIVES:</label>
                                                <input type="checkbox" data-toggle="toggle" data-on="Exclusive" data-off="Off" data-onstyle="success" data-offstyle="danger" name="arrival">
                                                <label>SUMMER ESSENTIALS:</label>
                                                <input type="checkbox" data-toggle="toggle" data-on="Essential" data-off="Off" data-onstyle="success" data-offstyle="danger" name="essential">
                                            </div>
                                        </div>

                                        <div class="col-md-12 mt-4">
                                            <div class="form-group">
                                                <label for="mainProductImageInput">Main Product Image:</label>
                                                <input type="file" class="form-control form__field visually-hidden" name="product_image" id="mainProductImageInput" accept="image/*" required>
                                                <label for="mainProductImageInput" class="file-input-label form__field form-control">
                                                    <i class="fas fa-camera"></i> Choose file
                                                </label>
                                                <small class='text-danger'>
                                                    <?php $__errorArgs = ['product_image'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo e($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                </small>
                                            </div>
                                            <img id="mainProductImagePreview" src="<?php echo e(asset('upload/No-Image.png')); ?>" alt="Profile Preview" style="width: 250px; height: 200px; margin-top: 10px;">
                                        </div>

                                        <div class="col-md-12 mt-5">
                                            <div class="form-group pt-4">
                                                <div class="card card-box-shadow">
                                                    <h5 class="card-header bg-dark text-white">
                                                        Image Gallery
                                                        <button type="button" class="btn btn-sm btn-outline-light float-right addImage">
                                                            <i class="la la-fw la-plus"></i>Add More Image
                                                        </button>
                                                    </h5>
                                                    <div class="card-body">
                                                        <div class="row addedField ml-5">
                                                            <div class="card shadow" style="width:300px;margin-right:20px;margin-bottom:15px;">
                                                                <div class="image-upload">
                                                                    <div class="avatar-preview">
                                                                        <img src="<?php echo e(asset('upload/No-Image.png')); ?>" class=" card-img-top profilePicPreview" id="productFirstGalleryImagePreview" style="height:200px;">
                                                                    </div>
                                                                    <div class="card-body">
                                                                        <div class="avatar-edit my-2">
                                                                            <label for="productFirstGalleryImageInput" class="btn btn-success btn-lg w-100"><?php echo app('translator')->get('Upload Image'); ?></label>
                                                                        </div>
                                                                        <input type="file" class="profilePicUpload" name="product_gallery_images[]" id="productFirstGalleryImageInput" accept=".png, .jpg, .jpeg, .webp" style="display:none;">
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-md-12 mt-5">
                                            <div class="form-group pt-4">
                                                <div class="card card-box-shadow">
                                                    <h5 class="card-header bg-dark text-white">
                                                        Add Product Variation
                                                        <button type="button" class="btn btn-sm btn-outline-light float-right addProductVariation">
                                                            <i class="la la-fw la-plus"></i>Add Product Variation
                                                        </button>
                                                    </h5>
                                                    <div class="card-body addProductVariationField">
                                                        <div class="row form-section">
                                                            <div class="col-md-3 mt-4">
                                                                <div class="form-group">
                                                                    <label>Select Size:</label>
                                                                    <select class="form-control form__field" name="size_id[]">
                                                                        <option value="" selected disabled>Select Size</option>
                                                                        <?php $__empty_1 = true; $__currentLoopData = $get_sizes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $size): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                                                            <option value="<?php echo e($size->id); ?>"><?php echo e($size->size_name); ?></option>
                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                                                            <option>Size Not Found</option>
                                                                        <?php endif; ?>
                                                                    </select>
                                                                </div>
                                                            </div>

                                                            <div class="col-md-3 mt-4">
                                                                <div class="form-group">
                                                                    <label for="color_name[]">Color Name:</label>
                                                                    <input type="text" name="color_name[]" class="form-control form__field" placeholder="Enter Color Name">
                                                                </div>
                                                            </div>

                                                            <div class="col-md-3 mt-4">
                                                                <div class="form-group">
                                                                    <label for="color_code[]">Color Code:</label>
                                                                    <input type="text" name="color_code[]" class="form-control form__field" placeholder="Enter Color Code">
                                                                </div>
                                                            </div>

                                                            <div class="col-md-3 mt-4">
                                                                <div class="form-group">
                                                                    <label for="size_price[]">Size Price:</label>
                                                                    <input type="text" name="size_price[]" class="form-control form__field" placeholder="Enter Size Price">
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-md-12 mt-4">
                                            <label for="">Short Description</label>
                                            <textarea name="description" rows="4" placeholder="Description" class="form-control form__field" id="summernote1"></textarea>
                                            <small class="text-danger">
                                                <?php $__errorArgs = ['description'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo e($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                            </small>
                                        </div>

                                        <div class="mx-auto mt-5">
                                            <div class="form-group">
                                                <button id="submit_btn" class="btn btn-primary custom_btn">
                                                    <i class="fa-solid fa-cloud-arrow-up"></i> Submit
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>

                            <!-- /.card-body -->
                        </div>
                        <!-- /.card -->
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </section>
        <!-- /.content -->
    </div>

    <!-- /.content-wrapper -->
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
    <script>
        $('#summernote1').summernote({
            placeholder: 'Hello Admin',
            tabsize: 2,
            height: 100
        });
    </script>
    <script>
        function showImagePreview(input, previewId) {
            const preview = document.getElementById(previewId);

            if (input.files && input.files[0]) {
                const reader = new FileReader();

                reader.onload = function (e) {
                    preview.src = e.target.result;
                    preview.style.display = 'block';
                };

                reader.readAsDataURL(input.files[0]);
            }
        }

        const mainProductImageInput = document.getElementById('mainProductImageInput');
        mainProductImageInput.addEventListener('change', function () {
            showImagePreview(this, 'mainProductImagePreview');
        });

        const productFirstGalleryImageInput = document.getElementById('productFirstGalleryImageInput');
        productFirstGalleryImageInput.addEventListener('change', function () {
            showImagePreview(this, 'productFirstGalleryImagePreview');
        });

        $('.addImage').on('click', function () {
            var randomId = Math.floor(Math.random() * 10000);


            var html = `
              <div class ="image-data">
         <div class="card shadow" style="width:300px;margin-right:20px;margin-bottom:15px;">
            <div class="image-upload">
                <div class="avatar-preview">
                    <img src="<?php echo e(asset('upload/No-Image.png')); ?>" class=" card-img-top profilePicPreview" id="profile-pic-show-${randomId}" style="height:200px;">
                </div>
                <div class="card-body">
                    <div class="avatar-edit my-2">
                        <label for="file-uploads-${randomId}" class=" btn btn-success btn-lg w-100"><?php echo app('translator')->get('Upload Image'); ?></label>
                        <button class="btn btn-danger btn-lg removeBtn w-100" type="button">
                            <?php echo app('translator')->get('Remove Image'); ?>
            </button>
        </div>
        <input type="file" class="profilePicUpload" name="product_gallery_images[]" id="file-uploads-${randomId}" data-id="${randomId}" accept=".png, .jpg, .jpeg, .webp"style="display:none;">

                </div>
            </div>
            </div>
        </div>`;


            $('.addedField').append(html);

            //NEW FILE UPLOAD WORK

            $(`#file-uploads-${randomId}`).on('change', function () {
                var input = this;
                var previewId = `#profile-pic-show-${randomId}`;

                if (input.files && input.files[0]) {
                    var reader = new FileReader();

                    reader.onload = function (e) {
                        $(previewId).attr('src', e.target.result);
                        // Set the data URL in the hidden input for form submission
                        $(`#cropped-image-${randomId}`).val(e.target.result);
                    };

                    reader.readAsDataURL(input.files[0]);
                }
            });

            $(document).on('click', '.removeBtn', function () {
                $(this).closest('div.image-data').remove();
            });

        });


        $('.addProductVariation').on('click', function () {
            var randomId = Math.floor(Math.random() * 10000);

            var newFormSection = `
                <div class="row product-variation-data mb-4 mt-4" id="formSection${randomId}">
                   <div class="col-md-12">
                      <button type='button' class=" custom_btn_sm_back custom_btn btn-sm float-right productVariationRemoveBtn">
                      <i class="fas fa-trash-alt"></i>
                      Remove
                      </button>
                   </div>
                   <div class="col-md-3 mt-4">
                      <div class="form-group">
                         <label>Select Size:</label>
                         <select class="form-control form__field"
                            name="size_id[]">
                            <option value="" selected disabled>Select Size</option>
                            <?php $__empty_1 = true; $__currentLoopData = $get_sizes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $size): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
             <option value="<?php echo e($size->id ?: ''); ?>">
                               <?php echo e($size->size_name ?: ''); ?>

            </option>
                 <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <option>Size Not Found</option>
                <?php endif; ?>
            </select>
                </div>
                </div>
                <div class="col-md-3 mt-4">
                <div class="form-group">
                   <label for="color_name[]">Color Name:</label>
                   <input type="text" name="color_name[]" class="form-control form__field" placeholder="Enter Color Name">
                </div>
                </div>
                <div class="col-md-3 mt-4">
                <div class="form-group">
                   <label for="color_code[]">Color Code:</label>
                   <input type="text" name="color_code[]" class="form-control form__field" placeholder="Enter Color Code">
                </div>
                </div>
                <div class="col-md-3 mt-4">
                <div class="form-group">
                   <label for="size_price[]">Size Price:</label>
                   <input type="text" name="size_price[]" class="form-control form__field" placeholder="Enter Size Price">
                </div>
                </div>
                </div>
                 `;
            $('.addProductVariationField').append(newFormSection);


            $(document).on('click', '.productVariationRemoveBtn', function () {
                $(this).closest('div.product-variation-data').remove();
            });

        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin-layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/vagrant/projects/upsence/resources/views/admin/product/add.blade.php ENDPATH**/ ?>