<?php



$studentId = $studentData['student_id'];
$studentName = $studentData['name'];
$fatherName = $studentData['father_name'];
$motherName = $studentData['mother_name'];
$batch = $studentData['batch'];
$course_name = $studentData['course_nama'];



$studentResultSQL = mysqli_query($conn, "SELECT * FROM `hsc` WHERE `student_id`='$studentId'");

if (!$studentResultSQL) {
    die("Query failed: " . mysqli_error($conn));
}

$studentResultRaw = mysqli_fetch_assoc($studentResultSQL);


    $gpa = $studentResultRaw['gpa'];
    $passingYear = $studentResultRaw['exam_year'];
    $center = $studentResultRaw['study_centre'];
    

 
//  
 
 function resultCalculate($result){
     
     if ($result > 79) {
                $grade_point = "A+";
                $point = 5.00;
            } elseif ($result > 69) {
                $grade_point = "A";
                $point = 4.00;
            } elseif ($result > 59) {
                $grade_point = "A-";
                $point = 3.50;
            } elseif ($result > 49) {
                $grade_point = "B";
                $point = 3.00;
            } elseif ($result > 39) {
                $grade_point = "C";
                $point = 2.00;
            } elseif ($result > 32) {
                $grade_point = "D";
                $point = 1.00;
            } else {
                $grade_point = "F";
                $point = 0.00;
            }
            
            return [
                     'grade_point' => $grade_point,
                     'point' => $point
                   ];

 }
 
 $bangla1 = $studentResultRaw['Bangla_1']; 

$bangla2 = $studentResultRaw['Bangla_2'];
$english1 = $studentResultRaw['English_1'];
$english2 = $studentResultRaw['English_2'];
$ict = $studentResultRaw['ict'];
$civics1 = $studentResultRaw['Civics1'];
$civics2 = $studentResultRaw['Civics2'];
$economics1 = $studentResultRaw['Economics1'];
$economics2 = $studentResultRaw['Economics2'];
$islamic1 = $studentResultRaw['agriculture1'];
$islamic2 = $studentResultRaw['agriculture2'];


$bangla1Res = resultCalculate($bangla1);
$bangla2Res = resultCalculate($bangla2);
$english1Res = resultCalculate($english1);
$english2Res = resultCalculate($english2);
$ictRes = resultCalculate($ict);
$civics1Res = resultCalculate($civics1);
$civics2Res = resultCalculate($civics2);
$economics1Res = resultCalculate($economics1);
$economics2Res = resultCalculate($economics2);
$islamic1Res = resultCalculate($islamic1);
$islamic2Res = resultCalculate($islamic2);

$totalPoints = $bangla1Res['point'] + $bangla2Res['point'] +
               $english1Res['point'] + $english2Res['point'] +
               $ictRes['point'] + $civics1Res['point'] + $civics2Res['point'] +
               $economics1Res['point'] + $economics2Res['point'] +
               $islamic1Res['point'] + $islamic2Res['point'];

$Total_GPA = round($totalPoints / 11, 2); // 11 subjects




echo <<<HTML
            
          <div data-v-390fc2b0="" class="flex justify-end mb-4">
            <button
              data-v-390fc2b0=""
              onclick="window.open('hsc_document.php?student_id={$studentId}', '_blank')"
              class="bg-gray-700 hover:bg-gray-800 text-white px-4 py-2 rounded-md flex items-center"
            >
              <svg
                data-v-390fc2b0=""
                xmlns="http://www.w3.org/2000/svg"
                width="24"
                height="24"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                class="lucide lucide-download-icon h-5 w-5 mr-2"
              >
                <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
                <polyline points="7 10 12 15 17 10"></polyline>
                <line x1="12" x2="12" y1="15" y2="3"></line></svg
              ><span data-v-390fc2b0="">Download</span>
            </button>
          </div>
          <div data-v-390fc2b0="" class="bg-white shadow rounded-lg">
            <div data-v-390fc2b0="" class="p-4">
              <h3 data-v-390fc2b0="" class="text-lg font-semibold mb-2">
                Student Information
              </h3>
              <dl
                data-v-390fc2b0=""
                class="grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-3 text-sm"
              >
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">Program:</dt>
                  <dd data-v-390fc2b0="" class="">
                    Higher Secondary Certificate
                  </dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">
                    Study Center:
                  </dt>
                  <dd data-v-390fc2b0="" class="">
                    $center
                  </dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">Student I D:</dt>
                  <dd data-v-390fc2b0="" class="">$studentId</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">
                    Student Name:
                  </dt>
                  <dd data-v-390fc2b0="" class="">$studentName</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">Father Name:</dt>
                  <dd data-v-390fc2b0="" class="">$fatherName</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">Mother Name:</dt>
                  <dd data-v-390fc2b0="" class="">$motherName</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">Batch:</dt>
                  <dd data-v-390fc2b0="" class="">$batch</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">
                    Passing Year:
                  </dt>
                  <dd data-v-390fc2b0="" class="">$passingYear</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">G P A:</dt>
                  <dd data-v-390fc2b0="" class="">$gpa</dd>
                </div>
              </dl>
            </div>
          </div>
          <div data-v-390fc2b0="" class="bg-white shadow rounded-lg mt-6">
            <div data-v-390fc2b0="" class="p-4">
              <h3 data-v-390fc2b0="" class="text-lg font-semibold mb-2">
                1st Year
              </h3>
              <div data-v-390fc2b0="" class="overflow-x-auto">
                <table
                  data-v-390fc2b0=""
                  class="min-w-full divide-y divide-gray-200"
                >
                  <thead data-v-390fc2b0="" class="bg-gray-50">
                    <tr data-v-390fc2b0="">
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Exam Year/Term
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Course Code
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Course Name
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Letter Grade
                      </th>
                    </tr>
                  </thead>
                  <tbody
                    data-v-390fc2b0=""
                    class="bg-white divide-y divide-gray-200"
                  >
                    
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        HSC101
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Bangla 1st Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                       {$bangla1Res['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        HSC107
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        English 1st Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        
                         {$english1Res['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        HSC285
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Information and Communication Technology
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$ictRes['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                         HSC269
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Civics and Good Governance 1st Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$civics1Res['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        
                         HSC109
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Economics 1st Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$economics1Res['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        HSC249
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Agriculture 1st Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$islamic1Res['grade_point']}
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <div data-v-390fc2b0="" class="bg-white shadow rounded-lg mt-6">
            <div data-v-390fc2b0="" class="p-4">
              <h3 data-v-390fc2b0="" class="text-lg font-semibold mb-2">
                2nd Year
              </h3>
              <div data-v-390fc2b0="" class="overflow-x-auto">
                <table
                  data-v-390fc2b0=""
                  class="min-w-full divide-y divide-gray-200"
                >
                  <thead data-v-390fc2b0="" class="bg-gray-50">
                    <tr data-v-390fc2b0="">
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Exam Year/Term
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Course Code
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Course Name
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Letter Grade
                      </th>
                    </tr>
                  </thead>
                  <tbody
                    data-v-390fc2b0=""
                    class="bg-white divide-y divide-gray-200"
                  >
                    
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        HSC102
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Bangla 2nd Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$bangla2Res['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        HSC108
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Engilsh 2nd Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$english2Res['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        HSC270
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Civics and Good Governance 2nd Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$civics2Res['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        HSC110
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Economics 2nd Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        
                        {$economics2Res['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        HSC250
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Agriculture 2nd Paper
                       
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                         {$islamic2Res['grade_point']}
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <div data-v-390fc2b0="" class="bg-white shadow rounded-lg mt-6">
            <div data-v-390fc2b0="" class="p-4">
              <h3 data-v-390fc2b0="" class="text-lg font-semibold mb-2">
                Note
              </h3>
              <p data-v-390fc2b0="" class="text-sm text-gray-600">
                (-)- Waiver, AB- Absent, PR- Problem Related to OMR Sheet
                fill-up, RP- Expelled in the respective course, WH- Withheld,
                IC- Incomplete, NA- Not Applicable, X- No Grade Received
              </p>
            </div>
          </div>
          <!---->
        
HTML;
?>