<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
   <section class="content-header">
      <div class="container-fluid">
         <div class="row mb-2">
            <div class="col-sm-6">
               <h4><?php echo htmlspecialchars($title) ?></h4>
            </div>
            <div class="col-sm-6">
               <ol class="breadcrumb float-sm-right">
                  <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin/admin/dashboard">Home</a></li>
                  <li class="breadcrumb-item active"><?php echo htmlspecialchars($title) ?></li>
               </ol>
            </div>
         </div>
      </div>
      <!-- /.container-fluid -->
   </section>
   <?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');
    }
    ?>
   <section class="content">
      <div class="container">
         <div class="row"> 
            <div class="col-md-12 col-lg-12">
               <div class="container-fluid">
                  <?php echo form_open_multipart('admin/role_permission/add_new_role'); ?>
                  <div class="card card-default">
                     <div class="card-header">
                     <h3 class="card-title">Add Role</h3>
                  </div>
                     <div class="card-body">
                        <div class="tab-content">
                           <!--Application Details-->
                           <div class="tab-pane active" id="general_setting">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Role Name</label>
                                 <div class="col-sm-12">
                                    <input type="text" name="role_name" class="form-control" id="inputName" placeholder="Enter Role Name" required="required">
                                 </div>
                              </div>
                              <div class="form-group row">
                                 <label for="inputEmail" class="col-sm-12 col-form-label">Select Permission</label>
                                 <div class="col-sm-12">
                                    <table>
                                       <tr>
                                          <div class="selectgroup selectgroup-pills">
                                            <?php 
                                            $tables = $this->db->list_fields('role_permission');
                                            foreach ($tables as $table){ ?>
                                              
                                            <label class="selectgroup-item" >
                                              <input type="checkbox" name="<?php echo $table ?>" value="1" class="selectgroup-input">
                                              <span class="selectgroup-button" style="display: <?php if($table == 'id' || $table == 'role_name' || $table == 'show'){echo 'none';} ?>;"><?php echo ucwords(str_replace("_", " ", $table)); ?></span>
                                            </label>

                                            <?php } ?>
                                          </div>
                                       </tr>
                                    </table>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </div>
                     <div class="form-group row">
                        <div class="offset-sm-2 col-sm-10">
                           <button style="float: right;" type="submit" class="btn btn-success setting-submit" name="submit">Save</button>
                        </div>
                     </div>
                     <?php echo form_close(); ?>
                  </div>
               </div>
            </div>
          </div>
            <div class="col-md-12 col-lg-12">
               <div class="card">
                  <div class="card-header">
                     <h3 class="card-title">All Role Permission Details</h3>
                  </div>
                  <!-- /.card-header -->
                  <div class="card-body">
                     <table width="100%" id="example1" class="table table-bordered table-striped">
                        <thead>
                           <tr>
                              <th>Role Name</th>
                              <th>Permission Details</th>
                              <th></th>
                           </tr>
                        </thead>
                        <tbody>
                           <?php foreach ($role_permission as $key => $permission):?>
                              
                           <tr>
                            <?php 
                            if(user()->role == 'Admin')
                            {
                              $status1 = $permission->role_name != 'Super Admin' && $permission->role_name != 'Admin' && $permission->role_name != 'Vendor';
                            } 
                            elseif(user()->role == 'User')
                            {
                              $status1 = $permission->role_name != 'Super Admin' && $permission->role_name != 'Admin' && $permission->role_name != 'Vendor';
                            }
                            elseif(user()->role == 'Super Admin')
                            {
                              $status1 = $permission->role_name != 'Super Admin'; 
                            }
                            else
                            {
                              $status1 = $permission->role_name != 'Super Admin' && $permission->role_name != 'Admin' && $permission->role_name != 'Vendor';
                            }

                             ?>
                            
                            <?php if($status1): ?>
                              <td><?php echo $permission->role_name ?></td>
                              <td>
                                <div class="selectgroup selectgroup-pills">
                                    <?php 
                                    $tables = $this->db->list_fields('role_permission');
                                    foreach ($tables as $table){ ?>
                                    <?php if($permission->$table == 1): ?>
                                    <label class="selectgroup-item">
                                    <input type="checkbox" checked disabled class="selectgroup-input">
                                    <span class="selectgroup-button" style="display: <?php if($table == 'id' || $table == 'role_name' || $table == 'show'){echo 'none';} ?>;"><?php echo ucwords(str_replace("_", " ", $table)); ?></span>
                                    </label>
                                    <?php endif ?>
                                    <?php } ?>
                                </div>
                              </td>
                              <td>
                                <?php if($permission->id != 1 && $permission->id != 2):?>
                                 <div class="input-group-prepend">
                                   <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                     Action
                                   </button>
                                   <div class="dropdown-menu" style="">
                                    <a class="dropdown-item" href="<?php echo base_url() ?>admin/role_permission/edit_permission/<?php echo $permission->id ?>"><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/role_permission/delete_role_permission/<?php echo $permission->id ?>"><i class="fa fa-trash" aria-hidden="true"></i>
                                      &nbsp;Delete</a>
                                   </div>
                                 </div>
                               <?php endif; ?>
                              </td>
                           </tr>
                         <?php endif; ?>
                         <?php endforeach; ?>
                        </tbody>
                     </table>
                  </div>
                  <!-- /.card-body -->
               </div>
               <!-- /.card -->
            </div>
         </div>
      </div>
   </div>
   
</section>
</div>
<!-- /.content-wrapper -->
<style type="text/css">
  .selectgroup-pills .selectgroup-item {
    margin-right: .5rem;
    -ms-flex-positive: 0;
    flex-grow: 0;
}
.selectgroup-item {
    -ms-flex-positive: 1;
    flex-grow: 1;
    position: relative;
    font-weight: 400!important;
}
.selectgroup-input {
    opacity: 0;
    position: absolute;
    z-index: -1;
    top: 0;
    left: 0;
}
.selectgroup-item:not(:last-child) .selectgroup-button {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.selectgroup-item:not(:first-child) .selectgroup-button {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}
body[data-background-color=dark] .selectgroup-button {
    border: 1px solid #2f374b;
}
.selectgroup-pills .selectgroup-button {
    border-radius: 50px!important;
}
.selectgroup-button {
    display: block;
    border: 1px solid rgba(0,40,100,.12);
    text-align: center;
    padding: .375rem 1rem;
    position: relative;
    cursor: pointer;
    border-radius: 3px;
    color: #9aa0ac;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    font-size: 14px;
    line-height: 1.5rem;
    min-width: 2.375rem;
}
.selectgroup-input:checked+.selectgroup-button {
    border-color: #1572e8;
    z-index: 1;
    color: #1572e8;
    background: rgba(21,114,232,.15);
}
</style>