<div>
    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8">
        <div>
            <h1 class="text-2xl font-bold text-gray-800">المنتجات</h1>
            <p class="text-sm text-gray-500 mt-1">تصفح المنتجات وأضفها إلى سلة المشتريات</p>
        </div>
        <div class="flex gap-3">
            <input wire:model.live.debounce.300ms="search" type="text" placeholder="بحث عن منتج..."
                   class="px-4 py-2.5 rounded-xl border border-gray-200 focus:border-emerald-500 focus:ring-2 focus:ring-emerald-500/20 outline-none text-sm w-60">
            <select wire:model.live="fulfillmentFilter"
                    class="px-4 py-2.5 rounded-xl border border-gray-200 focus:border-emerald-500 outline-none text-sm">
                <option value="">الكل</option>
                <option value="in_stock">من المخزن</option>
                <option value="on_demand">حسب الطلب</option>
            </select>
        </div>
    </div>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($products->isEmpty()): ?>
        <div class="bg-white rounded-2xl border border-gray-200 p-12 text-center">
            <svg class="w-16 h-16 mx-auto text-gray-300 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"/></svg>
            <p class="text-gray-500">لا توجد منتجات مطابقة</p>
        </div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    <div class="space-y-6">
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoop($loop->index); ?><?php endif; ?>
            <div class="bg-white rounded-2xl border border-gray-200 overflow-hidden shadow-sm">
                
                <button wire:click="toggleProduct(<?php echo e($product->id); ?>)"
                        class="w-full px-6 py-5 flex items-center justify-between text-right hover:bg-gray-50 transition">
                    <div class="flex items-center gap-4">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($product->image): ?>
                            <?php $imgPath = $product->image_thumbnail ?? $product->image_webp ?? $product->image; ?>
                            <img src="<?php echo e(asset('storage/' . $imgPath)); ?>" alt="<?php echo e($product->name); ?>"
                                 class="w-12 h-12 rounded-xl object-cover" loading="lazy">
                        <?php else: ?>
                            <div class="w-12 h-12 rounded-xl bg-emerald-100 flex items-center justify-center">
                                <svg class="w-6 h-6 text-emerald-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"/></svg>
                            </div>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <div>
                            <h3 class="font-bold text-gray-800"><?php echo e($product->name); ?></h3>
                            <div class="flex items-center gap-3 mt-1">
                                <span class="text-xs px-2.5 py-0.5 rounded-full <?php echo e($product->fulfillment_type === 'in_stock' ? 'bg-blue-100 text-blue-700' : 'bg-orange-100 text-orange-700'); ?>">
                                    <?php echo e($product->fulfillment_type === 'in_stock' ? 'من المخزن' : 'حسب الطلب'); ?>

                                </span>
                                <span class="text-xs text-gray-500"><?php echo e($product->variants_count); ?> نقشة</span>
                            </div>
                        </div>
                    </div>
                    <div class="flex items-center gap-4">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($product->pricingTiers->isNotEmpty()): ?>
                            <div class="text-left hidden sm:block">
                                <span class="text-xs text-gray-500">أقل سعر</span>
                                <p class="text-lg font-bold text-emerald-600"><?php echo e(number_format($product->pricingTiers->last()->unit_price, 2)); ?> ج.م</p>
                            </div>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <svg class="w-5 h-5 text-gray-400 transition-transform <?php echo e($expandedProductId === $product->id ? 'rotate-180' : ''); ?>"
                             fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/></svg>
                    </div>
                </button>

                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($expandedProductId === $product->id): ?>
                    <div class="border-t border-gray-100">
                        
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($product->pricingTiers->isNotEmpty()): ?>
                            <div class="px-6 py-4 bg-gradient-to-l from-emerald-50 to-teal-50 border-b border-gray-100">
                                <h4 class="text-sm font-semibold text-gray-700 mb-3">الشرائح السعرية</h4>
                                <div class="grid grid-cols-2 sm:grid-cols-4 gap-2">
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $product->pricingTiers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tier): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoop($loop->index); ?><?php endif; ?>
                                        <div class="bg-white rounded-xl p-3 text-center border border-emerald-100">
                                            <p class="text-xs text-gray-500"><?php echo e($tier->min_qty); ?> - <?php echo e($tier->max_qty ?? '∞'); ?> قطعة</p>
                                            <p class="text-lg font-bold text-emerald-600 mt-1"><?php echo e(number_format($tier->unit_price, 2)); ?></p>
                                            <p class="text-xs text-gray-400">ج.م / قطعة</p>
                                        </div>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                                </div>
                            </div>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

                        
                        <div class="px-6 py-4">
                            <h4 class="text-sm font-semibold text-gray-700 mb-3">النقشات المتاحة</h4>
                            <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3">
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $product->variants; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $variant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoop($loop->index); ?><?php endif; ?>
                                    <div class="bg-gray-50 rounded-xl overflow-hidden border border-gray-200 hover:border-emerald-300 transition">
                                        
                                        <div class="relative aspect-square bg-white overflow-hidden">
                                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($variant->image): ?>
                                                <?php $vImgPath = $variant->image_thumbnail ?? $variant->image_webp ?? $variant->image; ?>
                                                <img src="<?php echo e(asset('storage/' . $vImgPath)); ?>" alt="<?php echo e($variant->pattern_name); ?>"
                                                     class="w-full h-full object-cover" loading="lazy">
                                            <?php else: ?>
                                                <div class="w-full h-full flex items-center justify-center text-gray-300">
                                                    <svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m2.25 15.75 5.159-5.159a2.25 2.25 0 0 1 3.182 0l5.159 5.159m-1.5-1.5 1.409-1.409a2.25 2.25 0 0 1 3.182 0l2.909 2.909M3.75 21h16.5A2.25 2.25 0 0 0 22.5 18.75V5.25A2.25 2.25 0 0 0 20.25 3H3.75A2.25 2.25 0 0 0 1.5 5.25v13.5A2.25 2.25 0 0 0 3.75 21Z"/></svg>
                                                </div>
                                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($product->fulfillment_type === 'in_stock'): ?>
                                                <span class="absolute top-1.5 right-1.5 text-[10px] px-1.5 py-0.5 rounded-full <?php echo e($variant->stock > 0 ? 'bg-emerald-500 text-white' : 'bg-red-500 text-white'); ?>">
                                                    <?php echo e($variant->stock > 0 ? $variant->stock : 'نفذ'); ?>

                                                </span>
                                            <?php else: ?>
                                                <span class="absolute top-1.5 right-1.5 text-[10px] px-1.5 py-0.5 rounded-full bg-orange-500 text-white"><?php echo e($variant->lead_time_days); ?>ي</span>
                                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                        </div>

                                        
                                        <div class="p-2.5">
                                            <p class="text-xs font-semibold text-gray-800 line-clamp-1 mb-1"><?php echo e($variant->pattern_name); ?></p>
                                            <div class="flex items-center gap-1.5">
                                                <input type="number" wire:model="quantities.<?php echo e($variant->id); ?>" min="1" value="1"
                                                       class="w-12 text-center px-1 py-1 rounded-lg border border-gray-200 text-xs focus:border-emerald-500 outline-none">
                                                <button wire:click="addToCart(<?php echo e($variant->id); ?>, <?php echo e($product->id); ?>)"
                                                        <?php if($product->fulfillment_type === 'in_stock' && $variant->stock <= 0): ?> disabled <?php endif; ?>
                                                        class="flex-1 bg-emerald-600 hover:bg-emerald-700 disabled:bg-gray-300 disabled:cursor-not-allowed text-white text-xs font-medium py-1 px-2 rounded-lg transition">
                                                    أضف
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                            </div>
                        </div>
                    </div>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
    </div>
</div>
<?php /**PATH E:\Laravel-Project\tager_plus\resources\views/livewire/merchant/products-page.blade.php ENDPATH**/ ?>