description('Registered users') ->descriptionIcon('heroicon-o-user-group') ->color('primary') ->chart($this->getMonthlyData(User::class)) ->extraAttributes(['class' => 'hover:shadow-lg transition-shadow']), Stat::make('Total Reform Projects', ReformProject::count()) ->description('Submitted reforms') ->descriptionIcon('heroicon-o-document-text') ->color('success') ->chart($this->getMonthlyData(ReformProject::class)) ->extraAttributes(['class' => 'hover:shadow-lg transition-shadow']), Stat::make('Publications', Publication::count()) ->description('Available documents') ->descriptionIcon('heroicon-o-document-text') ->color('info') ->chart($this->getMonthlyData(Publication::class)) ->extraAttributes(['class' => 'hover:shadow-lg transition-shadow']), Stat::make('News Published', News::count()) ->description('Latest updates') ->descriptionIcon('heroicon-o-newspaper') ->color('warning') ->chart($this->getMonthlyData(News::class)) ->extraAttributes(['class' => 'hover:shadow-lg transition-shadow']), Stat::make('Active Reform Projects', ReformProject::where('status', 'In Progress')->count()) ->description('Currently in progress') ->descriptionIcon('heroicon-o-arrow-trending-up') ->color('info') ->chart($this->getStatusData('active')) ->extraAttributes(['class' => 'hover:shadow-lg transition-shadow']), ]; } private function getMonthlyData(string $model): array { return $model::query() ->selectRaw('MONTH(created_at) as month, COUNT(*) as count') ->whereYear('created_at', now()->year) ->groupBy('month') ->orderBy('month') ->get() ->pluck('count') ->toArray(); } private function getStatusData(string $status): array { return ReformProject::query() ->selectRaw('MONTH(created_at) as month, COUNT(*) as count') ->where('status', $status) ->whereYear('created_at', now()->year) ->groupBy('month') ->orderBy('month') ->get() ->pluck('count') ->toArray(); } } map(function ($i) { return now()->subMonths($i)->format('M Y'); }); // Reform projects data $reformData = $this->getDataForModel(ReformProject::class, 6); $newsData = $this->getDataForModel(News::class, 6); return [ 'datasets' => [ [ 'label' => 'Reform Projects', 'data' => $reformData, 'backgroundColor' => '#10B981', 'borderColor' => '#047857', 'borderWidth' => 1, ], [ 'label' => 'News Published', 'data' => $newsData, 'backgroundColor' => '#F59E0B', 'borderColor' => '#B45309', 'borderWidth' => 1, ], ], 'labels' => $months, ]; } private function getDataForModel(string $model, int $months): array { $data = []; for ($i = $months - 1; $i >= 0; $i--) { $date = now()->subMonths($i); $count = $model::whereYear('created_at', $date->year) ->whereMonth('created_at', $date->month) ->count(); $data[] = $count; } return $data; } protected function getType(): string { return 'bar'; } }