<?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');
    }
    ?>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Feature For You</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo admin_url() ?>admin">Home</a></li>
              <li class="breadcrumb-item active">Feature For You</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- 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">
                <h4>Update Section</h4>
                
              </div>
              <!-- /.card-header -->
              <?php echo form_open_multipart(base_url().'admin/frontend_setting/update_feature_for_you'); ?>
              <div class="card-body">
                <div class="row">
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Title<span class="required">*</span></label>
                      <input type="text" name="title" class="form-control" placeholder="Enter Heading" required="" value="<?php echo $feature->title; ?>">
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Description<span class="required">*</span></label>
                      <textarea type="text" name="description" class="form-control" placeholder="Enter  Sub Heading" required="" value=""><?php echo $feature->description; ?></textarea>
                    </div>
                  </div>

                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Image<span class="required">*</span></label>
                      <input type="file" name="image" class="form-control" placeholder="Enter  Content 2" >
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Image<span class="required">*</span></label>
                      <img src="<?php echo base_url()?><?php echo $feature->image; ?>" width="100px">
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <label for="inputEmail" class="col-sm-12 col-form-label">Add Content</label>
                      <div class="table-responsive">
                         <table class="table table-bordered" id="dynamic_field">


                          <?php 
                          if($feature->content){
                            $a=0; 
                            $filesCount = count(json_decode($feature->content)); 
                            for($i = 0; $i < $filesCount; $i++)
                            { 
                              $content = json_decode($feature->content)[$i];
                            ?>
                            <tr id="row_2_<?php echo $i?>">
                               <td width="90%"><input type="text" name="content[]" class="form-control name_list" placeholder="Enter Content" value="<?php echo $content ?>" /></td>
                               <td><button type="button" id="<?php echo $i?>" class="btn btn-danger btn_remove_2">X</button></td>
                               <input type="hidden" name="content_old_id[]" value="<?php echo $i ?>">
                            </tr>
                          <?php 
                            
                          }; } ?>
                          <tr>
                               <td width="90%"></td>
                               <td><button type="button" name="add" id="add" class="btn btn-success">+</button></td>
                            </tr>
                         </table>
                      </div>
                   </div>
                  </div>
                  
                  
                  <div class="col-md-12">
                    <div class="form-group">
                      <button class="btn btn-info" type="submit" style="float: right">Update</button>
                    </div>
                  </div>
                  <?php echo form_close(); ?>
                </div>
              </div>
            </div>
          </div>
          

      </div>
    </section>
    <!-- /.content -->
  </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="content[]" class="form-control name_list" placeholder="Enter Content"/></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();  
        });  
         $(document).on('click', '.btn_remove_2', function(){  
             var button_id = $(this).attr("id");   
             $('#row_2_'+button_id+'').remove();  
        });  
   });  
</script>