{{-- Subscription / trial expiration banner. Surfaces a warning at the top of every authenticated tenant page so the clinic owner cannot miss an upcoming lapse. The banner has three modes: - past : already expired (a grace day before auto-suspension) - urgent : <= 3 days left - approaching : <= 14 days for subscription, <= 7 days for trial Hidden entirely when no clinic is in scope (guest pages) or when the runway is comfortable. --}} @php $clinic = $currentClinic ?? null; if (! $clinic) { $bannerVisible = false; } else { // Pick the active countdown source. Trial wins while status == 'trial'; // otherwise we look at subscription_ends_at. $isTrial = $clinic->status === 'trial'; $endsAt = $isTrial ? $clinic->trial_ends_at : $clinic->subscription_ends_at; if (! $endsAt) { $bannerVisible = false; } else { $now = now(); // diffInDays(false) preserves sign — negative when endsAt is past. $rawDays = $now->diffInDays($endsAt, false); $daysLeft = (int) ceil($rawDays); $isPast = $rawDays < 0; // Urgency thresholds: shorter window for trials since they're // already a finite resource by definition. $approachingThreshold = $isTrial ? 7 : 14; $urgentThreshold = 3; if ($isPast) { $mode = 'past'; $bannerVisible = true; } elseif ($daysLeft <= $urgentThreshold) { $mode = 'urgent'; $bannerVisible = true; } elseif ($daysLeft <= $approachingThreshold) { $mode = 'approaching'; $bannerVisible = true; } else { $bannerVisible = false; } // Cosmetics — only resolved when the banner is actually shown, // since match($mode) on an unset $mode would raise. if ($bannerVisible) { $palette = match ($mode) { 'past' => ['bg' => 'danger', 'icon' => 'alert-octagon', 'border' => '#dc2626'], 'urgent' => ['bg' => 'danger', 'icon' => 'alert-circle', 'border' => '#ef4444'], 'approaching' => ['bg' => 'warning', 'icon' => 'alert-triangle', 'border' => '#f59e0b'], }; $title = match ($mode) { 'past' => $isTrial ? 'انتهت فترة التجربة' : 'انتهت مدة الاشتراك', 'urgent' => $isTrial ? "تنتهي فترة التجربة خلال {$daysLeft} " . ($daysLeft === 1 ? 'يوم' : 'أيام') : "ينتهي اشتراكك خلال {$daysLeft} " . ($daysLeft === 1 ? 'يوم' : 'أيام'), 'approaching' => $isTrial ? "تنتهي فترة التجربة خلال {$daysLeft} يوم" : "اشتراكك ينتهي خلال {$daysLeft} يوم", }; $body = match ($mode) { 'past' => 'سيتم إيقاف الوصول للنظام تلقائياً قريباً. يرجى التواصل مع الإدارة فوراً لتجديد الاشتراك.', 'urgent' => 'يرجى التواصل مع الإدارة لتجديد الاشتراك قبل انقطاع الخدمة.', 'approaching' => 'لتفادي انقطاع الخدمة، يُفضّل التجديد قبل تاريخ الانتهاء.', }; } } } @endphp @if(! empty($bannerVisible) && $bannerVisible)
@endif