<?php
/**
 * Home Page — Gmind Institute
 *
 * Main landing page with all sections: hero slider, announcements,
 * stats counter, courses, why choose us, branches, affiliations,
 * toppers, news, FAQs, and testimonials.
 *
 * PHP variables available (passed from HomeController):
 *   $sliders         — array of slider records
 *   $announcements   — array of announcement records
 *   $featuredCourses — array of featured course records
 *   $branches        — array of branch records
 *   $affiliations    — array of affiliation records
 *   $partners        — array of partner records
 *   $toppers         — array of topper records
 *   $branchNews      — array of branch_news records
 *   $faqs            — array of faq records
 *   $testimonials    — array of testimonial records
 *   $avgRating       — float average rating
 *   $stats           — array with keys: total_students, total_courses, total_branches, years_experience
 *   $settings        — key-value pairs from settings table
 *   $csrfToken       — CSRF token string
 *   $currentPage     — string 'home'
 */

// Provide safe defaults for stats
$statStudents = (int) ($stats['total_students']   ?? 5000);
$statCourses  = (int) ($stats['total_courses']     ?? 30);
$statBranches = (int) ($stats['total_branches']     ?? 15);
$statYears    = (int) ($stats['years_experience']   ?? 10);

// Ensure arrays are set
$sliders         = $sliders         ?? [];
$announcements   = $announcements   ?? [];
$featuredCourses = $featuredCourses ?? [];
$branches        = $branches        ?? [];
$affiliations    = $affiliations    ?? [];
$partners        = $partners        ?? [];
$toppers         = $toppers         ?? [];
$branchNews      = $branchNews      ?? [];
$faqs            = $faqs            ?? [];
$testimonials    = $testimonials    ?? [];
?>

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

<!-- ============================================================
     1. Hero Slider Section
     ============================================================ -->
<section class="hero-slider" aria-label="Featured highlights">
    <?php if (!empty($sliders)): ?>
        <?php foreach ($sliders as $index => $slider): ?>
        <div class="hero-slide<?= $index === 0 ? ' active' : '' ?>">
            <img
                class="hero-slide-image"
                src="<?= htmlspecialchars($slider['image'] ?? '/images/slider-default.jpg', ENT_QUOTES, 'UTF-8') ?>"
                alt="<?= htmlspecialchars($slider['title'] ?? 'Gmind Institute', ENT_QUOTES, 'UTF-8') ?>"
                loading="<?= $index === 0 ? 'eager' : 'lazy' ?>"
            >
            <div class="hero-slide-overlay"></div>
            <div class="hero-slide-content">
                <h1><?= htmlspecialchars($slider['title'] ?? 'Build Your Career in IT', ENT_QUOTES, 'UTF-8') ?></h1>
                <p><?= htmlspecialchars($slider['subtitle'] ?? 'Join Gmind Institute for industry-oriented computer courses with government-recognised certifications.', ENT_QUOTES, 'UTF-8') ?></p>
                <div class="hero-slide-cta">
                    <a href="<?= url('/courses') ?>" class="btn-primary">Explore Courses</a>
                    <a href="<?= url('/admission') ?>" class="btn-outline-white">Apply Now</a>
                </div>
            </div>
        </div>
        <?php endforeach; ?>
    <?php else: ?>
        <!-- Fallback slide when no sliders exist -->
        <div class="hero-slide active">
            <img class="hero-slide-image" src="<?= asset('/images/slider-default.jpg') ?>" alt="Gmind Institute" loading="eager">
            <div class="hero-slide-overlay"></div>
            <div class="hero-slide-content">
                <h1>Build Your Career in IT</h1>
                <p>Join Gmind Institute for industry-oriented computer courses with government-recognised certifications and 100% job placement assistance.</p>
                <div class="hero-slide-cta">
                    <a href="<?= url('/courses') ?>" class="btn-primary">Explore Courses</a>
                    <a href="<?= url('/admission') ?>" class="btn-outline-white">Apply Now</a>
                </div>
            </div>
        </div>
    <?php endif; ?>

    <!-- Dot Indicators -->
    <?php if (count($sliders) > 1): ?>
    <div class="hero-dots" aria-label="Slider navigation">
        <?php foreach ($sliders as $index => $slider): ?>
        <span class="hero-dot<?= $index === 0 ? ' active' : '' ?>" data-slide="<?= $index ?>"></span>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>

    <!-- Prev / Next Arrows -->
    <?php if (count($sliders) > 1): ?>
    <button class="hero-arrow hero-arrow-prev" aria-label="Previous slide">
        <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="15 18 9 12 15 6"/></svg>
    </button>
    <button class="hero-arrow hero-arrow-next" aria-label="Next slide">
        <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="9 18 15 12 9 6"/></svg>
    </button>
    <?php endif; ?>
</section>

<!-- ============================================================
     2. Announcement Marquee
     ============================================================ -->
<?php if (!empty($announcements)): ?>
<div class="announcement-bar" role="marquee" aria-label="Latest announcements">
    <div class="container">
        <span class="announcement-label">Latest News:</span>
        <div class="announcement-scroll">
            <?php foreach ($announcements as $announcement): ?>
                <span>
                    <?php if (!empty($announcement['link'])): ?>
                        <a href="<?= htmlspecialchars($announcement['link'], ENT_QUOTES, 'UTF-8') ?>" style="color:inherit;">
                            <?= htmlspecialchars($announcement['text'], ENT_QUOTES, 'UTF-8') ?>
                        </a>
                    <?php else: ?>
                        <?= htmlspecialchars($announcement['text'], ENT_QUOTES, 'UTF-8') ?>
                    <?php endif; ?>
                </span>
            <?php endforeach; ?>
        </div>
    </div>
</div>
<?php endif; ?>

<!-- ============================================================
     3. Stats Counter Section
     ============================================================ -->
<section class="stats-section" aria-label="Institute statistics">
    <div class="container">
        <div class="stats-grid">
            <div class="stat-item animate-on-scroll">
                <span class="stat-number" data-target="<?= $statStudents ?>">0</span>
                <span class="stat-label">Students Enrolled</span>
            </div>
            <div class="stat-item animate-on-scroll" data-delay="100">
                <span class="stat-number" data-target="<?= $statCourses ?>">0</span>
                <span class="stat-label">Courses Available</span>
            </div>
            <div class="stat-item animate-on-scroll" data-delay="200">
                <span class="stat-number" data-target="<?= $statBranches ?>">0</span>
                <span class="stat-label">Branches</span>
            </div>
            <div class="stat-item animate-on-scroll" data-delay="300">
                <span class="stat-number" data-target="<?= $statYears ?>">0</span>
                <span class="stat-label">Years of Excellence</span>
            </div>
        </div>
    </div>
</section>

<!-- ============================================================
     4. Popular Courses Section
     ============================================================ -->
<section class="courses-section" id="courses" aria-label="Popular courses">
    <div class="container">
        <div class="section-heading">
            <h2>Our Popular Courses</h2>
            <p>Explore our wide range of industry-recognised computer courses designed to boost your career</p>
        </div>

        <!-- Filter Tabs -->
        <div class="course-filters" role="tablist" aria-label="Filter courses by category">
            <button class="course-filter-btn active" data-category="all" role="tab" aria-selected="true">All</button>
            <button class="course-filter-btn" data-category="computer" role="tab" aria-selected="false">Computer</button>
            <button class="course-filter-btn" data-category="accounting" role="tab" aria-selected="false">Accounting</button>
            <button class="course-filter-btn" data-category="programming" role="tab" aria-selected="false">Programming</button>
            <button class="course-filter-btn" data-category="design" role="tab" aria-selected="false">Design</button>
        </div>

        <!-- Course Cards Grid -->
        <div class="courses-grid">
            <?php if (!empty($featuredCourses)): ?>
                <?php foreach ($featuredCourses as $course): ?>
                <div class="course-card animate-on-scroll" data-category="<?= htmlspecialchars($course['category'] ?? 'computer', ENT_QUOTES, 'UTF-8') ?>">
                    <div class="course-card-image">
                        <img
                            src="<?= htmlspecialchars($course['image'] ?? '/images/course-default.jpg', ENT_QUOTES, 'UTF-8') ?>"
                            alt="<?= htmlspecialchars($course['name'] ?? 'Course', ENT_QUOTES, 'UTF-8') ?>"
                            data-src="<?= htmlspecialchars($course['image'] ?? '/images/course-default.jpg', ENT_QUOTES, 'UTF-8') ?>"
                            loading="lazy"
                        >
                        <span class="course-card-badge badge-<?= htmlspecialchars($course['category'] ?? 'computer', ENT_QUOTES, 'UTF-8') ?>">
                            <?= htmlspecialchars(ucfirst($course['category'] ?? 'Course'), ENT_QUOTES, 'UTF-8') ?>
                        </span>
                    </div>
                    <div class="course-card-body">
                        <h3 class="course-card-title"><?= htmlspecialchars($course['name'] ?? 'Course', ENT_QUOTES, 'UTF-8') ?></h3>
                        <div class="course-card-meta">
                            <span>
                                <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
                                <?= htmlspecialchars($course['duration'] ?? 'N/A', ENT_QUOTES, 'UTF-8') ?>
                            </span>
                            <span class="fee">
                                <?php
                                    $fee = (float) ($course['fee'] ?? 0);
                                    echo $fee > 0 ? '₹' . number_format($fee, 0) : 'Contact Us';
                                ?>
                            </span>
                        </div>
                        <a href="<?= url('/courses/' . $course['id'] ?? '#') ?>" class="btn-enroll">Enroll Now</a>
                    </div>
                </div>
                <?php endforeach; ?>
            <?php else: ?>
                <!-- Fallback course cards when no courses exist -->
                <?php
                $fallbackCourses = [
                    ['name' => 'ADCA', 'category' => 'computer', 'duration' => '12 Months', 'fee' => 25000],
                    ['name' => 'DCA', 'category' => 'computer', 'duration' => '6 Months', 'fee' => 15000],
                    ['name' => 'Tally Prime', 'category' => 'accounting', 'duration' => '3 Months', 'fee' => 8000],
                    ['name' => 'Python Programming', 'category' => 'programming', 'duration' => '6 Months', 'fee' => 20000],
                    ['name' => 'Web Design', 'category' => 'design', 'duration' => '6 Months', 'fee' => 18000],
                    ['name' => 'Graphic Design', 'category' => 'design', 'duration' => '4 Months', 'fee' => 12000],
                ];
                ?>
                <?php foreach ($fallbackCourses as $fc): ?>
                <div class="course-card animate-on-scroll" data-category="<?= $fc['category'] ?>">
                    <div class="course-card-image">
                        <img src="<?= asset('/images/course-default.jpg') ?>" alt="<?= $fc['name'] ?>" loading="lazy">
                        <span class="course-card-badge badge-<?= $fc['category'] ?>"><?= ucfirst($fc['category']) ?></span>
                    </div>
                    <div class="course-card-body">
                        <h3 class="course-card-title"><?= $fc['name'] ?></h3>
                        <div class="course-card-meta">
                            <span>
                                <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
                                <?= $fc['duration'] ?>
                            </span>
                            <span class="fee">₹<?= number_format($fc['fee'], 0) ?></span>
                        </div>
                        <a href="<?= url('/admission') ?>" class="btn-enroll">Enroll Now</a>
                    </div>
                </div>
                <?php endforeach; ?>
            <?php endif; ?>
        </div>
    </div>
</section>

<!-- ============================================================
     5. Why Choose Us Section
     ============================================================ -->
<section class="why-choose-section" aria-label="Why choose Gmind Institute">
    <div class="container">
        <div class="section-heading">
            <h2>Why Choose Gmind Institute?</h2>
            <p>We are committed to providing quality education and career opportunities for every student</p>
        </div>

        <div class="why-choose-grid">
            <!-- 1. Experienced Faculty -->
            <div class="why-choose-item animate-on-scroll">
                <div class="why-choose-icon icon-navy" aria-hidden="true">
                    <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 00-3-3.87"/><path d="M16 3.13a4 4 0 010 7.75"/></svg>
                </div>
                <h3 class="why-choose-title">Experienced Faculty</h3>
                <p class="why-choose-desc">Learn from industry veterans with years of real-world expertise in computer science, accounting, and design.</p>
            </div>

            <!-- 2. Government Recognised -->
            <div class="why-choose-item animate-on-scroll" data-delay="100">
                <div class="why-choose-icon icon-scarlet" aria-hidden="true">
                    <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
                </div>
                <h3 class="why-choose-title">Government Recognised</h3>
                <p class="why-choose-desc">All our courses are government-recognised, ensuring your certification holds value across India and beyond.</p>
            </div>

            <!-- 3. Job Placement Assistance -->
            <div class="why-choose-item animate-on-scroll" data-delay="200">
                <div class="why-choose-icon icon-gold" aria-hidden="true">
                    <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="7" width="20" height="14" rx="2" ry="2"/><path d="M16 21V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v16"/></svg>
                </div>
                <h3 class="why-choose-title">Job Placement Assistance</h3>
                <p class="why-choose-desc">Get dedicated career support with resume building, interview preparation, and direct placement opportunities.</p>
            </div>

            <!-- 4. Online Exam System -->
            <div class="why-choose-item animate-on-scroll" data-delay="300">
                <div class="why-choose-icon icon-navy" aria-hidden="true">
                    <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="20" height="14" rx="2" ry="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>
                </div>
                <h3 class="why-choose-title">Online Exam System</h3>
                <p class="why-choose-desc">Practise and appear for exams online with our advanced digital examination platform — anytime, anywhere.</p>
            </div>

            <!-- 5. Digital Certificate -->
            <div class="why-choose-item animate-on-scroll" data-delay="400">
                <div class="why-choose-icon icon-scarlet" aria-hidden="true">
                    <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>
                </div>
                <h3 class="why-choose-title">Digital Certificate</h3>
                <p class="why-choose-desc">Receive verifiable digital certificates upon course completion — shareable on LinkedIn and with employers.</p>
            </div>

            <!-- 6. 24×7 Support -->
            <div class="why-choose-item animate-on-scroll" data-delay="500">
                <div class="why-choose-icon icon-gold" aria-hidden="true">
                    <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></svg>
                </div>
                <h3 class="why-choose-title">24×7 Support</h3>
                <p class="why-choose-desc">Our dedicated support team is available around the clock to assist you with any queries or technical issues.</p>
            </div>
        </div>
    </div>
</section>

<!-- ============================================================
     6. Latest Branches Section
     ============================================================ -->
<section class="branches-section" aria-label="Our branches">
    <div class="container">
        <div class="section-heading">
            <h2>Our Growing Network</h2>
            <p>Find a Gmind Institute branch near you across India</p>
        </div>

        <div class="branches-grid">
            <?php if (!empty($branches)): ?>
                <?php foreach ($branches as $branch): ?>
                <div class="branch-card animate-on-scroll">
                    <div class="branch-card-image">
                        <img
                            src="<?= htmlspecialchars($branch['image'] ?? '/images/branch-default.jpg', ENT_QUOTES, 'UTF-8') ?>"
                            alt="<?= htmlspecialchars($branch['city'] ?? 'Branch', ENT_QUOTES, 'UTF-8') ?>"
                            data-src="<?= htmlspecialchars($branch['image'] ?? '/images/branch-default.jpg', ENT_QUOTES, 'UTF-8') ?>"
                            loading="lazy"
                        >
                    </div>
                    <div class="branch-card-body">
                        <h3 class="branch-card-city"><?= htmlspecialchars($branch['city'] ?? $branch['name'] ?? 'City', ENT_QUOTES, 'UTF-8') ?></h3>
                        <div class="branch-card-state"><?= htmlspecialchars($branch['state'] ?? '', ENT_QUOTES, 'UTF-8') ?></div>
                        <div class="branch-card-address">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0118 0z"/><circle cx="12" cy="10" r="3"/></svg>
                            <?= htmlspecialchars($branch['address'] ?? '', ENT_QUOTES, 'UTF-8') ?>
                        </div>
                        <?php if (!empty($branch['phone'])): ?>
                        <div class="branch-card-phone">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" 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>
                            <a href="tel:<?= htmlspecialchars($branch['phone'], ENT_QUOTES, 'UTF-8') ?>"><?= htmlspecialchars($branch['phone'], ENT_QUOTES, 'UTF-8') ?></a>
                        </div>
                        <?php endif; ?>
                        <?php if (!empty($branch['map_link'])): ?>
                        <a href="<?= htmlspecialchars($branch['map_link'], ENT_QUOTES, 'UTF-8') ?>" target="_blank" rel="noopener noreferrer" class="branch-card-map">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polygon points="1 6 1 22 8 18 16 22 23 18 23 2 16 6 8 2 1 6"/><line x1="8" y1="2" x2="8" y2="18"/><line x1="16" y1="6" x2="16" y2="22"/></svg>
                            View on Map
                        </a>
                        <?php endif; ?>
                    </div>
                </div>
                <?php endforeach; ?>
            <?php else: ?>
                <!-- Fallback branch cards -->
                <?php
                $fallbackBranches = [
                    ['city' => 'New Delhi', 'state' => 'Delhi', 'address' => '123 Education Street, New Delhi', 'phone' => '9305640290'],
                    ['city' => 'Mumbai', 'state' => 'Maharashtra', 'address' => '45 Tech Park, Andheri West', 'phone' => '9305640291'],
                    ['city' => 'Jaipur', 'state' => 'Rajasthan', 'address' => '78 Knowledge Hub, Malviya Nagar', 'phone' => '9305640292'],
                    ['city' => 'Lucknow', 'state' => 'Uttar Pradesh', 'address' => '22 IT Lane, Gomti Nagar', 'phone' => '9305640293'],
                ];
                ?>
                <?php foreach ($fallbackBranches as $fb): ?>
                <div class="branch-card animate-on-scroll">
                    <div class="branch-card-image">
                        <img src="<?= asset('/images/branch-default.jpg') ?>" alt="<?= $fb['city'] ?>" loading="lazy">
                    </div>
                    <div class="branch-card-body">
                        <h3 class="branch-card-city"><?= $fb['city'] ?></h3>
                        <div class="branch-card-state"><?= $fb['state'] ?></div>
                        <div class="branch-card-address">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0118 0z"/><circle cx="12" cy="10" r="3"/></svg>
                            <?= $fb['address'] ?>
                        </div>
                        <div class="branch-card-phone">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" 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>
                            <a href="tel:<?= $fb['phone'] ?>"><?= $fb['phone'] ?></a>
                        </div>
                    </div>
                </div>
                <?php endforeach; ?>
            <?php endif; ?>
        </div>

        <div class="branches-view-all">
            <a href="<?= url('/branches') ?>" class="btn-outline">View All Branches</a>
        </div>
    </div>
</section>

<!-- ============================================================
     7. Affiliation & Partners Section
     ============================================================ -->
<?php if (!empty($affiliations) || !empty($partners)): ?>
<section class="affiliations-section" aria-label="Affiliations and partners">
    <div class="container">
        <!-- Affiliations -->
        <?php if (!empty($affiliations)): ?>
        <div class="affiliations-subsection">
            <h3>Affiliated With</h3>
            <div class="logo-strip-wrapper">
                <div class="logo-strip">
                    <?php
                    // Duplicate logos for seamless infinite scroll
                    $affLoop = array_merge($affiliations, $affiliations);
                    ?>
                    <?php foreach ($affLoop as $aff): ?>
                    <div class="logo-strip-item">
                        <?php if (!empty($aff['website'])): ?>
                        <a href="<?= htmlspecialchars($aff['website'], ENT_QUOTES, 'UTF-8') ?>" target="_blank" rel="noopener noreferrer" aria-label="<?= htmlspecialchars($aff['name'] ?? 'Affiliate', ENT_QUOTES, 'UTF-8') ?>">
                        <?php endif; ?>
                            <img
                                src="<?= htmlspecialchars($aff['logo'] ?? '/images/logo-placeholder.png', ENT_QUOTES, 'UTF-8') ?>"
                                alt="<?= htmlspecialchars($aff['name'] ?? 'Affiliate', ENT_QUOTES, 'UTF-8') ?>"
                                loading="lazy"
                            >
                        <?php if (!empty($aff['website'])): ?>
                        </a>
                        <?php endif; ?>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php endif; ?>

        <!-- Placement Partners -->
        <?php if (!empty($partners)): ?>
        <div class="affiliations-subsection">
            <h3>Our Placement Partners</h3>
            <div class="logo-strip-wrapper">
                <div class="logo-strip">
                    <?php
                    $partLoop = array_merge($partners, $partners);
                    ?>
                    <?php foreach ($partLoop as $partner): ?>
                    <div class="logo-strip-item">
                        <?php if (!empty($partner['website'])): ?>
                        <a href="<?= htmlspecialchars($partner['website'], ENT_QUOTES, 'UTF-8') ?>" target="_blank" rel="noopener noreferrer" aria-label="<?= htmlspecialchars($partner['name'] ?? 'Partner', ENT_QUOTES, 'UTF-8') ?>">
                        <?php endif; ?>
                            <img
                                src="<?= htmlspecialchars($partner['logo'] ?? '/images/logo-placeholder.png', ENT_QUOTES, 'UTF-8') ?>"
                                alt="<?= htmlspecialchars($partner['name'] ?? 'Partner', ENT_QUOTES, 'UTF-8') ?>"
                                loading="lazy"
                            >
                        <?php if (!empty($partner['website'])): ?>
                        </a>
                        <?php endif; ?>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php endif; ?>
    </div>
</section>
<?php endif; ?>

<!-- ============================================================
     8. Toppers Section
     ============================================================ -->
<section class="toppers-section section-navy" aria-label="Star performers">
    <div class="container">
        <div class="section-heading">
            <h2>Our Star Performers</h2>
            <p>Celebrating the achievements of our outstanding students</p>
        </div>

        <div class="toppers-grid">
            <?php if (!empty($toppers)): ?>
                <?php foreach ($toppers as $index => $topper): ?>
                    <?php
                    $rankClass = '';
                    if ($index === 0) $rankClass = 'rank-1';
                    elseif ($index === 1) $rankClass = 'rank-2';
                    elseif ($index === 2) $rankClass = 'rank-3';
                    ?>
                <div class="topper-card <?= $rankClass ?> animate-on-scroll">
                    <img
                        class="topper-photo"
                        src="<?= htmlspecialchars($topper['photo'] ?? '/images/avatar-default.png', ENT_QUOTES, 'UTF-8') ?>"
                        alt="<?= htmlspecialchars($topper['name'] ?? 'Student', ENT_QUOTES, 'UTF-8') ?>"
                        data-src="<?= htmlspecialchars($topper['photo'] ?? '/images/avatar-default.png', ENT_QUOTES, 'UTF-8') ?>"
                        loading="lazy"
                    >
                    <div class="topper-name"><?= htmlspecialchars($topper['name'] ?? 'Student', ENT_QUOTES, 'UTF-8') ?></div>
                    <div class="topper-course"><?= htmlspecialchars($topper['course_name'] ?? $topper['course_id'] ?? '', ENT_QUOTES, 'UTF-8') ?></div>
                    <?php if (!empty($topper['marks']) || !empty($topper['grade'])): ?>
                    <div class="topper-marks">
                        <?= htmlspecialchars($topper['marks'] ?? $topper['grade'] ?? '', ENT_QUOTES, 'UTF-8') ?>
                    </div>
                    <?php endif; ?>
                    <div class="topper-meta">
                        <?php if (!empty($topper['batch_year'])): ?>
                            <?= htmlspecialchars((string) $topper['batch_year'], ENT_QUOTES, 'UTF-8') ?>
                        <?php endif; ?>
                        <?php if (!empty($topper['branch_name'])): ?>
                            &bull; <?= htmlspecialchars($topper['branch_name'], ENT_QUOTES, 'UTF-8') ?>
                        <?php endif; ?>
                    </div>
                </div>
                <?php endforeach; ?>
            <?php else: ?>
                <!-- Fallback toppers -->
                <?php
                $fallbackToppers = [
                    ['name' => 'Amit Kumar', 'course' => 'ADCA', 'marks' => '95%', 'year' => '2025', 'branch' => 'New Delhi'],
                    ['name' => 'Priya Sharma', 'course' => 'DCA', 'marks' => '93%', 'year' => '2025', 'branch' => 'Mumbai'],
                    ['name' => 'Rahul Verma', 'course' => 'Python', 'marks' => '91%', 'year' => '2025', 'branch' => 'Jaipur'],
                    ['name' => 'Sneha Patel', 'course' => 'Web Design', 'marks' => '89%', 'year' => '2025', 'branch' => 'Lucknow'],
                ];
                ?>
                <?php foreach ($fallbackToppers as $fti => $ft): ?>
                    <?php
                    $rankClass = '';
                    if ($fti === 0) $rankClass = 'rank-1';
                    elseif ($fti === 1) $rankClass = 'rank-2';
                    elseif ($fti === 2) $rankClass = 'rank-3';
                    ?>
                <div class="topper-card <?= $rankClass ?>">
                    <img class="topper-photo" src="<?= asset('/images/avatar-default.png') ?>" alt="<?= $ft['name'] ?>" loading="lazy">
                    <div class="topper-name"><?= $ft['name'] ?></div>
                    <div class="topper-course"><?= $ft['course'] ?></div>
                    <div class="topper-marks"><?= $ft['marks'] ?></div>
                    <div class="topper-meta"><?= $ft['year'] ?> &bull; <?= $ft['branch'] ?></div>
                </div>
                <?php endforeach; ?>
            <?php endif; ?>
        </div>

        <div style="text-align:center; margin-top:2rem;">
            <a href="<?= url('/toppers') ?>" style="color:#f39c12; font-weight:600; font-size:0.9rem;">View All &rarr;</a>
        </div>
    </div>
</section>

<!-- ============================================================
     9. Branch News Section
     ============================================================ -->
<section class="branch-news-section" aria-label="Branch news">
    <div class="container">
        <div class="section-heading">
            <h2>Branch Updates &amp; News</h2>
            <p>Stay informed with the latest happenings at our branches</p>
        </div>

        <div class="news-grid">
            <?php if (!empty($branchNews)): ?>
                <?php foreach ($branchNews as $news): ?>
                <div class="news-card animate-on-scroll">
                    <div class="news-card-image">
                        <img
                            src="<?= htmlspecialchars($news['image'] ?? '/images/news-default.jpg', ENT_QUOTES, 'UTF-8') ?>"
                            alt="<?= htmlspecialchars($news['title'] ?? 'News', ENT_QUOTES, 'UTF-8') ?>"
                            data-src="<?= htmlspecialchars($news['image'] ?? '/images/news-default.jpg', ENT_QUOTES, 'UTF-8') ?>"
                            loading="lazy"
                        >
                    </div>
                    <div class="news-card-body">
                        <div class="news-card-meta">
                            <span class="news-card-date">
                                <?= htmlspecialchars(date('M d, Y', strtotime($news['published_at'] ?? $news['created_at'] ?? 'now')), ENT_QUOTES, 'UTF-8') ?>
                            </span>
                            <?php if (!empty($news['branch_name'])): ?>
                            <span class="news-card-branch-badge"><?= htmlspecialchars($news['branch_name'], ENT_QUOTES, 'UTF-8') ?></span>
                            <?php endif; ?>
                        </div>
                        <h3 class="news-card-title"><?= htmlspecialchars($news['title'] ?? 'News Update', ENT_QUOTES, 'UTF-8') ?></h3>
                        <p class="news-card-excerpt">
                            <?= htmlspecialchars(mb_substr($news['content'] ?? '', 0, 150), ENT_QUOTES, 'UTF-8') ?><?= mb_strlen($news['content'] ?? '') > 150 ? '...' : '' ?>
                        </p>
                        <a href="<?= url('/news/' . $news['slug'] ?? '#') ?>" class="news-card-link">
                            Read More
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>
                        </a>
                    </div>
                </div>
                <?php endforeach; ?>
            <?php else: ?>
                <!-- Fallback news cards -->
                <?php
                $fallbackNews = [
                    ['title' => 'New Branch Opening in Pune', 'date' => 'Feb 28, 2026', 'branch' => 'Pune', 'excerpt' => 'We are excited to announce the opening of our new branch in Pune, bringing quality computer education to more students across Maharashtra.'],
                    ['title' => 'ADCA Course Now Available Online', 'date' => 'Feb 15, 2026', 'branch' => 'New Delhi', 'excerpt' => 'Our flagship ADCA course is now available in online mode, allowing students to learn from anywhere in India at their own pace.'],
                    ['title' => 'Annual Job Fair 2026', 'date' => 'Jan 20, 2026', 'branch' => 'Mumbai', 'excerpt' => 'Join our annual job fair with top companies hiring for IT, accounting, and design positions. Register now to secure your spot.'],
                ];
                ?>
                <?php foreach ($fallbackNews as $fn): ?>
                <div class="news-card animate-on-scroll">
                    <div class="news-card-image">
                        <img src="<?= asset('/images/news-default.jpg') ?>" alt="<?= $fn['title'] ?>" loading="lazy">
                    </div>
                    <div class="news-card-body">
                        <div class="news-card-meta">
                            <span class="news-card-date"><?= $fn['date'] ?></span>
                            <span class="news-card-branch-badge"><?= $fn['branch'] ?></span>
                        </div>
                        <h3 class="news-card-title"><?= $fn['title'] ?></h3>
                        <p class="news-card-excerpt"><?= $fn['excerpt'] ?></p>
                        <a href="<?= url('/news') ?>" class="news-card-link">
                            Read More
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>
                        </a>
                    </div>
                </div>
                <?php endforeach; ?>
            <?php endif; ?>
        </div>

        <div class="news-view-all">
            <a href="<?= url('/news') ?>" class="btn-outline">View All News</a>
        </div>
    </div>
</section>

<!-- ============================================================
     10. FAQ Accordion Section
     ============================================================ -->
<section class="faq-section" aria-label="Frequently asked questions">
    <div class="container">
        <div class="section-heading">
            <h2>Frequently Asked Questions</h2>
            <p>Find answers to common queries about our courses, admissions, and more</p>
        </div>

        <div class="faq-list">
            <?php if (!empty($faqs)): ?>
                <?php foreach ($faqs as $faq): ?>
                <details class="faq-item">
                    <summary>
                        <?= htmlspecialchars($faq['question'] ?? 'Question', ENT_QUOTES, 'UTF-8') ?>
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        <?= htmlspecialchars($faq['answer'] ?? '', ENT_QUOTES, 'UTF-8') ?>
                    </div>
                </details>
                <?php endforeach; ?>
            <?php else: ?>
                <!-- Fallback FAQs -->
                <details class="faq-item" open>
                    <summary>
                        How do I enroll in a course at Gmind Institute?
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        You can enroll online through our Admission page or visit your nearest Gmind Institute branch. Our counsellors will guide you through the course selection and enrollment process.
                    </div>
                </details>
                <details class="faq-item">
                    <summary>
                        Are the courses government-recognised?
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        Yes, all courses offered by Gmind Institute are government-recognised. Upon successful completion, you receive a valid certification that is accepted across India.
                    </div>
                </details>
                <details class="faq-item">
                    <summary>
                        Do you provide job placement after course completion?
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        Absolutely! We have a dedicated placement cell that assists students with resume building, interview preparation, and connecting with hiring partners. Many of our students are placed within 3 months of completing their course.
                    </div>
                </details>
                <details class="faq-item">
                    <summary>
                        Can I appear for exams online?
                        <span class="faq-chevron" aria-hidden="true"></span>
                    </summary>
                    <div class="faq-answer">
                        Yes, Gmind Institute offers an online examination system. You can practise mock tests and appear for final exams from the comfort of your home using our secure digital platform.
                    </div>
                </details>
            <?php endif; ?>
        </div>

        <div style="text-align:center; margin-top:2rem;">
            <a href="<?= url('/faq') ?>" style="color:#1a4fa0; font-weight:600; font-size:0.9rem;">View All FAQs &rarr;</a>
        </div>
    </div>
</section>

<!-- ============================================================
     11. Testimonials Section
     ============================================================ -->
<section class="testimonials-section" aria-label="Student testimonials">
    <div class="container">
        <div class="section-heading">
            <h2>What Our Students Say</h2>
            <p>Hear from our alumni about their learning experience at Gmind Institute</p>
        </div>

        <div class="testimonials-wrapper">
            <div class="testimonials-track">
                <?php if (!empty($testimonials)): ?>
                    <?php foreach ($testimonials as $testimonial): ?>
                        <?php $rating = (int) ($testimonial['rating'] ?? 5); ?>
                    <div class="testimonial-card">
                        <div class="testimonial-card-inner">
                            <div class="testimonial-stars" aria-label="Rating: <?= $rating ?> out of 5">
                                <?php for ($i = 1; $i <= 5; $i++): ?>
                                <span class="star<?= $i > $rating ? ' empty' : '' ?>">&#9733;</span>
                                <?php endfor; ?>
                            </div>
                            <p class="testimonial-text"><?= htmlspecialchars($testimonial['review'] ?? 'Great experience at Gmind Institute!', ENT_QUOTES, 'UTF-8') ?></p>
                            <div class="testimonial-author">
                                <img
                                    class="testimonial-avatar"
                                    src="<?= htmlspecialchars($testimonial['photo'] ?? '/images/avatar-default.png', ENT_QUOTES, 'UTF-8') ?>"
                                    alt="<?= htmlspecialchars($testimonial['name'] ?? 'Student', ENT_QUOTES, 'UTF-8') ?>"
                                    data-src="<?= htmlspecialchars($testimonial['photo'] ?? '/images/avatar-default.png', ENT_QUOTES, 'UTF-8') ?>"
                                    loading="lazy"
                                >
                                <div class="testimonial-author-info">
                                    <span class="testimonial-author-name"><?= htmlspecialchars($testimonial['name'] ?? 'Student', ENT_QUOTES, 'UTF-8') ?></span>
                                    <span class="testimonial-author-course"><?= htmlspecialchars($testimonial['course_name'] ?? '', ENT_QUOTES, 'UTF-8') ?></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php endforeach; ?>
                <?php else: ?>
                    <!-- Fallback testimonials -->
                    <?php
                    $fallbackTestimonials = [
                        ['name' => 'Ravi Kumar', 'course' => 'ADCA', 'rating' => 5, 'review' => 'Gmind Institute completely transformed my career. The ADCA course was comprehensive and the faculty was incredibly supportive. I landed a great job within 2 months of completing the course!'],
                        ['name' => 'Anjali Singh', 'course' => 'Tally Prime', 'rating' => 5, 'review' => 'The Tally Prime course at Gmind Institute is the best investment I made for my career in accounting. Practical training and real-world projects gave me the confidence to handle complex accounting tasks.'],
                        ['name' => 'Mohit Jain', 'course' => 'Python Programming', 'rating' => 4, 'review' => 'Excellent Python course with hands-on projects. The instructors go above and beyond to ensure every student understands the concepts. Highly recommended for anyone looking to start a career in programming.'],
                        ['name' => 'Neha Gupta', 'course' => 'Web Design', 'rating' => 5, 'review' => 'The web design course taught me everything from HTML to advanced CSS and JavaScript. I now work as a freelance web designer and I owe my success to the amazing training at Gmind Institute.'],
                    ];
                    ?>
                    <?php foreach ($fallbackTestimonials as $ftest): ?>
                    <div class="testimonial-card">
                        <div class="testimonial-card-inner">
                            <div class="testimonial-stars" aria-label="Rating: <?= $ftest['rating'] ?> out of 5">
                                <?php for ($i = 1; $i <= 5; $i++): ?>
                                <span class="star<?= $i > $ftest['rating'] ? ' empty' : '' ?>">&#9733;</span>
                                <?php endfor; ?>
                            </div>
                            <p class="testimonial-text"><?= $ftest['review'] ?></p>
                            <div class="testimonial-author">
                                <img class="testimonial-avatar" src="<?= asset('/images/avatar-default.png') ?>" alt="<?= $ftest['name'] ?>" loading="lazy">
                                <div class="testimonial-author-info">
                                    <span class="testimonial-author-name"><?= $ftest['name'] ?></span>
                                    <span class="testimonial-author-course"><?= $ftest['course'] ?></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php endforeach; ?>
                <?php endif; ?>
            </div>

            <!-- Testimonial Navigation -->
            <div class="testimonials-nav">
                <button class="testimonials-arrow testimonials-prev" aria-label="Previous testimonial">
                    <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"><polyline points="15 18 9 12 15 6"/></svg>
                </button>
                <div class="testimonials-dots">
                    <?php
                    $totalTestimonials = !empty($testimonials) ? count($testimonials) : count($fallbackTestimonials ?? []);
                    for ($i = 0; $i < $totalTestimonials; $i++): ?>
                    <span class="testimonials-dot<?= $i === 0 ? ' active' : '' ?>" data-index="<?= $i ?>"></span>
                    <?php endfor; ?>
                </div>
                <button class="testimonials-arrow testimonials-next" aria-label="Next testimonial">
                    <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"><polyline points="9 18 15 12 9 6"/></svg>
                </button>
            </div>
        </div>
    </div>
</section>

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

<!-- Main JavaScript -->
<script src="<?= asset('/js/main.js') ?>"></script>
