count(); return "{$active} active subscribers across all campaigns."; } public function getTabs(): array { $campaigns = ScheduledGivingCampaign::withCount([ 'donations as active_count' => fn ($q) => $q->where('is_active', true), ])->get(); $tabs = []; // All active tab first $totalActive = ScheduledGivingDonation::where('is_active', true)->count(); $tabs['active'] = Tab::make('All Active') ->icon('heroicon-o-check-circle') ->badge($totalActive) ->badgeColor('success') ->modifyQueryUsing(fn (Builder $q) => $q->where('is_active', true)); // One tab per campaign foreach ($campaigns as $c) { $slug = str($c->title)->slug()->toString(); $tabs[$slug] = Tab::make($c->title) ->icon('heroicon-o-calendar') ->badge($c->active_count > 0 ? $c->active_count : null) ->badgeColor($c->active ? 'primary' : 'gray') ->modifyQueryUsing(fn (Builder $q) => $q ->where('scheduled_giving_campaign_id', $c->id) ->where('is_active', true)); } // Failed payments tab $failedCount = ScheduledGivingDonation::where('is_active', true) ->whereHas('payments', fn ($q) => $q ->where('is_paid', false) ->where('attempts', '>', 0)) ->count(); $tabs['failed'] = Tab::make('Failed Payments') ->icon('heroicon-o-exclamation-triangle') ->badge($failedCount > 0 ? $failedCount : null) ->badgeColor('danger') ->modifyQueryUsing(fn (Builder $q) => $q ->where('is_active', true) ->whereHas('payments', fn ($sub) => $sub ->where('is_paid', false) ->where('attempts', '>', 0))); // Cancelled $cancelled = ScheduledGivingDonation::where('is_active', false)->count(); $tabs['cancelled'] = Tab::make('Cancelled') ->icon('heroicon-o-x-circle') ->badge($cancelled > 0 ? $cancelled : null) ->badgeColor('gray') ->modifyQueryUsing(fn (Builder $q) => $q->where('is_active', false)); // Everything $tabs['all'] = Tab::make('Everything') ->icon('heroicon-o-squares-2x2'); return $tabs; } protected function getHeaderActions(): array { return []; } public function getDefaultActiveTab(): string | int | null { return 'active'; } }