<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('header', null, []); ?> 
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            لیست فاکتورهای من
        </h2>
     <?php $__env->endSlot(); ?>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            
            
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg mb-6">
                <form method="GET" action="<?php echo e(route('agent.invoices.index')); ?>" class="p-4 grid grid-cols-1 md:grid-cols-3 gap-4">
                    <?php if (isset($component)) { $__componentOriginal18c21970322f9e5c938bc954620c12bb = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal18c21970322f9e5c938bc954620c12bb = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.text-input','data' => ['type' => 'text','name' => 'search','placeholder' => 'جستجو (شماره فاکتور، نام مشتری...)','value' => ''.e(request('search')).'','class' => 'w-full md:col-span-2']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('text-input'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'text','name' => 'search','placeholder' => 'جستجو (شماره فاکتور، نام مشتری...)','value' => ''.e(request('search')).'','class' => 'w-full md:col-span-2']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal18c21970322f9e5c938bc954620c12bb)): ?>
<?php $attributes = $__attributesOriginal18c21970322f9e5c938bc954620c12bb; ?>
<?php unset($__attributesOriginal18c21970322f9e5c938bc954620c12bb); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal18c21970322f9e5c938bc954620c12bb)): ?>
<?php $component = $__componentOriginal18c21970322f9e5c938bc954620c12bb; ?>
<?php unset($__componentOriginal18c21970322f9e5c938bc954620c12bb); ?>
<?php endif; ?>
                    
                    
                    <select name="status" class="border-gray-300 rounded-md shadow-sm w-full" onchange="this.form.submit()">
                        <option value="all" <?php if(request('status') == 'all'): echo 'selected'; endif; ?>>همه وضعیت‌ها</option>
                        <option value="pending" <?php if(request('status') == 'pending'): echo 'selected'; endif; ?>>در انتظار پرداخت</option>
                        <option value="processing" <?php if(request('status') == 'processing'): echo 'selected'; endif; ?>>در حال انجام</option>
                        <option value="ready_to_ship" <?php if(request('status') == 'ready_to_ship'): echo 'selected'; endif; ?>>آماده برای ارسال</option>
                        <option value="shipped" <?php if(request('status') == 'shipped'): echo 'selected'; endif; ?>>ارسال شده</option>
                        <option value="delivered" <?php if(request('status') == 'delivered'): echo 'selected'; endif; ?>>تحویل داده شده</option>
                        <option value="returned" <?php if(request('status') == 'returned'): echo 'selected'; endif; ?>>مرجوع شده</option>
                        <option value="rejected" <?php if(request('status') == 'rejected'): echo 'selected'; endif; ?>>لغو شده</option>
                    </select>
                    
                </form>
            </div>

            
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <?php $__empty_1 = true; $__currentLoopData = $invoices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $invoice): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="bg-white overflow-hidden shadow-lg rounded-lg flex flex-col justify-between">
                        
                        <div class="p-4 flex justify-between items-center border-b">
                            <span class="font-bold text-gray-800">#<?php echo e($invoice->id); ?></span>
                            <?php
                                // ✅ START: رنگ‌بندی وضعیت اصلاح شد
                                $statusClasses = match($invoice->status) {
                                    'pending' => 'bg-yellow-100 text-yellow-800',
                                    'processing' => 'bg-blue-100 text-blue-800',
                                    'ready_to_ship' => 'bg-cyan-100 text-cyan-800', // جدید
                                    'shipped' => 'bg-indigo-100 text-indigo-800',
                                    'delivered' => 'bg-green-100 text-green-800',
                                    'returned' => 'bg-orange-100 text-orange-800', // جدید
                                    'rejected' => 'bg-red-100 text-red-800',
                                    default => 'bg-gray-100 text-gray-800',
                                };
                                // ✅ END: رنگ‌بندی وضعیت اصلاح شد
                            ?>
                            <span class="text-xs font-semibold px-3 py-1 rounded-full <?php echo e($statusClasses); ?>">
                                
                                <?php echo e(__($invoice->status)); ?>

                            </span>
                        </div>

                        
                        <div class="p-4 space-y-3 text-sm">
                            <p class="flex justify-between"><span class="text-gray-500">مشتری:</span><span class="font-medium"><?php echo e($invoice->customer->name); ?></span></p>
                            <p class="flex justify-between"><span class="text-gray-500">تعداد اقلام:</span><span class="font-medium"><?php echo e($invoice->products_count); ?> کالا</span></p>
                            <p class="flex justify-between"><span class="text-gray-500">طرح:</span><span class="font-medium"><?php echo e($invoice->planOption->plan->name); ?> (<?php echo e($invoice->planOption->months); ?> ماهه)</span></p>
                            <p class="flex justify-between"><span class="text-gray-500">تاریخ:</span><span class="font-medium"><?php echo e(verta($invoice->created_at)->format('Y/m/d')); ?></span></p>
                            <p class="flex justify-between text-base font-bold border-t pt-3 mt-3">
                                <span>مبلغ (ریال):</span>
                                <span><?php echo e(number_format($invoice->final_price)); ?></span>
                            </p>
                        </div>

                        
                        <div class="p-4 bg-gray-50 grid grid-cols-2 gap-3">
                            <?php if($invoice->status === 'pending'): ?>
                                <a href="<?php echo e(route('payment.start', $invoice->id)); ?>" class="block w-full text-center px-4 py-2 bg-green-600 border rounded-md font-semibold text-xs text-white uppercase hover:bg-green-500">
                                    پرداخت
                                </a>
                            <?php elseif($invoice->status === 'rejected'): ?>
                                <span class="block w-full text-center px-4 py-2 bg-red-500 border rounded-md font-semibold text-xs text-white uppercase cursor-not-allowed">
                                    لغو شده
                                </span>
                            <?php else: ?>
                                <span class="block w-full text-center px-4 py-2 bg-gray-400 border rounded-md font-semibold text-xs text-white uppercase cursor-not-allowed">
                                    در حال پیگیری
                                </span>
                            <?php endif; ?>

                            <a href="<?php echo e(route('agent.invoices.print', $invoice->id)); ?>" target="_blank" 
                               class="block w-full text-center px-4 py-2 bg-white border border-gray-300 rounded-md font-semibold text-xs text-gray-700 uppercase hover:bg-gray-50">
                                پیش فاکتور 
                            </a>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <p class="col-span-3 text-center text-gray-500 py-10">
                        هیچ فاکتوری یافت نشد.
                    </p>
                <?php endif; ?>
            </div>

            <div class="mt-6">
                <?php echo e($invoices->links()); ?>

            </div>
        </div>
    </div>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?><?php /**PATH D:\laragon\www\installment-app\resources\views/agent/invoices/index.blade.php ENDPATH**/ ?>