<?php $__env->startSection('content'); ?>
    <style>
        .description-ellipsis {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

    </style>
    <div class="mouse-cursor cursor-outer"></div>
    <div class="mouse-cursor cursor-inner"></div>


    <section class="innerBanner">
        <img src="<?php echo e(optional($product->getMedia('product_banner_image')->first())->getUrl()); ?>" class="w-100" alt="img">
        <div class="container">
            <h2><?php echo e($data->banner_title ?? 'APPEAREL'); ?></h2>
        </div>
    </section>

    <section class="productPage">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-3">
                    <div class="shopSidebar">

                        <?php if(isset($get_single_cate->name)): ?>

                            <h4>
                                <a href="<?php echo e(route('front.product', ['category_id' => $get_single_cate->id])); ?>"
                                   class="category-link"
                                   data-category-id="<?php echo e($get_single_cate->id); ?>"><?php echo e($get_single_cate->name); ?></a>
                            </h4>

                            <ul>
                                <?php $__currentLoopData = $get_single_cate->subcategories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subCategory): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <li><a href="<?php echo e(route('front.product', ['category_id' => $subCategory->id])); ?>"
                                           class="category-link"
                                           data-category-id="<?php echo e($subCategory->id); ?>"><?php echo e($subCategory->name); ?></a></li>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </ul>
                        <?php else: ?>
                            <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mainCategory): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <h4>
                                    <a href="<?php echo e(route('front.product', ['category_id' => $mainCategory->id])); ?>"
                                       class="category-link"
                                       data-category-id="<?php echo e($mainCategory->id); ?>"><?php echo e($mainCategory->name); ?></a>
                                </h4>
                                <ul>
                                    <?php $__currentLoopData = $mainCategory->subcategories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subCategory): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <li><a href="<?php echo e(route('front.product', ['category_id' => $subCategory->id])); ?>"
                                               class="category-link"
                                               data-category-id="<?php echo e($subCategory->id); ?>"><?php echo e($subCategory->name); ?></a></li>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </ul>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>


                    </div>
                </div>

                <div class="col-md-9" id="filtered-products-container">
                    <div class="row">
                        <?php if($products->isEmpty()): ?>
                            <div class="col-md-4">
                                <p>No products available.</p>
                            </div>
                        <?php else: ?>
                            <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="col-md-4">
                                    <div class="proBox">
                                        <span>-<?php echo e($product->discount_percent); ?>%</span>
                                        <ul class="iconShow">
                                            <li><a href="<?php echo e(route('front.product')); ?>"><i class="far fa-search"></i></a>
                                            </li>
                                            <li><a href="#" class="img-fluid compareProduct" data-product-id="<?php echo e($product->id); ?>"><i class="fa fa-random" aria-hidden="true"></i></a></li>

                                            <li><a href="<?php echo e(route('wishlist.show')); ?>" class="addToWishlist" data-product-id="<?php echo e($product->id); ?>"><i class="fal fa-heart"></i></a></li>
                                        </ul>
                                        <a href="<?php echo e(route('front.shop.product' , ['slug' => $product->slug])); ?>">
                                            <div class="proImg">
                                                <figure>
                                                    <img
                                                        src="<?php echo e($product->productImage() ?? asset('front/images/default-product-image.jpg')); ?>"
                                                        class="img-fluid" alt="img">
                                                    <img
                                                        src="<?php echo e($product->productImage() ?? asset('front/images/default-product-image.jpg')); ?>"
                                                        class="img-fluid" alt="img">
                                                </figure>
                                            </div>
                                            <div class="proContent">
                                                <h2><?php echo e($product->name ?? 'Product Name'); ?></h2>
                                                <p class="description-ellipsis"><?php echo e($product->description ?? ''); ?></p>
                                                <h6>$<?php echo e($product->price ?? '0.00'); ?></h6>
                                                <form method="post" action="<?php echo e(route('chat.startConversation')); ?>">
                                                    <?php echo csrf_field(); ?>
                                                    <input type="hidden" name="product_id" value="<?php echo e($product->id); ?>">
                                                    <input type="hidden" name="user_id"
                                                           value="<?php echo e(auth()->user()->id ?? ''); ?>">
                                                    <input type="hidden" name="quotation" value="<?php echo e('000'); ?>">
                                                    <button type="submit" class="offerBtn">Make Offer</button>
                                                </form>
                                            </div>
                                        </a>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </section>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
    <script>
        $(document).ready(function() {
            var isAddingToWishlist = false;

            $('body').on('click', '.addToWishlist', function(e) {
                e.preventDefault();

                var productId = $(this).data('product-id');

                if (!isAddingToWishlist) {
                    // Single click
                    $.ajax({
                        url: "<?php echo e(route('wishlist.add')); ?>",
                        type: "POST",
                        data: {
                            product_id: productId,
                            _token: "<?php echo e(csrf_token()); ?>",
                        },
                        beforeSend: function() {
                            isAddingToWishlist = true;
                        },
                        success: function(response) {
                            alert(response.success); // Show success message
                        },
                        error: function(xhr, status, error) {
                            if (xhr.status === 401) {
                                alert('You must be logged in to add products to the wishlist');
                            } else if (xhr.status === 400) {
                                alert('Product is already in the wishlist');
                            } else {
                                console.error(xhr.responseText);
                                alert('Failed to add product to wishlist');
                            }
                        },
                        complete: function() {
                            isAddingToWishlist = false;
                        }
                    });
                }
            });

            // Double-click event handler
            $('body').on('dblclick', '.addToWishlist', function(e) {
                e.preventDefault();

                var wishlistUrl = "<?php echo e(route('wishlist.show')); ?>";
                window.location.href = wishlistUrl; // Redirect to wishlist page
            });
        });

    </script>

    <script>
        $(document).ready(function() {
            var isAddingToCompare = false;

            $('body').on('click', '.compareProduct', function(e) {
                e.preventDefault();

                var productId = $(this).data('product-id');
                var compareUrl = "<?php echo e(route('compare.show')); ?>";

                if (!isAddingToCompare) {
                    $.ajax({
                        url: "<?php echo e(route('compare.add')); ?>",
                        type: "POST",
                        data: {
                            product_id: productId,
                            _token: "<?php echo e(csrf_token()); ?>",
                        },
                        beforeSend: function() {
                            isAddingToCompare = true;
                        },
                        success: function(response) {
                            alert(response.success);
                            $('.compareProduct[data-product-id="' + productId + '"]').html('<i class="fas fa-check"></i>');
                        },
                        error: function(xhr, status, error) {
                            if (xhr.status === 400) {
                                alert('Product is already in the comparison');
                            } else if (xhr.status === 500) {
                                alert('Failed to add product to compare');
                            } else {
                                console.error(xhr.responseText);
                                alert('something went wrong');
                            }
                        },
                        complete: function() {
                            isAddingToCompare = false;
                        }
                    });
                }
            });

            $('body').on('dblclick', '.compareProduct', function(e) {
                e.preventDefault();

                var compareUrl = "<?php echo e(route('compare.show')); ?>";
                window.location.href = compareUrl; // Redirect to compare page
            });
        });
    </script>

<?php $__env->stopSection(); ?>



<?php echo $__env->make('front.layout.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/servicedemoweb/public_html/premiere-deals/resources/views/front/pages/product.blade.php ENDPATH**/ ?>