<?php
namespace App\Http\Controllers;

use App\Models\QuestionTopic;
use App\Models\QuestionBank;
use App\Models\Quiz;
use Illuminate\View\View;

class QuestionBankDashboardController extends Controller
{
    public function index(): View
    {
        $topicCount = QuestionTopic::count();
        $activeTopicCount = QuestionTopic::where('status', 'Đang sử dụng')->count();
        $questionCount = QuestionBank::count();
        $activeQuestionCount = QuestionBank::where('status', 'Đang sử dụng')->count();
        $quizCount = Quiz::count();

        $latestTopics = QuestionTopic::withCount('questions')->latest()->take(5)->get();
        $latestQuestions = QuestionBank::with('topic')->latest()->take(5)->get();

        return view('question_bank.dashboard', compact(
            'topicCount','activeTopicCount','questionCount',
            'activeQuestionCount','quizCount','latestTopics','latestQuestions'
        ));
    }
}
