<?php

declare(strict_types=1);

namespace App\Controllers;

use App\Core\Controller;

/**
 * FAQ Controller
 *
 * Handles the FAQ listing page with questions grouped by category.
 */
class FaqController extends Controller
{
    /**
     * Display all active FAQs grouped by category.
     *
     * @return void
     */
    public function index(): void
    {
        $faqModel = $this->model('Faq');

        // Get all active FAQs
        $faqs = $faqModel->where('active', 1);

        // Group FAQs by category
        $groupedFaqs = [];
        foreach ($faqs as $faq) {
            $category = $faq['category'] ?? 'General';
            if (!isset($groupedFaqs[$category])) {
                $groupedFaqs[$category] = [];
            }
            $groupedFaqs[$category][] = $faq;
        }

        $this->view('faq/index', [
            'title'       => 'Frequently Asked Questions - Gmind Institute',
            'faqs'        => $faqs,
            'groupedFaqs' => $groupedFaqs,
            'currentNav'  => 'faq',
            'currentPage' => 'faq',
        ]);
    }
}
