

<?php $__env->startSection('content'); ?>
<div class="container-xxl flex-grow-1 container-p-y">
  <div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
      <div>
        <h5 class="mb-0">Assignment Submissions</h5>
        <small class="text-muted">Teacher: only your assignments • Student: only your submissions</small>
      </div>

      <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(auth()->user()->hasRole('student') || auth()->user()->hasRole('master-admin')): ?>
        <a href="<?php echo e(route('assignment-submissions.create')); ?>" class="btn btn-primary btn-sm">New Submission</a>
      <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>
    <hr class="mb-0"/>

    <div class="card-body">

      <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session('success')): ?> <div class="alert alert-success"><?php echo e(session('success')); ?></div> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
      <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session('error')): ?> <div class="alert alert-danger"><?php echo e(session('error')); ?></div> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

      <div class="table-responsive">
        <table <?php if($submissions->count() > 0): ?> id="bookings-table" <?php endif; ?>
               class="table table-bordered align-middle text-center">

          <thead class="table-light">
            <tr>
              <th>ID</th>
              <th>Assignment</th>
              <th>Teacher</th>
              <th>Student</th>
              <th>Submission File</th>
              <th>Submitted At</th>
              <th>Grade</th>
              <th width="200">Actions</th>
            </tr>
          </thead>

          <tbody>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $submissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
              <?php
                $teacherName = $s->assignment?->course?->teacher?->name ?? '-';
                $fileUrl = $s->file_path ? asset($s->file_path) : null;
              ?>

              <tr>
                <td><?php echo e($s->id); ?></td>

                <td>
                  <div class="fw-semibold"><?php echo e($s->assignment->title ?? '-'); ?></div>
                </td>

                <td><?php echo e($teacherName); ?></td>

                <td>
                  <div class="fw-semibold"><?php echo e($s->student->name ?? '-'); ?></div>
                  <div class="text-muted small">Student ID: <?php echo e($s->student_id); ?></div>
                </td>

                <td>
                  <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($fileUrl): ?>
                    <div class="d-flex justify-content-center gap-2 flex-wrap">
                      
                      <a class="btn btn-outline-success btn-sm" target="_blank" href="<?php echo e($fileUrl); ?>">
                        View
                      </a>

                      
                      <a class="btn btn-outline-primary btn-sm"
                         href="<?php echo e($fileUrl); ?>"
                         download>
                        Download
                      </a>
                    </div>
                  <?php else: ?>
                    <span class="text-muted">No File</span>
                  <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </td>

                <td><?php echo e(optional($s->submitted_at)->format('Y-m-d H:i')); ?></td>
                <td><?php echo e($s->grade ?? '-'); ?></td>

                <td class="text-nowrap">
                  <a class="btn btn-sm btn-outline-primary"
                     href="<?php echo e(route('assignment-submissions.show', $s)); ?>">
                    View
                  </a>

                  <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('update assignment submissions')): ?>
                    <a class="btn btn-sm btn-outline-warning"
                       href="<?php echo e(route('assignment-submissions.edit', $s)); ?>">
                      Edit
                    </a>
                  <?php endif; ?>

                  <?php if(auth()->user()->hasRole('master-admin')): ?>
                    <form action="<?php echo e(route('assignment-submissions.destroy', $s)); ?>"
                          method="POST"
                          class="d-inline"
                          onsubmit="return confirm('Delete this submission?');">
                      <?php echo csrf_field(); ?>
                      <?php echo method_field('DELETE'); ?>
                      <button class="btn btn-sm btn-outline-danger">Delete</button>
                    </form>
                  <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </td>

              </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
              <tr>
                <td colspan="8" class="text-center text-muted">No submissions found.</td>
              </tr>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
          </tbody>

        </table>
      </div>

    </div>
  </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
<script>
$(document).ready(function () {
  if ($('#bookings-table').length) {
    $('#bookings-table').DataTable({
      responsive: false,
      scrollX: true,
      pageLength: 10,
      lengthMenu: [5, 10, 25, 50, 100],
      order: [[0, 'desc']],
      columnDefs: [{ orderable: false, targets: -1 }]
    });
  }
});
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\xampp\htdocs\digitizing-academy.lifelinehealthcare.com.pk\resources\views\assignment_submissions\index.blade.php ENDPATH**/ ?>