<x-layout bodyClass="g-sidenav-show  bg-gray-200">

  <x-navbars.sidebar_triage
    role="{{ $request->user()->role }}"
    activePage="exam_results"
    teacherId="{{ $current_teacher->id }}"
  >
  </x-navbars.sidebar_triage>

  <main
    class="main-content position-relative max-height-vh-100 h-100 border-radius-lg"
  >

    <!-- Navbar -->
    <x-navbars.navs.auth
      titlePage="Applied students"
      role="{{ $request->user()->role }}"
      firstName="{{ $current_teacher->firstName }}"
      last_name="{{ $current_teacher->lastName }}"
    >
    </x-navbars.navs.auth>
    <!-- End Navbar -->

    <div class="container-fluid py-4">

      @if ($message = Session::get('success'))
        <div
          class="alert alert-success"
          style="display: flex; align-items: center; gap: 0.5rem; color: white; opacity: 0.9;"
        >
          <!-- <p>{{ $message }}</p> -->
          <i class="material-icons opacity-10">check</i>
          <p style="padding: 0; margin: 0;">{{ $message }}</p>
        </div>
      @endif

      <form
        action="{{ route('teacherUpdateExamResult', [$current_teacher->id, $exam_id]) }}"
        method="POST"
        enctype="multipart/form-data"
      >
        @csrf
        @method('PUT')

        <div class="row mt-2">
          <div class="col-2">
            <span style="font-weight: bold">Email</span>
          </div>
          <div class="col-2">
            <span style="font-weight: bold">Student name</span>
          </div>
          <div class="col-2">
            <span style="font-weight: bold">Exam result</span>
          </div>
        </div>

        @if (count($students_with_exam) > 0)
          @foreach ($students_with_exam as $student)
            <div class="row mt-2">
              <div class="col-2">
                {{ $student->email }}
              </div>
              <div class="col-2">
                {{ $student->lastName }} {{ $student->firstName }}
              </div>
              <div class="col-2">
                <input
                  name="exam_result.student_id_{{ $student->id }}"
                  type="text"
                  value="{{ $student_with_exam_result[$student->id] }}"
                />
              </div>
            </div>
          @endforeach

          <div class="mt-4">

            <button
              class="btn bg-gradient-dark"
              type="submit"
            >
              <i class="material-icons opacity-10">save</i> Save
            </button>

            <a
              class="btn bg-gradient-dark"
              href="{{ route('teacherShowExamResult', [$current_teacher->id]) }}"
            >
              Cancel
            </a>
          </div>
        @else
          <div class="row my-4">
            <div
              class="col-6"
              style="font-weight: bold;"
            >
              <span>sorry but currently no student in this exam.</span>
            </div>
          </div>

          <div class="mt-4">
            <a
              class="btn btn-secondary"
              href="{{ route('teacherShowExamResult', [$current_teacher->id]) }}"
            >
              <i
                class="fas fa-arrow-left"
                style="font-size: 1rem;"
              ></i> Back
            </a>
          </div>

        @endif

      </form>

      <x-footers.auth></x-footers.auth>
    </div>

  </main>

</x-layout>
