<style id="table-print">
	.gm-report-wrap {
		font-family: Arial, sans-serif;
		font-size: 13px;
	}
	.gm-title {
		text-align: center;
		font-weight: bold;
		font-size: 17px;
		margin-bottom: 12px;
	}
	.gm-header-row {
		width: 100%;
		border-collapse: collapse;
		margin-bottom: 18px;
	}
	.gm-header-row2 {
		width: 100%;
		border-collapse: collapse;
		margin-bottom: 8px;
	}
	.gm-header-row td {
		padding: 3px 10px 3px 0;
		font-size: 13px;
		border: none !important;
	}
	.gm-student-header {
		color: #000;
		font-weight: bold;
		font-size: 13px;
		margin-top: 18px;
		margin-bottom: 4px;
	}
	.gm-student-name-italic {
		font-style: italic;
	}
	.gm-table {
		width: 100%;
		border-collapse: collapse;
		margin-bottom: 10px;
	}
	.gm-table th {
		border: 1px solid #000;
		padding: 4px 6px;
		text-align: center;
		font-weight: bold;
		background: none !important;
		font-size: 13px;
	}
	.gm-table th:nth-child(1), .gm-table td:nth-child(1) {
		width: 5%;
	}
	.gm-table th:nth-child(2), .gm-table td:nth-child(2) {
		width: 10%;
	}
	.gm-table th:nth-child(3), .gm-table td:nth-child(3) {
		width: 15%;
	}
	.gm-table th:nth-child(4), .gm-table td:nth-child(4) {
		width: 25%;
	}
	.gm-table th:nth-child(5), .gm-table td:nth-child(5) {
		width: 15%;
	}
	.gm-table th:nth-child(6), .gm-table td:nth-child(6) {
		width: 15%;
	}
	.gm-table th:nth-child(7), .gm-table td:nth-child(7) {
		width: 10%;
	}
	.gm-table th:nth-child(8), .gm-table td:nth-child(8) {
		width: 5%;
	}
	.gm-table td {
		border: 1px solid #000;
		padding: 4px 6px;
		text-align: center;
		font-size: 13px;
		height: 20px;
	}
	.gm-table td.subject-code {
		text-align: left;
	}
	.hidden {
		display: none !important;
	}
	.gm-print-header {
		display: none;
	}
	@media print {
		.gm-print-header {
			display: block;
		}
	}
</style>

{% if students|length > 0 %}
{% set firstStudent = students|first %}
{% set firstTerm = firstStudent.academicTerms is not empty ? firstStudent.academicTerms|first : null %}

<div class="gm-report-wrap">

	<div class="gm-print-header">
		{% if additionalDetails.collegeData.isHeaderEnabled %}
			<div style="text-align: center; margin-bottom: 8px;">
				<img src="{{ additionalDetails.collegeData.collegeHeader }}" style="max-width: 100%; height: auto;">
			</div>
		{% else %}
			{% if additionalDetails.collegeData.collageLogo %}
			<div style="text-align: center; margin-bottom: 10px;">
				<img src="{{ additionalDetails.collegeData.collageLogo }}" style="width: 100px; height: auto;">
			</div>
			{% endif %}
			<div style="text-align: center; margin-bottom: 10px;">
				<div style="font-size: 18px; font-weight: bold; line-height: 1.4;">{{ additionalDetails.collegeData.collegeName ?? '' }}{% if additionalDetails.collegeData.universityName %} ({{ additionalDetails.collegeData.universityName }}){% endif %}</div>
				<div style="font-size: 14px; margin-top: 2px;">{{ additionalDetails.collegeData.collegeAddress ?? '' }}</div>
			</div>
		{% endif %}
	</div>

	<div class="gm-title">GRACE MARK REPORT - STUDENT WISE</div>

	{% set currentBatch = null %}
	{% set batchCount = 0 %}
	{% set rowCounter = 0 %}
	{% for student in students %}
		{% if student.batchName != currentBatch %}
			{% if batchCount > 0 %}</tbody></table>{% endif %}
			{% set currentBatch = student.batchName %}
			{% set batchCount = batchCount + 1 %}
			{% set rowCounter = 0 %}

			<table class="gm-table">
				<thead>
					{% if batchCount == 1 %}
					<tr class="hidden">
						<th data-a-h="center" data-f-bold="true" colspan="8">{{ additionalDetails.collegeData.collegeName ?? '' }}{% if additionalDetails.collegeData.universityName %} ({{ additionalDetails.collegeData.universityName }}){% endif %}</th>
					</tr>
					<tr class="hidden">
						<th data-a-h="center" data-f-bold="true" colspan="8">{{ additionalDetails.collegeData.collegeAddress ?? '' }}</th>
					</tr>
					<tr>
						<th colspan="8" style="border: none !important; padding: 8px 0 4px 0; font-size: 13px; text-align: left;">
							<strong>Examination:</strong> {{ firstStudent.examRegistrationName }}
						</th>
					</tr>
					{% endif %}
					<tr>
						<th colspan="8" style="border: none !important; padding: 4px 0 8px 0; font-size: 13px; text-align: left;">
							<strong>Batch:</strong> {{ student.batchName }}
						</th>
					</tr>
					<tr>
						<th data-a-h="center" data-f-bold="true">Sl. No</th>
						<th data-a-h="center" data-f-bold="true">Roll No</th>
						<th data-a-h="center" data-f-bold="true">Course Code</th>
						<th data-a-h="center" data-f-bold="true">Course</th>
						<th data-a-h="center" data-f-bold="true">Mark Before Gracing</th>
						<th data-a-h="center" data-f-bold="true">Mark After Gracing</th>
						<th data-a-h="center" data-f-bold="true">Grace Marks</th>
						<th data-a-h="center" data-f-bold="true">Result</th>
					</tr>
				</thead>
				<tbody>
		{% endif %}
		
		{% for academicTerm in student.academicTerms %}
			{% for subject in academicTerm.subjects %}
				{% for examRegistration in subject.examRegistrations %}
					{% set rowCounter = rowCounter + 1 %}
					<tr>
						<td>{{ rowCounter }}</td>
						<td>{{ student.registerNo }}</td>
						<td class="subject-code">{{ subject.code }}</td>
						<td style="text-align: left;">{{ subject.name }}</td>
						<td>{{ examRegistration.subjectExternalMarkWithOutGraceMark }}</td>
						<td>{{ (examRegistration.subjectExternalMarkWithOutGraceMark + examRegistration.graceMark) }}</td>
						<td>{{ examRegistration.graceMark }}</td>
						<td>{{ examRegistration.subjectExtrenalGradeWithGraceMark }}</td>
					</tr>
				{% endfor %}
			{% endfor %}
		{% endfor %}
	{% endfor %}
			</tbody>
			</table>

	<div class="gm-print-header" style="text-align: right; font-size: 12px; margin-top: 20px;">
		Generated on: {{ "now"|date("d-m-Y H:i:s") }}
	</div>

</div>
{% endif %}
