<?php
/**
 * FAQ Page — Gmind Institute
 *
 * Frequently asked questions with category tabs/filters,
 * accordion items, and a contact CTA at bottom.
 *
 * Expected PHP variables:
 *   $faqs        — array of FAQ records
 *   $categories  — array of FAQ categories
 *   $currentCat  — string current category filter (optional)
 *   $csrfToken   — CSRF token string
 *   $currentPage — string 'faq'
 *   $title       — page title
 */

$faqs       = $faqs       ?? [];
$categories = $categories ?? ['general', 'courses', 'admission', 'exam', 'certificate'];
$currentCat = $currentCat ?? 'all';
$basePath = defined('BASE_PATH') ? BASE_PATH : '/gmind';
include __DIR__ . '/../layouts/header.php';

?>
<!-- ============================================================
     Page Banner
     ============================================================ -->
<section class="page-banner" aria-label="Page heading">
    <div class="container">
        <h1><?= __('faq.page_title') ?></h1>
        <p><?= __('faq.page_subtitle') ?></p>
        <nav class="breadcrumb" aria-label="Breadcrumb">
            <a href="<?= $basePath ?>/"><?= __('nav.home') ?></a>
            <span aria-hidden="true">/</span>
            <span><?= __('faq.page_title') ?></span>
        </nav>
    </div>
</section>

<!-- ============================================================
     FAQ Section
     ============================================================ -->
<section class="faq-page-section section-white" aria-label="FAQs">
    <div class="container">
        <!-- Category Tabs -->
        <div class="course-filters faq-category-filters" role="tablist" aria-label="Filter FAQs by category">
            <a href="<?= $basePath ?>/faq" class="course-filter-btn<?= $currentCat === 'all' ? ' active' : '' ?>" role="tab" aria-selected="<?= $currentCat === 'all' ? 'true' : 'false' ?>"><?= __('courses.filter_all') ?></a>
            <?php foreach ($categories as $cat): ?>
            <a href="<?= $basePath ?>/faq?category=<?= htmlspecialchars($cat, ENT_QUOTES, 'UTF-8') ?>" class="course-filter-btn<?= $currentCat === $cat ? ' active' : '' ?>" role="tab" aria-selected="<?= $currentCat === $cat ? 'true' : 'false' ?>">
                <?= htmlspecialchars(ucfirst($cat), ENT_QUOTES, 'UTF-8') ?>
            </a>
            <?php endforeach; ?>
        </div>

        <!-- FAQ Accordion -->
        <div class="faq-list faq-page-list">
            <?php if (!empty($faqs)): ?>
                <?php foreach ($faqs as $faq): ?>
                <details class="faq-item">
                    <summary>
                        <?= htmlspecialchars(getBilingual($faq, 'question') ?: __('faq.question_default'), ENT_QUOTES, 'UTF-8') ?>
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        <?= htmlspecialchars(getBilingual($faq, 'answer'), ENT_QUOTES, 'UTF-8') ?>
                    </div>
                </details>
                <?php endforeach; ?>
            <?php else: ?>
                <!-- Fallback FAQs -->
                <details class="faq-item" open>
                    <summary>
                        <?= __('faq.fallback_q1') ?>
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        <?= __('faq.fallback_a1') ?>
                    </div>
                </details>
                <details class="faq-item">
                    <summary>
                        <?= __('faq.fallback_q2') ?>
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        <?= __('faq.fallback_a2') ?>
                    </div>
                </details>
                <details class="faq-item">
                    <summary>
                        <?= __('faq.fallback_q3') ?>
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        <?= __('faq.fallback_a3') ?>
                    </div>
                </details>
                <details class="faq-item">
                    <summary>
                        <?= __('faq.fallback_q4') ?>
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        <?= __('faq.fallback_a4') ?>
                    </div>
                </details>
                <details class="faq-item">
                    <summary>
                        <?= __('faq.fallback_q5') ?>
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        <?= __('faq.fallback_a5') ?>
                    </div>
                </details>
                <details class="faq-item">
                    <summary>
                        <?= __('faq.fallback_q6') ?>
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        <?= __('faq.fallback_a6') ?>
                    </div>
                </details>
            <?php endif; ?>
        </div>
    </div>
</section>

<!-- ============================================================
     Contact CTA Section
     ============================================================ -->
<section class="faq-cta-section section-navy" aria-label="Still have questions">
    <div class="container">
        <div class="faq-cta-content">
            <h2><?= __('faq.still_questions') ?></h2>
            <p><?= __('faq.still_questions_desc') ?></p>
            <div class="faq-cta-buttons">
                <a href="<?= $basePath ?>/contact" class="btn-primary" style="background-color:#ffffff;color:#1a4fa0;"><?= __('nav.contact') ?></a>
                <a href="tel:9305640290" class="btn-outline-white">
                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07 19.5 19.5 0 01-6-6 19.79 19.79 0 01-3.07-8.67A2 2 0 014.11 2h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L8.09 9.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45c.907.339 1.85.573 2.81.7A2 2 0 0122 16.92z"/></svg>
                    <?= __('faq.call') ?>: 9305640290
                </a>
            </div>
        </div>
    </div>
</section>

<?php include __DIR__ . '/../layouts/footer.php'; ?>
