<?php

declare(strict_types=1);

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

?>

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

            <h4 class="mt-3">

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

                Marksheet

            </h4>

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

                        Percentage

                    </th>

                    <td>

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

                    </td>

                </tr>

                <tr>

                    <th>

                        Rank

                    </th>

                    <td>

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

                    </td>

                </tr>

            </table>

        </div>

    </div>

    <!-- SUBJECT TABLE -->

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

                            <strong>

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

                            </strong>

                            <br>

                            <small class="text-muted">

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

                            </small>

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

</div>