<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <div class="content-header">
    <div class="container-fluid">
      <div class="row mb-2">
        <div class="col-sm-6">
          <h1 class="m-0 text-dark">Update Subject</h1>
        </div><!-- /.col -->
        <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="#">Course</a></li>
            <li class="breadcrumb-item active">Update Subject</li>

          </ol>
        </div><!-- /.col -->
      </div><!-- /.row -->
    </div><!-- /.container-fluid -->
  </div>
  <!-- /.content-header -->
  <!-- Main content -->
  <section class="content">
    <div class="container-fluid">

      <div class="row">
        <div class="col-sm-12">
          <div class="card card-default">
            <div class="card-header">
              <h3 class="card-title">Update Subject</h3>
              <div class="card-tools">
                <a href="<?php echo base_url() ?>admin/course/all_subject" class="btn btn-primary btn-sm"><i
                    class="fa fa-eye" aria-hidden="true"></i> View Subject</a>
              </div>
            </div>
            <!-- /.card-header -->
            <?php echo form_open(base_url() . 'admin/course/edit_subject/' . $subject->subject_id); ?>
            <div class="card-body">
              <div class="row">

               
                <div class="col-md-12">
                  <div class="form-group">
                    <label for="inputEmail" class="col-sm-12 col-form-label">Subject Name<span
                        class="required">*</span></label>
                    <div class="col-sm-12">
                    <input type="text" value="<?php echo $subject->subject_name; ?>" class="form-control" id="recipient-text" placeholder="Enter Subject Name" required name="subject_name">
                    </div>
                  </div>
                </div>
                <div class="col-md-12">
                  <div class="form-group ">
                     <label class="col-sm-12 col-form-label">Chapter</label>
                     <div class="col-sm-12">
                        <div id="requirement_area">
                          <div class="d-flex mt-2 mb-4">
                            <div class="flex-grow-1 px-3">
                                <div class="form-group">
                                    <input type="text" class="form-control d-none mb-5" placeholder="Enter Chapter Name">
                                </div>
                            </div>
                            <div class="">
                                <button type="button" class="btn btn-success btn-sm" style="" name="button" onclick="appendRequirement()"> <i class="fa fa-plus"></i> </button>
                            </div>
                          </div>
                           <?php if (count(json_decode($subject->subject_chapter)) > 0): ?>
                              <?php
                              $counter = 0;
                              foreach (json_decode($subject->subject_chapter) as $subject):?>
                              <?php if ($counter == 0):
                                  $counter++; ?>
                                  <div class="d-flex mt-2">
                                      <div class="flex-grow-1 px-3">
                                          <div class="form-group">
                                              <input type="text" class="form-control" name="subject_chapter[]" id="requirements" placeholder="Enter Chapter Name" value="<?php echo $subject; ?>" required>
                                          </div>
                                      </div>
                                      <div class="">
                                          <button type="button" class="btn btn-danger btn-sm" style="margin-top: 0px;" name="button" onclick="removeRequirement(this)"> <i class="fa fa-minus"></i> </button>
                                      </div>
                                  </div>
                              <?php else: ?>
                                  <div class="d-flex mt-2">
                                      <div class="flex-grow-1 px-3">
                                          <div class="form-group">
                                              <input type="text" class="form-control" name="subject_chapter[]" id="requirements" placeholder="Enter Chapter Name" value="<?php echo $subject; ?>" required>
                                          </div>
                                      </div>
                                      <div class="">
                                          <button type="button" class="btn btn-danger btn-sm" style="margin-top: 0px;" name="button" onclick="removeRequirement(this)"> <i class="fa fa-minus"></i> </button>
                                      </div>
                                  </div>
                              <?php endif; ?>
                          <?php endforeach; ?>
                        <?php else: ?>
                          
                        <?php endif; ?>
                        </div>
                     </div>
                  </div>
                </div>

                <div class="col-md-12">
                  <div class="form-group">
                    <button name="form1" type="submit" class="btn btn-success">Update</button>
                  </div>
                </div>
                <?php echo form_close() ?>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
</div>
<div id = "blank_requirement_field">
    <div class="d-flex mt-2">
       <div class="flex-grow-1 px-3">
          <div class="form-group">
             <input type="text" class="form-control" name="subject_chapter[]" id="requirements" placeholder=" Enter Chapter Name" required>
          </div>
       </div>
       <div class="">
          <button type="button" class="btn btn-danger btn-sm" style="margin-top: 0px;" name="button" onclick="removeRequirement(this)"> <i class="fa fa-minus"></i> </button>
       </div>
    </div>
 </div>
<script type="text/javascript">
var blank_requirement = jQuery('#blank_requirement_field').html();
jQuery(document).ready(function() {
    jQuery('#blank_requirement_field').hide();
});

function appendRequirement() {
    jQuery('#requirement_area').append(blank_requirement);
}

function removeRequirement(requirementElem) {
    jQuery(requirementElem).parent().parent().remove();
}
</script>