class Admin::DashboardController < Admin::BaseController
  def index
    @user_count = User.count
    @contributor_count = User.contributor.count
    @reviewer_count = User.reviewer.count
    @admin_count = User.admin.count

    @entry_count = Entry.count
    @verified_count = Entry.where(verified: true).count
    @unverified_count = @entry_count - @verified_count

    @pending_suggestions_count = SuggestedMeaning.pending.count
    @accepted_suggestions_count = SuggestedMeaning.accepted.count
    @rejected_suggestions_count = SuggestedMeaning.rejected.count

    @comment_count = Comment.count

    @recent_users = User.order(created_at: :desc).limit(5)
    @recent_entries = Entry.order(created_at: :desc).limit(5)
    @pending_invitations = User.where.not(invitation_token: nil)
                                 .where(invitation_accepted_at: nil)
                                 .where("invitation_sent_at > ?", 14.days.ago)
                                 .count

    @supported_languages = SupportedLanguage.where(active: true).order(:sort_order)
    @language_completion = @supported_languages.index_with do |language|
      next 0 if @entry_count.zero?

      (Entry.where.not(language.code => [ nil, "" ]).count * 100.0 / @entry_count).round
    end
  end
end
