<div class="content-wrapper">
   <div class="content-header">
      <div class="container-fluid">
         <div class="row mb-2">
            <div class="col-sm-6">
               <h1 class="m-0 text-dark">Edit Batch</h1>
            </div>
            <div class="col-sm-6">
               <ol class="breadcrumb float-sm-right">
                  <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin/admin/dashboard">Dashboard</a></li>
                  <li class="breadcrumb-item"><a href="#">Admission</a></li>
                  <li class="breadcrumb-item active">Edit Batch </li>
               </ol>
            </div>
         </div>
      </div>
   </div>
   <section class="content">
      <div class="container-fluid">
         <div class="card card-default">
            <div class="card-header">
               <h3 class="card-title">Edit Batch</h3>
               <div class="card-tools">
                  <a href="<?php echo base_url()?>/admin/admission/view_all_batch" class="btn btn-success btn-sm"><i class="fa fa-eye" aria-hidden="true"></i> View All Batch</a>
               </div>
            </div>
            <?php echo form_open('admin/admission/update_batch/'.$batch->batch_id); ?>
            <div class="card-body">
               <div class="row">
                  <div class="col-md-7">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Batch Name<span class="required">*</span></label>
                        <div class="col-sm-12">
                           <input type="text" class="form-control"  name="batch_name"  required="required" placeholder="Enter Batch Name" value="<?php echo $batch->batch_name?>">
                        </div>
                     </div>
                  </div>
                  <div class="col-md-3">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Batch Size<span class="required">*</span> </label>
                        <div class="col-sm-12">
                           <input type="number" class="form-control"  name="batch_size"  required="required" placeholder="Enter Batch Size" value="<?php echo $batch->batch_size?>" min="1">
                        </div>
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Batch Room No<span class="required">*</span> </label>
                        <div class="col-sm-12">
                           <select class="form-control"  name="batch_room_no"  required="required" placeholder="Enter Batch Size">
                              <option value="">Select</option>
                              <option <?php if($batch->batch_room_no == 1){echo 'selected';} ?> value="1">1</option>
                              <option <?php if($batch->batch_room_no == 2){echo 'selected';} ?> value="2">2</option>
                              <option <?php if($batch->batch_room_no == 3){echo 'selected';} ?> value="3">3</option>
                              <option <?php if($batch->batch_room_no == 4){echo 'selected';} ?> value="4">4</option>
                              <option <?php if($batch->batch_room_no == 5){echo 'selected';} ?> value="5">5</option>
                           </select>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-4">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Batch Course<span class="required">*</span> </label>
                        <div class="col-sm-12">
                           <select type="number" class="form-control"  name="batch_course"  required="required" placeholder="Enter Batch Size">
                              <option value="">Select A Course</option>
                              <?php foreach ($all_course as $key => $course):?>
                                 <option <?php if($batch->batch_course == $course->course_id){echo 'selected';}?> value="<?php echo $course->course_id; ?>"><?php echo $course->course_name; ?></option>
                              <?php endforeach; ?>
                           </select>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-4">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Batch Teacher<span class="required">*</span> </label>
                        <div class="col-sm-12">
                           <select type="number" class="form-control"  name="batch_teacher"  required="required" placeholder="Enter Batch Size">
                              <option value="">Select A Teacher</option>
                              <?php foreach ($all_teacher as $key => $teacher):?>
                                 <option <?php if($batch->batch_teacher == $teacher->user_id){echo 'selected';}?> value="<?php echo $teacher->user_id; ?>"><?php echo $teacher->user_name; ?></option>
                              <?php endforeach; ?>
                           </select>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-4">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Batch Start Date<span class="required">*</span> </label>
                        <div class="col-sm-12">
                           <input type="date" class="form-control"  name="batch_start_date"  required="required" placeholder="Enter Batch Size" value="<?php echo $batch->batch_start_date?>"> 
                        </div>
                     </div>
                  </div>
                  <?php
                     $days = array(
                         'mon' => 'Monday',
                         'tue' => 'Tuesday',
                         'wed' => 'Wednesday',
                         'thu' => 'Thursday',
                         'fri' => 'Friday',
                         'sat' => 'Saturday',
                         'sun' => 'Sunday'
                     );

                     $dataArray = json_decode($batch->batch_timing_details, true);
                  ?>
                  <div class="col-md-4">
                     <table width="100%">
                        <?php foreach ($days as $dayKey => $dayName): ?>
                           <tr>
                               <td>
                                   <label><input type="checkbox" id="<?php echo $dayKey; ?>-checkbox" onclick="toggleWorkingHours('<?php echo $dayKey; ?>')" <?php echo !empty($dataArray[$dayName]['start']) || !empty($dataArray[$dayName]['end']) ? 'checked' : ''; ?>>&nbsp;&nbsp;<?php echo $dayName; ?></label>
                               </td>
                               <td>
                                   <input type="time" class="" name="<?php echo $dayKey; ?>-start" id="<?php echo $dayKey; ?>-start" value="<?php echo $dataArray[$dayName]['start']; ?>" <?php echo empty($dataArray[$dayName]['start']) ? 'disabled' : ''; ?>> &nbsp;&nbsp;to&nbsp;&nbsp;
                                   <input type="time" class="" name="<?php echo $dayKey; ?>-end" id="<?php echo $dayKey; ?>-end" value="<?php echo $dataArray[$dayName]['end']; ?>" <?php echo empty($dataArray[$dayName]['end']) ? 'disabled' : ''; ?>>
                               </td>
                           </tr>
                        <?php endforeach; ?>
                     </table>
                  </div>
                  <div class="col-md-12">
                     <div class="form-group">
                        <button name="submit" style="float: right" type="submit" class="btn btn-success">Update</button>
                     </div>
                  </div>
                  <?php echo form_close() ?>
               </div>
            </div>
         </div>
      </div>
   </section>
</div>
 <script>
   function toggleWorkingHours(day) {
      var startInput = document.getElementById(day + '-start');
      var endInput = document.getElementById(day + '-end');
      var checkbox = document.getElementById(day + '-checkbox');
        
      startInput.disabled = !checkbox.checked;
      endInput.disabled = !checkbox.checked;
        
      if (checkbox.checked) {
          startInput.setAttribute('required', 'required');
          endInput.setAttribute('required', 'required');
      } else {
          startInput.removeAttribute('required');
          endInput.removeAttribute('required');
      }
   }
  </script>