<!-- Main Content -->

<div class="page-wrapper">

<div class="container-fluid pt-25">

   <div class="row">

      <div class="col-md-12">

         <div class="alert alert-success alert-dismissible" role="alert" <?php if($this->session->flashdata('message')==''){ ?> style="display:none" <?php } ?> >

            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>

            <?php echo $this->session->flashdata('message'); ?>

         </div>

      </div>

   </div>

   <!-- Row -->

   <div class="row">

      <div class="col-sm-12">

         <div class="panel panel-default card-view">

            <div class="panel-heading">

               <div class="pull-left">

                  <h6 class="panel-title txt-dark">Brand List </h6>

               </div>

               <div class="pull-right">
                  <?php if($this->admin_type=='superadmin' || (in_array('2.1', $this->authority))){ ?>
                     <a  data-toggle="modal" data-target="#addAdmin" class="btn btn-primary"> Add Brand </a>
                  <?php } ?>

               </div>

               <div class="clearfix"></div>

            </div>

            <div class="panel-wrapper collapse in">

               <div class="panel-body">
                  <?php if($this->admin_type=='superadmin' || (in_array('2.2', $this->authority))){ ?>
                     <div class="table-wrap">

                        <div class="table-responsive">

                           <table id="datable_1" class="table  table-hover">

                              <thead>

                                 <tr>

                                    <th>Sr. No.</th>

                                    <th>Brand Id</th>

                                    <!-- <th>Brand Image</th> -->
                                    <th>Brand Name</th>

                                    <th>Action</th>

                                 </tr>

                              </thead>

                              <tbody>

                                 <?php 

                                    if($brand){ foreach ($brand as $key => $value) : 

                                 ?>

                                 <tr id="<?php echo "brand_".$value['id']; ?>">

                                    <td><?php echo ($key+1); ?></td>

                                    <td><?php echo $value['brandid']; ?></td>
                                    <?php /* ?>
                                    <td>
                                       <?php if($value['image']!=''){ ?>
                                         <img src="<?php echo base_url($value['image']); ?>" style="width:100px" alt="img">
                                       <?php } ?>
                                    </td>
                                    <?php */ ?>
                                    <td><?php echo $value['brand_name']; ?></td>

                                    <td>
                                       <?php if($this->admin_type=='superadmin' || (in_array('2.3', $this->authority))){ ?>
                                          <a href="<?php echo base_url(A.'/edit-brand/'.$value['id']); ?>" class="text-inverse pr-10"  title="Edit Brand">
                                             <button class=" btn btn-info btn-icon-anim btn-square">
                                                <i class="fa fa-pencil fa-lg"></i>                                                
                                             </button>
                                          </a>
                                       <?php } ?>
                                       <?php if($this->admin_type=='superadmin' || (in_array('2.4', $this->authority))){ ?>
                                          <a href="javascript:void(0)" class="brand_delete" data-table="brand" data-value="<?php echo "id_".$value['id']; ?>" data-image='' data-id="<?php echo $value['id']; ?>">
                                             <button class="btn btn-danger btn-icon-anim btn-square">
                                                <i class="fa fa-trash fa-lg"></i>                                                
                                             </button>
                                           </a>
                                       <?php } ?>

                                       

                                       </td>

                                 </tr>

                                 <?php endforeach; } ?>

                              </tbody>

                           </table>

                        </div>

                     </div>
                  <?php } ?>
               </div>

            </div>

         </div>

      </div>

   </div>

   <!-- /Row -->

</div>





<div class="modal fade" id="addAdmin" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Add Brand</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form id="addUserForm" action="<?php echo base_url(A.'/addBrand'); ?>" method="post" enctype="multipart/form-data">
        <div class="modal-body">          
          <div class="form-group">
            <label>Brand Name</label>
            <input type="text" name="brand_name[]" class="form-control" placeholder="Enter Brand Name" />
          </div>       
          <!-- <div class="form-group">
            <label>Image</label>
            <input type="file" name="image" class="form-control"/>
            <p>image size 270x150 px</p>
          </div> -->
        </div>
        <div class="modal-footer">
          <button type="submit" class="btn btn-primary">Submit</button>
        </div>
    </form>    
  </div>
  </div>
</div>

<script type="text/javascript">
  var site_url = "<?php echo base_url(); ?>";
  var urlLink = "<?php echo A; ?>";

  $(".brand_delete").on("click",function(){

      var table = $(this).attr('data-table');

      var id = $(this).attr('data-id');

      var pimage = $(this).attr('data-image');

      var ok = confirm("Are you sure you want to delete?");

      if (ok) {

          $.ajax({

              url: site_url+urlLink+'/ajaxDelete',

              type:'POST',

              data:'id='+id+'&pimage='+pimage+'&table='+table,

              success: function(data){

                  location.reload();

              },

          });

      }

    });

</script>
<style type="text/css">
	.select2-selection{height:auto !important;min-height:42px !important;}
</style>