<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"><?php echo $title ?></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/dashboard">Dashboard</a></li>
                  <li class="breadcrumb-item"><a href="#"><?php echo ucwords(str_replace("_", " ", $this->uri->segment(2))); ?></a></li>
                  <li class="breadcrumb-item active"><?php echo ucwords(str_replace("_", " ", $title)); ?></li>
               </ol>
            </div>
            <!-- /.col -->
         </div>
         <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
   </div>
   <!-- /.content-header -->
   <?php
      $errors = $this->session->userdata('errors');
      if (isset($errors)) {
          ?>
   <script>
      swal ( "Oops" ,  "<?php echo $errors ?>" ,  "error" )
   </script>
   <?php echo $errors ?>
   <?php
      $this->session->unset_userdata('errors');
      }
      $error = $this->session->userdata('error');
      if (isset($error)) {
      ?>
   <script>
      swal ( "Oops" ,  "<?php echo $error ?>" ,  "error" )
   </script>
   <?php
      $this->session->unset_userdata('error');
      }
      $success = $this->session->userdata('success');
      if (isset($success)) {
      ?>
   <script>
      swal({
      title: "Done!",
      text: "<?php echo $success ?>",
      icon: "success",
      });
   </script>
   <?php
      $this->session->unset_userdata('success');
      }
      ?>
   <!-- Main content -->
   <section class="content">
      <div class="container-fluid">
         <!-- Info boxes -->
         <div class="row">
          <div class="col-sm-12">
            <div class="card card-default">
                <div class="card-header">
                   <h6>Add New FAQ Details</h6>
                   <div class="card-tools">
                   </div>
                </div>
                <!-- /.card-header -->
                 <?php echo form_open_multipart('admin/lab_page/add_new_faq_content'); ?>
                <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">Add Content<span class="required">*</span></label>
                          <div class="table-responsive">
                             <table class="table table-bordered" id="dynamic_field">
                                <tr>
                                  <td><input type="text" name="heading[]" class="form-control name_list" placeholder="Enter FAQ Heading" required="" /></td>
                                   <td><input type="text" name="content[]" class="form-control name_list" placeholder="Enter FAQ content" required="" /></td>
                                   <td><button type="button" name="add" id="add" class="btn btn-primary">+</button></td>
                                </tr>
                             </table>
                          </div>
                       </div>
                      </div>

                      <div class="col-md-12">
                         <div class="form-group">
                            <button id="button" name="submit" style="float: right" type="submit" class="btn btn-success">Add</button>
                         </div>
                      </div>
                      <?php echo form_close() ?>
                      <!-- /.col -->
                   </div>
                   <!-- /.row -->
                </div>
                <!-- /.card-body -->
             </div>
            </div>
            <script type="text/javascript">
              $(document).ready(function(){  
                    var i=1;  
                    $('#add').click(function(){  
                         i++;  
                         $('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text" name="heading[]" class="form-control name_list" placeholder="Enter FAQ Heading" required="" /></td><td><input type="text" name="content[]" class="form-control name_list" placeholder="Enter FAQ content" required="" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');  
                    });  
                    $(document).on('click', '.btn_remove', function(){  
                         var button_id = $(this).attr("id");   
                         $('#row'+button_id+'').remove();  
                    });  
               });  
            </script>

            <div class="col-sm-12">
              <div class="card card-default">
                <div class="card-header">
                   <h6>View All FAQ</h6>
                   
                </div>
                <div class="card-body">
                  <table id="example1" class="table table-bordered table-striped">
                     <thead>
                        <tr>
                           <th>id</th>
                           <th>Faq Heading</th>
                           <th>Faq Content</th>
                           <th></th>
                        </tr>
                     </thead>
                     <tbody>
                        <?php $i=1; foreach ($get_all_faq_content as $key => $faq):?>
                        <tr>
                           <td><?php echo $i ?></td>
                           <td><?php
                           $filesCount = count(json_decode($faq->heading)); 
                           $s =1;
                            for($a = 0; $a < $filesCount; $a++): ?>
                              <?php echo '<b>'.$s.')</b> '. json_decode($faq->heading)[$a].'<br/>'; ?>
                           <?php $s++; endfor; 
                        ?></td>
                        <td><?php
                           $filesCount1 = count(json_decode($faq->content)); 
                           $s1 =1;
                            for($a1 = 0; $a1 < $filesCount1; $a1++): ?>
                              <?php echo '<b>'.$s1.')</b> '. json_decode($faq->content)[$a1].'<br/>'; ?>
                           <?php $s1++; endfor; 
                        ?></td>
                           <td>
                              <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                              Action
                              </button> 
                              <div class="dropdown-menu">
                                 <a class="dropdown-item" data-toggle="modal" data-target="#update-faq<?php echo $faq->id ?>" href="#"><i class="fa fa-edit option-icon"></i>&nbsp;Edit</a>
                                 <div class="dropdown-divider"></div>
                                 <a class="dropdown-item" onclick="return confirm('Are you sure?')" href="<?php echo base_url() ?>admin/lab_page/delete_faq/<?php echo $faq->id ?>"><i class="fa fa-trash" aria-hidden="true"></i>
                                 &nbsp;Delete</a>
                              </div>
                           </td>
                        </tr>
                        <?php $i++; ?>
                        <?php endforeach; ?>
                     </tbody>
                    
                  </table>
                </div>
              </div>
            </div>
          <!-- /.row -->
        </div>
      </div>
      <!--/. container-fluid -->
   </section>
   <!-- /.content -->
</div>
<!-- /.content-wrapper -->
 <?php $i=1; foreach ($get_all_faq_content as $key => $faq):?>
 <div class="modal fade" id="update-faq<?php echo $faq->id ?>">
  <div class="modal-dialog">
    <div class="modal-content bg-primary">
      <div class="modal-header">
        <h4 class="modal-title">Update Category</h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span></button>
      </div>
      <?php echo form_open('admin/lab_page/update_faq_content_details'); ?>
      <div class="modal-body">
        <div class="row">

            <div class="col-md-12">
               <div class="form-group">
                 <label for="inputEmail" class="col-sm-12 col-form-label">Add Content<span class="required">*</span></label>
                  <div class="table-responsive">
                     <table class="table table-bordered dynamic_field1" >
                        <?php 
                         $filesCount = count(json_decode($faq->heading)); 
                         for($a = 0; $a < $filesCount; $a++): ?>
                           <tr>
                              <td><input type="text" name="old_heading[]" class="form-control name_list" placeholder="Enter FAQ Heading" required="" value="<?php echo json_decode($faq->heading)[$a] ?>" /></td>
                              <td><input type="text" name="old_content[]" class="form-control name_list" placeholder="Enter FAQ content" required="" value="<?php echo json_decode($faq->content)[$a] ?>" />
                                 </td>
                              <td><a onclick="return confirm('Are you sure?')" href="<?php echo base_url() ?>admin/lab_page/delete_faq_content/<?php echo $a;?>/<?php echo $faq->id; ?>"><button type="button" class="btn btn-danger">X</button></a></td>
                           </tr>
                        <?php endfor; 
                        ;?>
                        <input type="hidden" name="faq_id" value="<?php echo $faq->id; ?>">
                       <tr>
                         <td width="45%"></td>
                          <td width="45%"></td>
                          <td><button type="button" name="add" class="add1 btn btn-success">+</button></td>
                       </tr>
                     </table>
                  </div>
               </div>
             </div>

          </div>
      </div>
      <div class="modal-footer justify-content-between">
        <button type="button" class="btn btn-outline-light" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-outline-light">Save changes</button>
      </div>
      <?php echo form_close() ?>
    </div>

  </div>
  <!-- /.modal-dialog -->
</div>
 <?php endforeach; ?>

 <script type="text/javascript">
  $(document).ready(function(){  
        var i=1;  
        $('.add1').click(function(){  
             i++;  
             $('.dynamic_field1').append('<tr id="row'+i+'"><td><input type="text" name="old_heading[]" class="form-control name_list" placeholder="Enter FAQ Heading" required="" /></td><td><input type="text" name="old_content[]" class="form-control name_list" placeholder="Enter FAQ content" required="" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');  
        });  
        $(document).on('click', '.btn_remove', function(){  
             var button_id = $(this).attr("id");   
             $('#row'+button_id+'').remove();  
        });  
   });  
</script>