@if($sellerList->count() > 0)
@php $rank = 1; @endphp
@foreach($sellerList as $seller)
@php
$shop = $seller->shop ?? null;
$plan = $shop ? $shop->seller_package : null;
$shopPhone = preg_replace('/\D/','',$seller->phone ?? '');
$dist = isset($seller->distance) ? round($seller->distance, 1) : null;
$radius = $plan->radius_range ?? 0;
$leadsLimit = $plan->leads_limit ?? 0;
$planExpiry = $shop->package_invalid_at ?? null;
$isExpired = $planExpiry && \Carbon\Carbon::parse($planExpiry)->isPast();
$isWithin = $dist !== null && $radius > 0 && $dist <= $radius;
$isAssigned = $userInquiry->seller_id == $seller->id;
// Today leads count
$todayLeads = \App\Models\CustomerInquiry::where('seller_id',$seller->id)
->whereDate('created_at', today())->count();
// Plan badge
if(!$plan) { $planClass = 'pb-noplan'; $planText = '⚠️ No Plan'; }
elseif($isExpired) { $planClass = 'pb-expired'; $planText = '❌ Expired'; }
else { $planClass = 'pb-premium'; $planText = '✅ '.$plan->name; }
@endphp
{{-- Rank + Checkbox --}}
{{-- Shop Logo --}}
@if($shop && $shop->logo)
 }})
@endif
{{-- Main Info --}}
{{ $shop->name ?? $seller->name }}
@if($isAssigned)
✅ Currently Assigned
@endif
{{ $planText }}
{{-- Key metrics row --}}
{{-- Distance --}}
Distance
@if($dist !== null)
📍 {{ $dist }} km
@else
N/A
@endif
{{-- Radius --}}
Plan Radius
@if($radius == 0)
⚠️ 0 km (no limit set)
@else
{{ $radius }} km
@if($dist !== null)
{{ $isWithin ? '✅ within range' : '❌ out of range' }}
@endif
@endif
{{-- Leads --}}
Leads (today/limit)
{{ $todayLeads }} / {{ $leadsLimit == 0 ? '∞' : $leadsLimit }}
@if($leadsLimit > 0 && $todayLeads >= $leadsLimit)
⚠️ limit reached
@endif
{{-- Plan expiry --}}
@if($planExpiry)
Plan Valid Till
{{ \Carbon\Carbon::parse($planExpiry)->format('d M Y') }}
{{ $isExpired ? '❌ Expired' : '✅' }}
@endif
{{-- Location --}}
Seller Location
{{ $seller->city ?? '' }} {{ $seller->state ? ', '.$seller->state : '' }}
{{-- Warnings --}}
@if($radius == 0)
⚠️ Radius = 0 km — automatic leads వెళ్ళవు. Admin manually assign చేయాలి లేదా plan update చేయాలి.
@elseif(!$isWithin && $dist !== null)
⚠️ Buyer {{ $dist }} km దూరంలో ఉన్నారు, seller radius {{ $radius }} km మాత్రమే — range బయట ఉంది.
@endif
@if($isExpired)
❌ Plan expired — automatic leads వెళ్ళవు.
@endif
{{-- Actions --}}
@if(!$isAssigned)
@endif
@if($seller->phone)
📞 Call
💬 WhatsApp
@endif
@php $rank++; @endphp
@endforeach
@else
🔍
No sellers found for "{{ $categoryName }}"
ఈ category లో sellers లేరు లేదా location data లేదు.
@endif