<!DOCTYPE html>
<html lang="en">
<?php include('fixed/top.php');  ?>
<body>
  <div class="loader"></div>
  <div id="app">
    <div class="main-wrapper main-wrapper-1">
      <div class="navbar-bg"></div>

       <?php include('fixed/navigation.php');  ?>
      <!-- Main Content -->
      <div class="main-content">
        <section class="section">
          <div class="section-body">
            <div class="row">
              <div class="col-12">
                   <?php echo $this->session->flashdata('msg'); ?>
                <div class="card">
                  <div class="card-header">
                    <h4><?=$title?></h4>
                      <button data-target="#add_cat" data-toggle="modal" class="btn btn-outline-primary" style="float:right;">Add Category</button><button data-target="#add_subcat" data-toggle="modal" class="btn btn-outline-primary" style="float:right;">Add Subcategory</button>
                  </div>
                  <div class="card-body">
                      
                    <div class="table-responsive">
                      <table class="table table-striped table-hover" id="banner" style="width:100%;">
                        <thead>
                          <tr>
                            <th>#</th>
                            <th>Category</th>
                            <th>Subcategories</th>
                            <th>Options</th>
                          </tr>
                        </thead>
                          <tbody>
                              <?php $j ='1';if(!empty($prepare)){ foreach($prepare as $prep){ if($prep->parent_id=='0'){ ?>
                              <tr>
                              <td><?=$j?></td>
                              <td><?=$prep->name?></td>
                              <td>
                              <?php  $subcat = $this->db->get_where('prepare_category', array('parent_id'=>$prep->id))->result();     foreach($subcat as $sub){ ?>
                                  <li><?=$sub->name?>
                                  <span><?php echo  "<a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$sub->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>"; ?></span>   </li> 
                              <?php } ?> 
                              </td>
                              <td>
                                 <?php echo  "<a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$prep->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>"; ?>
                              </td>
                              </tr>
                              <?php $j++; } } $j++; } ?>
                          </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </section>
      </div>
         <!---delete modal--->
          <?php 
          foreach($prepare as $prep) {
          ?>
          <div class="modal fade" id="delete_modal<?=$prep->id?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
          aria-hidden="false">
          <div class="modal-dialog" role="document">
         <form id="" method="post" action="<?php echo base_url(); ?>admin/delete_prepare_category/<?=$prep->id?>" enctype="multipart/form-data">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel" style="color:red;">Delete Data</h5>
              </div>
              <div class="modal-body">
                <div class="row clearfix">
                     <div class="col-md-12 col-sm-12 col-xs-12">
                               <div class="form-group">
                               <p>Are you sure you want to delete this record ?</p>
                                   </div>
                      </div>   

                            </div>   
              </div>
               
              <div class="modal-footer bg-whitesmoke br">
                <button type="submit" class="btn btn-primary" id="send">Continue</button>
                <!--button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button-->
              </div>
            </div>
              </form>
          </div>
        </div>
          <?php } ?>
        
         <!---add category modal--->
        
          <div class="modal fade" id="add_cat" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
          aria-hidden="false">
          <div class="modal-dialog" role="document">
         <form id="" method="post" action="<?php echo base_url(); ?>admin/add_prep_category" enctype="multipart/form-data">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel" style="color:green;">Add Category</h5>
              </div>
              <div class="modal-body">
                <div class="row clearfix">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                      <div class="form-group">
                        <label>Name</label>
                       <input name="name" type="text" class="form-control" required>
                           <input name="parent_id" type="hidden" VALUE="0" class="form-control" required>
                      </div>
                    </div>   
               </div>   
              </div>
               
              <div class="modal-footer bg-whitesmoke br">
                <button type="submit" class="btn btn-primary" id="send">Continue</button>
                <!--button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button-->
              </div>
            </div>
              </form>
          </div>
        </div>
        
          <div class="modal fade" id="add_subcat" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
          aria-hidden="false">
          <div class="modal-dialog" role="document">
         <form id="" method="post" action="<?php echo base_url(); ?>admin/add_prep_category" enctype="multipart/form-data">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel" style="color:green;">Add Subcategory</h5>
              </div>
              <div class="modal-body">
                <div class="row clearfix">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                      <div class="form-group">
                        <label>Category</label>
                       <select class="form-control" name="parent_id" required>
                            <option value="">Choose Category</option>
                          <?php if(!empty($prepare)){ foreach($prepare as $prep){ if($prep->parent_id=='0'){ ?>
                           <option value="<?=$prep->id?>"><?=$prep->name?></option>
                           <?php } } } ?>
                          </select>
                         
                      </div>
                    </div> 
                    <div class="col-md-12 col-sm-12 col-xs-12">
                      <div class="form-group">
                        <label>Subcategory Name</label>
                       <input name="name" type="text" class="form-control" required>
                      </div>
                    </div>   
               </div>   
              </div>
               
              <div class="modal-footer bg-whitesmoke br">
                <button type="submit" class="btn btn-primary" id="send">Continue</button>
                <!--button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button-->
              </div>
            </div>
              </form>
          </div>
        </div>
      <?php include('fixed/footer.php');  ?>
    </div>
  </div>
   <?php include('fixed/bottom.php');  ?>
</body>
<script>
    $(document).ready(function () {
    		$('#banner').DataTable({
	            
		    });
    	
    });
    </script>
</html>