<?php

declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| EXPECTED VARIABLES
|--------------------------------------------------------------------------
|
| $school
| $result
|
*/

?>

<div class="final-marksheet-container">

    <!-- HEADER -->

    <div class="row mb-4">

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

            <?php

            $logo = !empty($school['school_logo'])
                ? WEB_ROOT . 'uploads/school/' . $school['school_logo']
                : 'https://placehold.co/100x100?text=Logo';

            ?>

            <img
                src="<?= htmlspecialchars($logo); ?>"
                width="100"
                class="img-fluid"
                alt="School Logo"
            >

        </div>

        <div class="col-8 text-center">

            <h2 class="mb-1">

                <?= htmlspecialchars($school['school_name'] ?? 'School'); ?>

            </h2>

            <p class="mb-1">

                <?= htmlspecialchars($school['school_address'] ?? ''); ?>

            </p>

            <p>

                <?= htmlspecialchars($school['school_phone'] ?? ''); ?>

            </p>

            <h3 class="mt-3">

                Final Report Card

            </h3>

        </div>

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

            <?php

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

            ?>

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

        </div>

    </div>

    <!-- STUDENT DETAILS -->

    <div class="row mb-4">

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

            <table class="table table-bordered">

                <tr>

                    <th width="40%">

                        Student Name

                    </th>

                    <td>

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

                    </td>

                </tr>

                <tr>

                    <th>

                        Father Name

                    </th>

                    <td>

                        <?= htmlspecialchars($result['father_name'] ?? '-'); ?>

                    </td>

                </tr>

                <tr>

                    <th>

                        Roll No

                    </th>

                    <td>

                        <?= htmlspecialchars($result['roll_no']); ?>

                    </td>

                </tr>

            </table>

        </div>

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

            <table class="table table-bordered">

                <tr>

                    <th width="40%">

                        Class

                    </th>

                    <td>

                        <?= htmlspecialchars($result['class_name']); ?>

                    </td>

                </tr>

                <tr>

                    <th>

                        Final Percentage

                    </th>

                    <td>

                        <?= htmlspecialchars($result['percentage']); ?>%

                    </td>

                </tr>

                <tr>

                    <th>

                        Final Grade

                    </th>

                    <td>

                        <?= htmlspecialchars($result['overall_grade']); ?>

                    </td>

                </tr>

            </table>

        </div>

    </div>

    <!-- FINAL SUMMARY -->

    <div class="table-responsive">

        <table class="table table-bordered">

            <thead>

                <tr>

                    <th>

                        Total Marks

                    </th>

                    <th>

                        Obtained Marks

                    </th>

                    <th>

                        Percentage

                    </th>

                    <th>

                        Grade

                    </th>

                    <th>

                        Result Status

                    </th>

                    <th>

                        Rank

                    </th>

                </tr>

            </thead>

            <tbody>

                <tr>

                    <td>

                        <?= htmlspecialchars($result['total_marks']); ?>

                    </td>

                    <td>

                        <?= htmlspecialchars($result['obtained_marks']); ?>

                    </td>

                    <td>

                        <?= htmlspecialchars($result['percentage']); ?>%

                    </td>

                    <td>

                        <?= htmlspecialchars($result['overall_grade']); ?>

                    </td>

                    <td>

                        <?php if ($result['result_status'] === 'Pass'): ?>

                            <span class="badge badge-success">

                                Pass

                            </span>

                        <?php else: ?>

                            <span class="badge badge-danger">

                                Fail

                            </span>

                        <?php endif; ?>

                    </td>

                    <td>

                        <?= htmlspecialchars($result['rank_position']); ?>

                    </td>

                </tr>

            </tbody>

        </table>

    </div>

    <!-- SIGNATURES -->

    <div class="row mt-5">

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

            <hr>

            <strong>

                Class Teacher

            </strong>

        </div>

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

            <hr>

            <strong>

                Principal

            </strong>

        </div>

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

            <hr>

            <strong>

                Parent Signature

            </strong>

        </div>

    </div>

</div>