<?php

declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| EXPECTED VARIABLES
|--------------------------------------------------------------------------
|
| $stats
| $topper
|
*/

?>

<div class="result-summary-container">

    <div class="row">

        <!-- TOTAL STUDENTS -->

        <div class="col-md-3">

            <div class="small-box bg-info">

                <div class="inner">

                    <h3>

                        <?= (int) ($stats['total_students'] ?? 0); ?>

                    </h3>

                    <p>

                        Total Students

                    </p>

                </div>

                <div class="icon">

                    <i class="fas fa-users"></i>

                </div>

            </div>

        </div>

        <!-- PASS STUDENTS -->

        <div class="col-md-3">

            <div class="small-box bg-success">

                <div class="inner">

                    <h3>

                        <?= (int) ($stats['pass_students'] ?? 0); ?>

                    </h3>

                    <p>

                        Pass Students

                    </p>

                </div>

                <div class="icon">

                    <i class="fas fa-check-circle"></i>

                </div>

            </div>

        </div>

        <!-- FAIL STUDENTS -->

        <div class="col-md-3">

            <div class="small-box bg-danger">

                <div class="inner">

                    <h3>

                        <?= (int) ($stats['fail_students'] ?? 0); ?>

                    </h3>

                    <p>

                        Fail Students

                    </p>

                </div>

                <div class="icon">

                    <i class="fas fa-times-circle"></i>

                </div>

            </div>

        </div>

        <!-- AVERAGE -->

        <div class="col-md-3">

            <div class="small-box bg-warning">

                <div class="inner">

                    <h3>

                        <?= htmlspecialchars($stats['average_percentage'] ?? 0); ?>%

                    </h3>

                    <p>

                        Average Percentage

                    </p>

                </div>

                <div class="icon">

                    <i class="fas fa-chart-line"></i>

                </div>

            </div>

        </div>

    </div>

    <!-- TOPPER -->

    <?php if (!empty($topper)): ?>

        <div class="card card-outline card-success mt-4">

            <div class="card-header">

                <h3 class="card-title">

                    Class Topper

                </h3>

            </div>

            <div class="card-body">

                <div class="row align-items-center">

                    <div class="col-md-2 text-center">

                        <?php

                        $photo = !empty($topper['photo'])
                            ? WEB_ROOT . 'student/uploads/' . $topper['photo']
                            : 'https://placehold.co/100x100?text=Photo';

                        ?>

                        <img
                            src="<?= htmlspecialchars($photo); ?>"
                            class="img-thumbnail"
                            width="100"
                            alt="Topper Photo"
                        >

                    </div>

                    <div class="col-md-10">

                        <h4>

                            <?= htmlspecialchars($topper['name']); ?>

                        </h4>

                        <p class="mb-1">

                            Roll No:
                            <?= htmlspecialchars($topper['roll_no']); ?>

                        </p>

                        <p class="mb-1">

                            Percentage:
                            <?= htmlspecialchars($topper['percentage']); ?>%

                        </p>

                        <p>

                            Grade:
                            <?= htmlspecialchars($topper['overall_grade']); ?>

                        </p>

                    </div>

                </div>

            </div>

        </div>

    <?php endif; ?>

</div>