<?php

declare(strict_types=1);

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

?>

<div class="report-card-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">

                Academic Report Card

            </h3>

        </div>

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

            <?php

            $photo = !empty($student['photo'])
                ? WEB_ROOT . 'student/uploads/' . $student['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($student['name']); ?>

                    </td>

                </tr>

                <tr>

                    <th>

                        Roll No

                    </th>

                    <td>

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

                    </td>

                </tr>

                <tr>

                    <th>

                        Father Name

                    </th>

                    <td>

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

                    </td>

                </tr>

            </table>

        </div>

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

            <table class="table table-bordered">

                <tr>

                    <th width="40%">

                        Class

                    </th>

                    <td>

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

                    </td>

                </tr>

                <tr>

                    <th>

                        Overall Percentage

                    </th>

                    <td>

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

                    </td>

                </tr>

                <tr>

                    <th>

                        Overall Grade

                    </th>

                    <td>

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

                    </td>

                </tr>

            </table>

        </div>

    </div>

    <!-- SUBJECT REPORT -->

    <div class="table-responsive">

        <table class="table table-bordered">

            <thead>

                <tr>

                    <th>

                        Subject

                    </th>

                    <th>

                        Max Marks

                    </th>

                    <th>

                        Obtained

                    </th>

                    <th>

                        Grade

                    </th>

                    <th>

                        Status

                    </th>

                </tr>

            </thead>

            <tbody>

                <?php foreach ($subjects as $subject): ?>

                    <tr>

                        <td>

                            <?= htmlspecialchars($subject['subject_name']); ?>

                        </td>

                        <td>

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

                        </td>

                        <td>

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

                        </td>

                        <td>

                            <?= htmlspecialchars($subject['subject_grade']); ?>

                        </td>

                        <td>

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

                                <span class="badge badge-success">

                                    Pass

                                </span>

                            <?php else: ?>

                                <span class="badge badge-danger">

                                    Fail

                                </span>

                            <?php endif; ?>

                        </td>

                    </tr>

                <?php endforeach; ?>

            </tbody>

            <tfoot>

                <tr>

                    <th>

                        Total

                    </th>

                    <th>

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

                    </th>

                    <th>

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

                    </th>

                    <th>

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

                    </th>

                    <th>

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

                    </th>

                </tr>

            </tfoot>

        </table>

    </div>

    <!-- REMARKS -->

    <div class="mt-4">

        <h5>

            Teacher Remarks

        </h5>

        <div class="border p-3 rounded">

            <?= htmlspecialchars($result['remarks'] ?? 'Good Performance'); ?>

        </div>

    </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>