@if(!empty($isUserSharing))
{{-- Image 1: User is sharing this service (public or draft/private) --}}
@php
$serviceId = (int) ($subscription->service_id ?? $subscription->service?->id ?? 0);
$hasSubId = ! empty($subscription->id);
$allTabUrl = $hasSubId
? route('subscriptions.show', array_filter(['subscription' => $subscription->id, 'country' => $selectedCountry]))
: ($serviceId > 0 ? route('subscriptions.service.show', array_filter(['service' => $serviceId, 'country' => $selectedCountry])) : '#');
$isAllActive = empty($selectedPlan) && empty($selectedPlanKey);
@endphp
All ({{ $listingCount }})
@foreach($planCounts as $plan)
@php
$planParam = $plan['id'] > 0 ? $plan['id'] : $plan['key'];
$planTabUrl = $hasSubId
? route('subscriptions.show', array_filter(['subscription' => $subscription->id, 'plan' => $planParam, 'country' => $selectedCountry]))
: ($serviceId > 0 ? route('subscriptions.service.show', array_filter(['service' => $serviceId, 'plan' => $planParam, 'country' => $selectedCountry])) : '#');
$isPlanActive = (!empty($selectedPlan) && (int) $selectedPlan === (int) $plan['id'])
|| (!empty($selectedPlanKey) && $selectedPlanKey === $plan['key']);
$matchingRawPlan = $rawPlans->first(fn ($rp) => in_array((int) $rp->id, (array) ($plan['ids'] ?? []), true) || strcasecmp((string) $rp->name, $plan['name']) === 0);
$pillPrice = 0.0;
if ($matchingRawPlan) {
$pPrice = (float) ($matchingRawPlan->price ?? 0);
$aFee = (float) ($matchingRawPlan->admin_fee ?? 0);
$sPrice = (float) ($subscription->service?->price ?? 0);
if ($sPrice > 0) {
$pillPrice = round($sPrice + $aFee, 2);
} elseif ($pPrice > 0) {
$pillPrice = $pPrice;
} elseif (! empty($matchingRawPlan->monthly_price) && (float) $matchingRawPlan->monthly_price > 0) {
$pillPrice = (float) $matchingRawPlan->monthly_price;
} elseif (! empty($matchingRawPlan->total_price) && (float) $matchingRawPlan->total_price > 0) {
$pillPrice = (float) $matchingRawPlan->total_price;
}
}
@endphp
{{ $plan['name'] }} ({{ $plan['count'] }})
@endforeach
No Active Packages Found
There are currently no active public packages available for this service.
@foreach($serviceSubscriptions as $item)
@php
$totalSeats = max((int) $item->total_slots, 1);
$activeMembersSlots = (int) ($item->members ? $item->members->whereNotIn('status', ['cancelled', 'expired'])->sum('slots_taken') : 0);
$maxShareable = max($totalSeats - (1 + $activeMembersSlots), 0);
$availableSlots = isset($item->available_slots) ? (int) $item->available_slots : $maxShareable;
// Remaining seats available for co-subscribers to join (respects locked/reserved seats)
$remainingSeats = max(min($availableSlots, $maxShareable), 0);
// Occupied seats include the owner (1), active members, and all locked/reserved slots
$occupiedSeats = min($totalSeats, max($totalSeats - $remainingSeats, 1 + $activeMembersSlots));
$visibleSeatSlots = min(max($totalSeats, 1), 6);
$trustScore = (int) max(60, min(100, 80 + (float) ($item->owner?->trust_score ?? 0)));
$isExpired = (bool) $item->is_expired;
if ($isExpired) {
continue;
}
$isJoinable = $remainingSeats > 0 && ! in_array($item->status, ['cancelled', 'expired'], true) && ! $isExpired;
$isYouTube = str_contains(strtolower($item->service?->name ?? ''), 'youtube');
$isVerified = ! empty($item->is_invoice_verified) || ($item->invoice_status ?? '') === 'approved';
$isOwnListing = auth()->check() && (int) auth()->id() === (int) $item->owner_id;
$serviceName = (string) ($item->service?->name ?? $subscription->service?->name ?? 'Subscription');
$palette = $cardPalettes[abs(crc32((string) ($item->servicePlan?->name ?? $serviceName))) % count($cardPalettes)];
$cardLogo = marketplaceImageUrl($item->service?->logo ?: $subscription->service?->logo ?: $subscription->service?->category?->image_url);
$compactLogoLabel = preg_replace('/[^A-Z0-9]/', '', strtoupper($serviceName)) ?: 'APP';
$serviceLogoChunks = collect();
if (preg_match('/\s/', trim($serviceName))) {
$serviceLogoChunks = collect(preg_split('/[\s\-_]+/', strtoupper($serviceName)))
->map(fn ($chunk) => preg_replace('/[^A-Z0-9]/', '', (string) $chunk))
->filter()
->map(fn ($chunk) => substr($chunk, 0, 5))
->take(3)
->values();
}
if ($serviceLogoChunks->isEmpty()) {
$serviceLogoChunks = collect([substr($compactLogoLabel, 0, 5)]);
}
$owner = $item->owner;
$isHostOnline = $owner ? $owner->isOnline() : false;
$hostLastSeen = $owner ? $owner->lastSeenForHumans() : 'some time ago';
$ownerInitials = '';
if ($owner && $owner->name) {
$ownerInitials = collect(explode(' ', trim((string) $owner->name)))
->filter()
->take(2)
->map(fn ($part) => strtoupper(substr($part, 0, 1)))
->implode('');
}
$ownerAvatar = str_replace('\\', '/', trim((string) data_get($owner, 'avatar', '')));
$ownerAvatarSrc = '';
if ($ownerAvatar !== '') {
if (preg_match('/^https?:\/\//i', $ownerAvatar)) {
$ownerAvatarSrc = $ownerAvatar;
} elseif (file_exists(public_path(ltrim($ownerAvatar, '/')))) {
$ownerAvatarSrc = asset(ltrim($ownerAvatar, '/'));
} elseif (file_exists(public_path('assets/img/avatars/users/' . basename($ownerAvatar)))) {
$ownerAvatarSrc = asset('assets/img/avatars/users/' . basename($ownerAvatar));
} else {
$ownerAvatarSrc = asset(ltrim($ownerAvatar, '/'));
}
} elseif (file_exists(public_path('assets/img/avatars/user_avatar.webp'))) {
$ownerAvatarSrc = asset('assets/img/avatars/user_avatar.webp');
}
$pricePerSlot = round((float) $item->price_per_slot * (float) ($selectedCountryMeta['rate'] ?? 1), 2);
$totalPriceConverted = round((float) $item->total_price * (float) ($selectedCountryMeta['rate'] ?? 1), 2);
$createdAtFormatted = $item->created_at ? $item->created_at->format('d M Y, h:i A') : 'N/A';
$createdAtDiff = $item->created_at ? $item->created_at->diffForHumans() : '';
$startsAtFormatted = $item->effective_starts_at->format('d M Y');
$endsAtFormatted = $item->effective_ends_at->format('d M Y');
$endsAtDiff = $item->is_expired
? 'Expired'
: 'Active • ' . $item->effective_ends_at->diffForHumans(null, true) . ' remaining';
$packageDataPayload = [
'id' => (int) $item->id,
'title' => (string) ($item->title ?: ($item->servicePlan?->name ?? 'Standard Package')),
'service_name' => (string) $serviceName,
'service_logo' => (string) ($cardLogo ?: ''),
'category_name' => (string) ($item->service?->category?->name ?? 'Subscription'),
'plan_name' => (string) ($item->servicePlan?->name ?? 'Standard'),
'owner_name' => (string) ($owner?->name ?? 'Provider'),
'owner_avatar' => (string) $ownerAvatarSrc,
'owner_initials' => (string) ($ownerInitials !== '' ? $ownerInitials : 'U'),
'trust_score' => (int) $trustScore,
'is_verified' => (bool) $isVerified,
'is_online' => (bool) $isHostOnline,
'last_seen' => (string) $hostLastSeen,
'total_slots' => (int) $totalSeats,
'available_slots' => (int) $remainingSeats,
'occupied_slots' => (int) $occupiedSeats,
'price_per_slot' => number_format($pricePerSlot, 2),
'currency_symbol' => (string) $currencySymbol,
'total_price' => number_format($totalPriceConverted, 2),
'created_at_formatted' => $createdAtFormatted,
'created_at_diff' => $createdAtDiff,
'starts_at_formatted' => $startsAtFormatted,
'ends_at_formatted' => $endsAtFormatted,
'ends_at_diff' => $endsAtDiff,
'status' => ucfirst((string) ($item->status ?? 'Active')),
'service_description' => (string) ($item->service?->description ?: (\App\Models\Service::where('name', $item->service?->name)->whereNotNull('description')->value('description') ?? '')),
'notes' => (string) ($item->notes ?? ''),
'requires_manual_approval' => (bool) $item->requires_manual_approval,
'is_joinable' => (bool) $isJoinable,
'is_youtube' => (bool) $isYouTube,
'is_own' => (bool) $isOwnListing,
'join_url' => route('subscriptions.join.create', $item),
'request_url' => route('subscriptions.join.request', $item),
'manage_url' => route('subscriptions.manage', $item),
];
@endphp
@php
$ringCircumference = 251.33;
$clampedTrustScore = min(max((int) $trustScore, 0), 100);
$ringOffset = round($ringCircumference * (1 - ($clampedTrustScore / 100)), 2);
$trustClass = $clampedTrustScore >= 80 ? 'is-high' : ($clampedTrustScore >= 50 ? 'is-med' : 'is-low');
@endphp
@if($ownerAvatarSrc !== '')

@endif
{{ $ownerInitials !== '' ? $ownerInitials : 'U' }}
{{ $trustScore }}%
@if($isExpired)
Expired
@elseif($isHostOnline)
Online
@else
Offline · {{ $hostLastSeen }}
@endif
@if($isVerified)
Verified Invoice
@endif
{{ $owner?->name ?? 'Provider' }}
@if($item->servicePlan?->name)
{{ $item->servicePlan?->name }}
@endif
@if($item->title)
{{ $item->title }}
@endif
@for($i = 0; $i < $visibleSeatSlots; $i++)
@endfor
{{ $remainingSeats }} seat(s) left
@if($isOwnListing)
View details
@endif
{{ number_format($pricePerSlot, 2) }}
{{ $currencySymbol }}
/ mo
@if($isOwnListing)
@endif
@auth
@if($isOwnListing)
@elseif($isExpired)
@elseif($remainingSeats <= 0)
@elseif(! $isJoinable)
@else
{{ $isYouTube ? 'Request' : 'Join' }}
@endif
@else
@if($isExpired)
@elseif($remainingSeats <= 0)
@elseif(! $isJoinable)
@else
{{ $isYouTube ? 'Request' : 'Join' }}
@endif
@endauth
@endforeach