<?php $__env->startSection('title', 'پیشنهادات شگفت‌انگیز'); ?>

<?php $__env->startSection('styles'); ?>
<link rel="stylesheet" href="<?php echo e(asset('theme/assets/plugin/nouislider/nouislider.min.css')); ?>">
<style>
    .shop-sidebar { position: sticky; top: 20px; }
    .shop-cat-indent-1 { padding-right: 16px; }
    .shop-cat-indent-2 { padding-right: 32px; }
    .shop-cat-indent-3 { padding-right: 48px; }
    .shop-cat-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
    .shop-cat-row .form-check { margin-bottom: 0; }
    .shop-empty { padding: 60px 20px; text-align: center; color: #aaa; }
    .shop-empty i { font-size: 64px; display: block; margin-bottom: 16px; }
    .pagination .page-link { color: var(--main-color-one); }
    .pagination .page-item.active .page-link { background-color: var(--main-color-one); border-color: var(--main-color-one); color: #fff; }
</style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="content">
    <div class="container-fluid">

        <form method="GET" action="<?php echo e(route('amazing')); ?>" id="shopForm">

            <input type="hidden" id="shopPriceMin" name="price_min" value="<?php echo e($priceMin); ?>">
            <input type="hidden" id="shopPriceMax" name="price_max" value="<?php echo e($priceMax > 0 ? $priceMax : $maxPrice); ?>">

            
            <div class="custom-filter d-lg-none d-block">
                <button class="btn btn-filter-float border-0 main-color-two-bg shadow-box px-3 rounded-3 position-fixed"
                    style="z-index:999;bottom:80px;" type="button"
                    data-bs-toggle="offcanvas" data-bs-target="#offcanvasShopFilter"
                    aria-controls="offcanvasShopFilter">
                    <i class="bi bi-funnel font-20 fw-bold text-white"></i>
                    <span class="d-block font-14 text-white">فیلتر</span>
                </button>
                <div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasShopFilter"
                    aria-labelledby="offcanvasShopFilterLabel">
                    <div class="offcanvas-header">
                        <h5 class="offcanvas-title" id="offcanvasShopFilterLabel">فیلتر ها</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
                    </div>
                    <div class="offcanvas-body">
                        <?php echo $__env->make('site.partials.shop-filters', ['prefix' => 'mobile'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    </div>
                </div>
            </div>

            <div class="row gy-3">

                
                <div class="col-lg-3 d-lg-block d-none">
                    <div class="shop-sidebar">
                        <?php echo $__env->make('site.partials.shop-filters', ['prefix' => 'desktop'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    </div>
                </div>

                
                <div class="col-lg-9">

                    
                    <div class="category-sort mb-3">
                        <div class="content-box">
                            <div class="container-fluid">
                                <div class="d-flex align-items-center flex-wrap gap-2">
                                    <div class="me-3">
                                        <h5 class="font-16 mb-1">
                                            <i class="bi bi-stars text-warning me-1"></i>پیشنهادات شگفت‌انگیز
                                        </h5>
                                    </div>
                                    <div class="me-3">
                                        <span class="text-muted font-14">مرتب سازی:</span>
                                    </div>
                                    <div class="d-flex flex-wrap gap-2">
                                        <?php $__currentLoopData = [
                                            'default'        => 'پیشفرض',
                                            'popular'        => 'محبوب‌ترین',
                                            'best_sellers'   => 'پرفروش‌ترین',
                                            'newest'         => 'جدیدترین',
                                            'cheapest'       => 'ارزان‌ترین',
                                            'most_expensive' => 'گران‌ترین',
                                        ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $val => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php
                                            $currentParams = array_merge(request()->except(['sort', 'page']), ['sort' => $val]);
                                            $sortUrl = route('amazing') . '?' . http_build_query($currentParams);
                                        ?>
                                        <a href="<?php echo e($sortUrl); ?>"
                                            class="btn btn-sm rounded-pill <?php echo e($sort === $val ? 'main-color-one-bg text-white border-0' : 'btn-outline-secondary'); ?>">
                                            <?php echo e($label); ?>

                                        </a>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    
                    <div class="category-items">
                        <?php if($products->isEmpty()): ?>
                        <div class="shop-empty">
                            <i class="bi bi-stars"></i>
                            <p class="font-18 mt-2">محصول شگفت‌انگیزی یافت نشد.</p>
                            <a href="<?php echo e(route('amazing')); ?>" class="btn-outline-site">پاک کردن فیلترها</a>
                        </div>
                        <?php else: ?>
                        <div class="row g-3">
                            <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $variant     = $product->defaultVariant() ?: $product->variants->first();
                                $price       = $variant ? (float)$variant->price : 0;
                                $finalPrice  = ($variant && $variant->discount_price) ? (float)$variant->discount_price : $price;
                                $hasDiscount = $variant && $variant->discount_price && $variant->discount_price < $variant->price;
                                $discPct     = ($hasDiscount && $price > 0) ? round((1 - $finalPrice / $price) * 100) : 0;
                                $img1        = $product->featured_image ? asset('uploads/products/' . $product->featured_image) : null;
                                $img2obj     = $product->images->skip(1)->first();
                                $img2Url     = $img2obj ? asset('uploads/products/' . $img2obj->image) : $img1;
                                $inStock     = $product->isInStock();
                            ?>
                            <div class="col-12 col-md-6 col-lg-4">
                                <div class="product-box <?php echo e($inStock ? '' : 'out-of-stock'); ?>">
                                    <div class="product-timer">
                                        <div class="timer-label">
                                            <?php if($hasDiscount && $discPct > 0): ?>
                                            <span><?php echo e($discPct); ?>% تخفیف</span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="product-header-btn">
                                            <a href="javascript:void(0)" class="wish-toggle"
                                                data-product="<?php echo e($product->id); ?>"
                                                data-bs-toggle="tooltip" data-bs-placement="top"
                                                data-bs-title="علاقه‌مندی">
                                                <i class="bi <?php echo e(auth()->check() && auth()->user()->hasWished($product->id) ? 'bi-heart-fill' : 'bi-heart'); ?>"></i>
                                            </a>
                                            <a href="<?php echo e(route('product.show', $product->slug)); ?>"
                                                data-bs-toggle="tooltip" data-bs-placement="top"
                                                data-bs-title="مشاهده محصول">
                                                <i class="bi bi-eye"></i>
                                            </a>
                                        </div>
                                    </div>
                                    <a href="<?php echo e(route('product.show', $product->slug)); ?>">
                                        <div class="product-image">
                                            <?php if($img1): ?>
                                            <img src="<?php echo e($img1); ?>" loading="lazy" alt="<?php echo e($product->title); ?>" class="img-fluid one-image">
                                            <img src="<?php echo e($img2Url ?? $img1); ?>" loading="lazy" alt="<?php echo e($product->title); ?>" class="img-fluid two-image">
                                            <?php else: ?>
                                            <img src="<?php echo e(asset('theme/assets/image/default-product.png')); ?>" loading="lazy" alt="<?php echo e($product->title); ?>" class="img-fluid one-image">
                                            <img src="<?php echo e(asset('theme/assets/image/default-product.png')); ?>" loading="lazy" alt="<?php echo e($product->title); ?>" class="img-fluid two-image">
                                            <?php endif; ?>
                                        </div>
                                    </a>
                                    <div class="product-title">
                                        <div class="title">
                                            <p class="text-overflow-1"><?php echo e($product->title); ?></p>
                                            <?php if($product->title_en): ?>
                                            <span class="text-muted text-overflow-1"><?php echo e($product->title_en); ?></span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="rating">
                                            <div class="number">
                                                <?php if($product->variants->count() > 1): ?>
                                                <span class="text-muted font-12"><?php echo e($product->variants->count()); ?> تنوع</span>
                                                <?php endif; ?>
                                            </div>
                                            <div class="icon"><i class="bi bi-star-fill"></i></div>
                                        </div>
                                    </div>
                                    <div class="product-action">
                                        <div class="price">
                                            <?php if($price > 0): ?>
                                                <?php if($hasDiscount): ?>
                                                <p class="new-price"><?php echo e(number_format($finalPrice)); ?> تومان</p>
                                                <p class="old-price"><?php echo e(number_format($price)); ?> تومان</p>
                                                <?php else: ?>
                                                <p class="new-price"><?php echo e(number_format($price)); ?> تومان</p>
                                                <?php endif; ?>
                                            <?php else: ?>
                                            <p class="new-price text-muted">تماس بگیرید</p>
                                            <?php endif; ?>
                                        </div>
                                        <div class="link">
                                            <?php if($inStock): ?>
                                            <a href="<?php echo e(route('product.show', $product->slug)); ?>"
                                                class="btn border-0 rounded-3 main-color-one-bg">
                                                <i class="bi bi-basket text-white"></i>
                                                <span class="text-white">خرید</span>
                                            </a>
                                            <?php else: ?>
                                            <span class="btn border-0 rounded-3 btn-out-of-stock disabled" aria-disabled="true">
                                                <i class="bi bi-x-circle"></i>
                                                <span>ناموجود</span>
                                            </span>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>

                        <?php if($products->hasPages()): ?>
                        <div class="my-paginate my-4">
                            <nav>
                                <ul class="pagination flex-wrap justify-content-center">
                                    <?php if($products->onFirstPage()): ?>
                                    <li class="page-item disabled"><span class="page-link rounded-3">قبلی</span></li>
                                    <?php else: ?>
                                    <li class="page-item"><a class="page-link rounded-3" href="<?php echo e($products->previousPageUrl()); ?>">قبلی</a></li>
                                    <?php endif; ?>

                                    <?php $__currentLoopData = $products->getUrlRange(1, $products->lastPage()); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $page => $url): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <li class="page-item <?php echo e($products->currentPage() === $page ? 'active' : ''); ?>">
                                        <a class="page-link rounded-3" href="<?php echo e($url); ?>"><?php echo e($page); ?></a>
                                    </li>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                    <?php if($products->hasMorePages()): ?>
                                    <li class="page-item"><a class="page-link rounded-3" href="<?php echo e($products->nextPageUrl()); ?>">بعدی</a></li>
                                    <?php else: ?>
                                    <li class="page-item disabled"><span class="page-link rounded-3">بعدی</span></li>
                                    <?php endif; ?>
                                </ul>
                            </nav>
                        </div>
                        <?php endif; ?>
                        <?php endif; ?>
                    </div>

                </div>

            </div>

        </form>

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

<?php $__env->startSection('scripts'); ?>
<script src="<?php echo e(asset('theme/assets/plugin/nouislider/nouislider.min.js')); ?>"></script>
<script>
(function () {
    var priceMinInput = document.getElementById('shopPriceMin');
    var priceMaxInput = document.getElementById('shopPriceMax');

    document.querySelectorAll('.shop-price-slider').forEach(function (slider) {
        var filterPrice = slider.closest('.filter-price');
        var minDisplay  = filterPrice.querySelector('.min-price-filter');
        var maxDisplay  = filterPrice.querySelector('.max-price-filter');

        var maxVal  = parseInt(slider.dataset.max, 10)     || 50000000;
        var initMin = parseInt(slider.dataset.initMin, 10) || 0;
        var initMax = parseInt(slider.dataset.initMax, 10) || maxVal;

        noUiSlider.create(slider, {
            start: [initMin, initMax],
            connect: true,
            range: { min: 0, max: maxVal },
            step: 100000,
            format: {
                to:   function (v) { return Math.round(v); },
                from: function (v) { return Number(v); }
            }
        });

        slider.noUiSlider.on('update', function (values, handle) {
            var val = values[handle];
            var formatted = new Intl.NumberFormat('fa-IR').format(val);
            if (handle === 0) {
                if (minDisplay) minDisplay.value = formatted;
                if (priceMinInput) priceMinInput.value = val;
            } else {
                if (maxDisplay) maxDisplay.value = formatted;
                if (priceMaxInput) priceMaxInput.value = val;
            }
        });
    });
})();
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('site.layouts.site-layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/louishop/public_html/engine/resources/views/site/amazing.blade.php ENDPATH**/ ?>