<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>جدول الدرجات</title>
  <script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
  <script src="https://cdn.tailwindcss.com"></script>
  <link href="https://fonts.googleapis.com/css2?family=Amiri:wght@400;700&display=swap" rel="stylesheet">
  <style>
    body {
      font-family: 'Amiri', serif;
      font-size: 12px; /* Adjusted font size for better fit */
    }
    @page {
      size: A4 portrait;
      margin: 1mm; /* Slightly larger margin for printing */
    }
    @media print {
      body {
        margin: 0;
        padding: 0;
      }
      .print-container {
        margin: 0 auto;
        width: 100%;
      }
    }
    .table-container {
      width: 100%;
      max-width: 800px; /* Reduced width to fit A4 */
      margin: auto;
      border: 1px solid #333;
      background: white;
    }
    table {
      width: 100%;
      border-collapse: collapse;
      text-align: center;
    }
    th, td {
      border: 1px solid black;
      padding: 4px; /* Reduced padding for compact fit */
      font-size: 13px;
    }

    th {
      background: #f3f3f3;
    }
  </style>
</head>
<body class="flex flex-col justify-center items-center min-h-screen bg-gray-50">

<?php if($missingMatieres->isNotEmpty()): ?>
<!-- Popup: matieres missing notes — bulletin cannot be generated -->
<div id="no-notes-popup" class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
  <div class="bg-white rounded-xl shadow-2xl p-8 max-w-md w-full text-right" dir="rtl">
    <div class="text-5xl mb-3 text-center">⚠️</div>
    <h2 class="text-xl font-bold text-red-600 mb-1 text-center">تعذّر إنشاء البطاقة</h2>
    <p class="text-gray-600 mb-4 text-center text-sm">
      المواد التالية لا تزال بدون نتائج. يجب إدخال النتائج قبل طباعة البطاقة:
    </p>
    <ul class="divide-y divide-gray-200 mb-6">
      <?php $__currentLoopData = $missingMatieres; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $matiere): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <li class="py-2 flex justify-between items-center">
          <span class="text-gray-800 font-semibold"><?php echo e($matiere->name); ?></span>
          <span class="text-xs text-gray-400">معامل: <?php echo e($matiere->coefficient); ?></span>
        </li>
      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </ul>
    <button onclick="document.getElementById('no-notes-popup').style.display='none'"
      class="w-full bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-6 rounded-lg transition">
      إغلاق
    </button>
  </div>
</div>
<?php endif; ?>
  <!-- First Section -->
  <div class="w-[760px] h-[200px] bg-white  p-8 flex flex-col justify-between">
    <div class="flex justify-between items-start">
      <!-- Left Section -->
      <div class="text-center">
        <p class="text-sm font-bold">الجمهورية التونسية</p>
        <p class="text-sm font-bold">وزارة التربية</p>
        <p class="text-sm font-bold">المندوبية الجهوية للتربية</p>
        <p class="text-sm font-bold">مدنين</p>
      </div>

      <!-- Center Section -->
      <div class="text-center">
        <p class="text-lg font-bold">بطاقة النتائج المدرسية</p>
        <br>
        <div class="flex items-right space-x-4">
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<p class="text-lg font-bold" id="scoreDisplay"></p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        <p class="text-lg font-bold">
    السنة الدراسية:
    <span>
             <?php echo e($classe->ammm); ?>


    </span>
</p>

        </div>
      </div>
      <!-- Right Section -->
      <div class="text-center">
        <p class="text-sm font-bold">المعهد الثانوي الخاص</p>
        <p class="text-sm font-bold">02 ماي 66</p>
        <p class="text-sm font-bold">جرجيس</p>
      </div>
    </div>
    <div class="mt-6 text-right">
<p class="text-sm font-bold" >اسم التلميذ (ة) و لقبه (ها)  <?php echo e($eleve->first_name); ?> <?php echo e($eleve->last_name); ?> </p>
<p class="text-sm font-bold"> القسم: <span><?php echo e($classe->year); ?></span></p>
     <p class="text-sm font-bold">تاريخ الولادة: <span><?php echo e($eleve->date); ?></span></p>
     <p class="text-sm font-bold">عدد التلاميذ: <span><?php echo e($nbreleve->eleves_count); ?></span></p>
    </div>
  </div>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <!-- Second Section -->
  <div class=" w-[770px] table-container print-container">
    <table>
      <thead>
        <tr>
          <th>المواد</th>
          <th>الضارب</th>
          <th>شفاهي</th>
          <th>الأشغال<br>التطبيقية</th>
          <th>الاختبارات<br>الكتابية</th>
          <th colspan="2">
            <div>فروض المراقبة</div>
            <div class="flex justify-around items-center">
              <span>ف.م.1</span> | <span>ف.م.2</span>
            </div>
          </th>
          <th>الفرض<br>التأليفي</th>
          <th>المعدل<br>الثلاثي</th>
          <th>الرتبة</th>
          <th>الحاصل</th>
          <th>ملاحظات الأستاذ (ة) <br> و اسمه (ها)</th>
        </tr>
      </thead>
      <tbody>
        <?php $__currentLoopData = $data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <tr class=" font-semibold" >
                <td><?php echo e($item->matiere->name); ?></td>
                <td><?php echo e($item->matiere->coefficient); ?></td>
                <td><?php echo e($item->oral_exam); ?></td>
                <td><?php echo e($item->practical_work); ?></td>
                <td><?php echo e($item->written_tests); ?></td>
                <td><?php echo e($item->monitoring_exam_1 ?? '----'); ?></td>
                <td><?php echo e($item->monitoring_exam_2 ?? '----'); ?></td>
                <td><?php echo e($item->main_exam); ?></td>
                <td><?php echo e($item->quarter_average); ?></td>
                <td><?php echo e($item->rank); ?></td>
                <td><?php echo e($item->sum); ?></td>
                <td class="p-2 text-right"><?php echo e($item->professor->first_name); ?> <?php echo e($item->professor->last_name); ?></td>
               
            </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <tr class="text-xl font-semibold">
            <td >المجموع</td>
            <td ><?php echo e($sc); ?></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <!--<td ><?php echo e($ssum); ?></td>-->
            <td><?php echo e($data->sum('sum')); ?></td>

            <td class="p-2 text-right"></td>
      
        </tr>
      </tbody>
    </table>
  </div>

  <!-- Third Section -->
  <div class="w-[770px] border border-black text-[13px]">
    <table class="w-full border-collapse text-black">
      <thead>
        <tr class="text-xl font-semibold" >
          <th colspan="4" class="  p-2 bg-gray-100 text-center" >النتائج</th>
          <th colspan="3" class="  p-2 bg-gray-100 text-center">العقوبات</th>
          <th colspan="2" class="  p-2 bg-gray-100 text-right">قرار مجلس القسم وملاحظات المدير</th>
        </tr>
        <tr class="text-xl font-semibold">
          <th class="  p-2 bg-gray-100 text-right">الفترة</th>
          <th class="  p-2 bg-gray-100 text-right">الرتبة</th>
          <th class="  p-2 bg-gray-100 text-right">المعدل</th>
          <th class="  p-2 bg-gray-100 text-right">الجوائز</th>
          <th class="  p-2 bg-gray-100 text-right">إنذار</th>
          <th class="  p-2 bg-gray-100 text-right">طرد</th>
          <th class="  p-2 bg-gray-100 text-right">مجلس</th>
        </tr>
      </thead>
      <tbody>
<?php
    $sortedScores = $scoresdata->sortBy('type');
?>

<?php $__currentLoopData = $sortedScores; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $itemsc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<tr class="text-xl font-semibold">
    <td class="p-2 text-right"><?php echo e($itemsc->name); ?></td>

    <?php if($itemsc->dispenser === 'true'): ?>
        <td class="p-2 text-right">غير مرتب</td>
        <td class="p-2 text-right">معفى</td>
    <?php else: ?>
        <td class="p-2 text-right"><?php echo e($itemsc->rank); ?></td>
        <td class="p-2 text-right"><?php echo e(number_format($itemsc->average, 2)); ?></td>
    <?php endif; ?>

    <td class="p-2 text-right"></td>
    <td class="p-2 text-right"></td>
    <td class="p-2 text-right"></td>
    <td class="p-2 text-right"></td>
</tr>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>



  
      <tr>
          <td class="  p-2 text-right">السنوي</td>

          <td class="  p-2 text-right"><?php echo e($rankgen); ?></td>
          <td class="  p-2 text-right"><?php echo e($moyennegen); ?></td>
          <td class="  p-2 text-right"></td>
          <td class="  p-2 text-right"></td>
          <td class="  p-2 text-right"></td>
          <td class="  p-2 text-right"></td>
          
    <td colspan="7" class="text-right text-[13px] !important">امضاء مدير معهد</td>

      </tr>
      </tbody>
    </table>
  </div>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</body>
<script>
 
       // Get the full path from the URL
       const path = window.location.pathname;

// Split the path into segments
const segments = path.split('/');

// Select the element to display the result
const display = document.getElementById('scoreDisplay');

// Extract the value after '/score/' (e.g., 1, 2, or 3)
const scoreIndex = segments.indexOf('score');
const scoreValue = scoreIndex !== -1 ? segments[scoreIndex + 1] : null;

// Check the score value and update the display
if (scoreValue === '1') {
    display.textContent = 'الثلاثي الأول';
} else if (scoreValue === '2') {
    display.textContent = 'الثلاثي الثاني';
} else if (scoreValue === '3') {
    display.textContent = 'الثلاثي الثالث';
} else {
    display.textContent = 'مسار غير معروف';
}
    </script>
</html>
<?php /**PATH C:\Users\Toby\Desktop\02 mai zarzis\version 2026\v2\my-app\resources\views/classes/bulletins.blade.php ENDPATH**/ ?>