<style>
    body {
        font-family: "Times New Roman", Times, serif;
        margin: 0;
        padding: 0;
    }
    @media print {
        body {
            margin: 0;
            padding: 0;
        }
        .primary-table,
        .primary-table th,
        .primary-table td {
            -webkit-print-color-adjust: exact;
            print-color-adjust: exact;
        }
    }
    .report-container {
        padding: 10mm;
        margin: 0;
    }
    .primary-table {
        border-collapse: separate;
        border-spacing: 2px;
        width: 100%;
        margin-top: 5mm;
    }
    .primary-table th {
        text-align: center;
        background: none;
        height: 6mm;
        border: 1px solid #666;
        padding: 2mm;
        font-weight: bold;
        font-size: 12px;
    }
    .primary-table td {
        padding: 2mm;
        line-height: 15px;
        height: 6mm;
        border: 1px solid #666;
        text-align: center;
        vertical-align: middle;
        font-size: 11px;
    }
    .batch-header {
        font-weight: bold;
        text-align: center;
    }
    .text-left {
        text-align: left;
    }
    .text-center {
        text-align: center;
    }
</style>

<div class="report-container">
    <!-- Data Table -->
    <table class="primary-table">
        <thead>
            <!-- College Header Row -->
            <tr>
                {% set months = ['', 'January','February','March','April','May','June','July','August','September','October','November','December'] %} 
                <td colspan="11" style="text-align: center; font-weight: bold; font-size: 16px; padding: 8px;">
                    {{college.collegeName}}<br><br><br><br>RECHECKING RESULTS: {{ examRegistration.parentExamRegistrationProperties.examMonth ? (examRegistration.parentExamRegistrationProperties.examMonth ~ '/01/2000')|date('F') : '' }} {{examRegistration.parentExamRegistrationProperties.examYear}}
                   
                </td>
            </tr>
            
            <!-- Column Headers Row -->
            <tr>
                <th style="width: 5%;" rowspan="2">Roll No.</th>
                <th style="width: 15%;" rowspan="2">Name</th>
                <th style="width: 8%;" rowspan="2">Course Code</th>
                <th style="width: 20%;" rowspan="2">Course Title</th>
                <th style="width: 8%;" rowspan="2">Internal Mark</th>
                <th style="width: 16%;" colspan="2">ESE</th>
                <th style="width: 8%;" rowspan="2">Total</th>
                <th style="width: 8%;" rowspan="2">Result</th>
                <th style="width: 8%;" rowspan="2">Remark</th>
                <th style="width: 8%;" rowspan="2">Finalized</th>
            </tr>
            <tr>
                <th style="width: 8%;">External Mark</th>
                <th style="width: 8%;">Rechecking</th>
            </tr>
        </thead>
        <tbody>
            {% set currentBatch = null %}
            {% set batchStudentCount = 0 %}
            
            {% for student in students %}
                {% if currentBatch != student.groupName %}
                    {% if currentBatch != null %}
                    {% endif %}
                    <tr>
                        <td colspan="11" class="batch-header">
                            {{ student.groupName }}
                        </td>
                    </tr>
                    {% set currentBatch = student.groupName %}
                    {% set batchStudentCount = 0 %}
                {% endif %}
                
                {% set batchStudentCount = batchStudentCount + 1 %}
                
                <tr class="text-center">
                    <td>{{ student.studentRegisterNo }}</td>
                    <td class="text-left">{{ student.studentName }}</td>
                    <td>{{ student.subjectCode }}</td>
                    <td class="text-left">{{ student.subjectName }}</td>
                    <td>{{ student.internalMark|round(0) }}</td>
                    <td>{{ student.externalMark|round(0) }}</td>
                    <td><b>{{ student.revaluationMark|round(0) ?: '' }}</b></td>
                    <td>
                        {% if student.finalizedValuationMark and student.externalMark %}
                            {% if student.revaluationMark is not null and student.revaluationMark != '' %}
                                {% set effectiveMark = student.revaluationMark > student.externalMark ? student.revaluationMark : student.externalMark %}
                                {{ (student.internalMark + effectiveMark)|default('-')|round(0) }}
                            {% else %}
                                {{ (student.internalMark + student.externalMark)|default('-')|round(0) }}
                            {% endif %}
                        {% else %}
                            -
                        {% endif %}
                    </td>
                    <td>{{ (student.finalizedValuationMark and student.externalMark) ? (student.finalGrade ?: '') : '-' }}</td>
                    <td>
                    </td>
                    <td>
                        {{ (student.finalizedValuationMark and student.externalMark ) ? 'YES' : 'NO' }}
                    </td>
                </tr>
            {% endfor %}
            </div>
        </tbody>
    </table>
    <div style="margin-top: 30mm; text-align: right; padding-right: 10mm; font-size: 13px;">
        Controller of Examination
    </div>
</div>