@extends('layouts.admin')

@section('content')
  @php
    $subjectResults = [
        ['label' => 'G.K.', 'marks' => $useranswerdetails->gkmarks, 'percentage' => $useranswerdetails->gkpercentage],
        ['label' => 'Science', 'marks' => $useranswerdetails->sciencemarks, 'percentage' => $useranswerdetails->sciencepercentage],
        ['label' => 'Hindi', 'marks' => $useranswerdetails->hindimarks, 'percentage' => $useranswerdetails->hindipercentage],
        ['label' => 'English', 'marks' => $useranswerdetails->englishmarks, 'percentage' => $useranswerdetails->englishpercentage],
        ['label' => 'Maths', 'marks' => $useranswerdetails->mathsmarks, 'percentage' => $useranswerdetails->mathspercentage],
    ];
  @endphp

  <div class="card-header">
    <h4>Exam Result Details</h4>
  </div>
  <div class="card-body">
    @include('admin.partials.flash-messages')

    <div class="result-overview-grid">
      <div class="result-overview-card">
        <span>Assignment</span>
        <strong>{{ $assignment?->competitiontitle ?: ($useranswerdetails->competitionassigntitle ?: $useranswerdetails->competitiontitle) }}</strong>
      </div>
      <div class="result-overview-card">
        <span>Student</span>
        <strong>{{ $student->name }}</strong>
      </div>
      <div class="result-overview-card">
        <span>Total Marks</span>
        <strong>{{ $useranswerdetails->totalmarks }}</strong>
      </div>
      <div class="result-overview-card">
        <span>Total Percentage</span>
        <strong>{{ $useranswerdetails->totalpercentage }}%</strong>
      </div>
      <div class="result-overview-card">
        <span>Final Result</span>
        <strong class="{{ (int) $useranswerdetails->status === 1 ? 'text-success' : 'text-danger' }}">
          {{ (int) $useranswerdetails->status === 1 ? 'Pass' : 'Fail' }}
        </strong>
      </div>
    </div>

    <div class="table-responsive">
      <table class="table table-striped table-hover" id="tableExport" style="width:100%;">
        <thead>
          <tr>
            <th>Subject</th>
            <th>Marks</th>
            <th>Percentage</th>
            <th>Result</th>
          </tr>
        </thead>
        <tbody>
          @foreach($subjectResults as $subject)
            <tr>
              <td>{{ $subject['label'] }}</td>
              <td>{{ $subject['marks'] }}</td>
              <td>{{ $subject['percentage'] }}%</td>
              <td>
                @if((float) $subject['percentage'] >= 40)
                  <span class="badge badge-success">Pass</span>
                @else
                  <span class="badge badge-danger">Fail</span>
                @endif
              </td>
            </tr>
          @endforeach
        </tbody>
      </table>
    </div>
  </div>
@endsection
