<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="<?php echo base_url()?>assets/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="<?php echo base_url()?>assets/css/dataTables.bootstrap4.min.css">

    <link data-require="sweet-alert@*" data-semver="0.4.2" rel="stylesheet" href="<?php echo base_url()?>assets/css/sweetalert.min.css" />

    <link rel="icon" type="image/png" href="../../assets/images/favicon.png" />

    <title>Aplikasi UMKM</title>
  </head>
  <body>

        <nav class="navbar navbar-expand-lg navbar-dark bg-primary">    
            <div class="container">
                <a class="navbar-brand" href="#">
                    <img src="<?php echo base_url()?>assets/images/logo-white.png" width="100" alt="">
                </a>
                    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>

                    <div class="collapse navbar-collapse" id="navbarSupportedContent">
                        <ul class="navbar-nav mr-auto">
                        
                        </ul>
                        <form methode="POST" action="../login/logout" class="form-inline my-2 my-lg-0" >
                        <button class="btn btn-outline-warning btn-sm my-2 my-sm-0" type="submit">Logout</button>
                        </form>
                    </div>
             </div>
        </nav>

    <div class="container">
       <div class="row">
           <div class="col-md-3" style="cursor:pointer;">
                <div class="card" style="width: 18rem;">
                <div class="card-header text-center">
                    <img src="<?php echo base_url()?>assets/images/<?php echo $user_logged->foto_user ?>" width="125" /><br>
                    <strong><?php echo $user_logged->nama ?></strong>
                </div>
                    <ul class="list-group list-group-flush">
                    <a href="<?php echo base_url('index.php/')?>admin/dashboard" style="text-decoration:none;">
                        <li class="list-group-item bg-primary text-white border-bottom">Data Pemilik UMKM</li>
                    </a>
                    <a href="<?php echo base_url('index.php/')?>admin/umkm" style="text-decoration:none;">
                        <li class="list-group-item text-dark border-bottom">Data UMKM</li>
                    </a>
                    <a href="<?php echo base_url('index.php/')?>admin/absensi" style="text-decoration:none;">
                        <li class="list-group-item text-dark border-bottom">Absensi</li>
                    </a>
                    <a href="<?php echo base_url('index.php/')?>admin/laporan" style="text-decoration:none;">
                        <li class="list-group-item text-dark border-bottom">Laporan</li>
                    </a>
                    <a href="<?php echo base_url('index.php/')?>admin/setting" style="text-decoration:none;">
                        <li class="list-group-item text-dark">Setting</li>
                    </a>
                    </ul>
                </div>
           </div>
           <div class="col-md-9">
                <div class="card">
                    <h5 class="card-header">Pemilik UMKM</h5>
                    <div class="card-body">
                        <div>
                        <ul class="nav nav-tabs">
                            <li class="nav-item">
                                <a href="<?php echo base_url('index.php/')?>admin/tambahpemilik" class="nav-link">Tambah Data</a>
                            </li>
                            <li class="nav-item">
                                <a href="<?php echo base_url('index.php/')?>admin/dashboard" class="nav-link active">Data Pemilik</a>
                            </li>
                            
                        </ul>

                        <div class="mt-3">
                            <?php 
                                if (isset($del_msg)){
                                    if($del_msg=='error'){
                            ?>
                            <div class="alert alert-danger" role="alert">Tidak bisa menghapus <strong><?php echo $del_pemilik ?></strong>
                            , kerena terdapat data UMKM yang terkait !</div>
                            <?php } elseif($del_msg=='sucess'){ ?>
                            <div class="alert alert-success" role="alert">Data berhasil terhapus !</div>
                            <?php }}?>
                            <table id="tabeldata" class="table table-striped table-bordered" style="width:100%">
                                <thead>
                                    <tr>
                                        <th>No</th>
                                        <th>Nama</th>
                                        <th>Username</th>
                                        <th>Opsi</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                     $no=0;
                                     foreach($data_pemilik as $pemilik) {
                                     $no++;
                                    ?>
                                    <tr>
                                        <td><?php echo $no?></td>
                                        <td><?php echo $pemilik->nama?></td>
                                        <td><?php echo $pemilik->username?></td>
                                        <td>
                                            <a href="<?php echo base_url('index.php/')?>admin/tambahumkm?id_user=<?php echo $pemilik->id_user ?>" class="btn btn-success btn-sm mb-1">Tambah Umkm</a>
                                            <a href="<?php echo base_url('index.php/')?>admin/editpemilik?id_user=<?php echo $pemilik->id_user ?>" class="btn btn-warning btn-sm mb-1">Edit</a>
                                            <a href="<?php echo base_url('index.php/')?>admin/detailpemilik?id_user=<?php echo $pemilik->id_user ?>" class="btn btn-primary btn-sm mb-1">Detail</a>
                                            <a href="<?php echo base_url('index.php/')?>admin/resetpasspemilik?id_user=<?php echo $pemilik->id_user ?>" class="btn btn-info btn-sm mb-1">Reset Password</a>
                                            <a id="btn_hapus" href="<?php echo base_url('index.php/')?>admin/hapuspemilik?id_user=<?php echo $pemilik->id_user ?>" class="btn btn-danger btn-sm mb-1">Hapus</a>
                                        </td>
                                    </tr>
                                    <?php 
                                     }
                                    ?>
                                
                                </tbody>
                            
                            </table>
                        </div>
                        

                        </div>
                    </div>
                </div>
           </div>

       </div>
    </div>
    

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="<?php echo base_url()?>assets/js/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="<?php echo base_url()?>assets/js/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="<?php echo base_url()?>assets/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script src="<?php echo base_url()?>assets/js/jquery.dataTables.min.js"></script>
    <script src="<?php echo base_url()?>assets/js/dataTables.bootstrap4.min.js"></script>
    <script src="<?php echo base_url()?>assets/js/sweetalert.min.js"></script>

    <script>
        $(document).ready(function() {
            $('#tabeldata').DataTable();
        } );
    </script>

<script>
    const element = document.querySelectorAll('#btn_hapus')
    element.forEach(function(el){
  
      el.addEventListener('click', function (e) {  
      
      e.preventDefault();

      var urlToRedirect = e.currentTarget.getAttribute('href'); //use currentTarget because the click may be on the nested i tag and not a tag causing the href to be empty
      console.log(urlToRedirect); // verify if this is the right URL
      
      swal({
          title: "Kamu yakin ?",
          text: "Data yang dihapus tidak bisa dikembalikan.",
          icon: "warning",
          buttons: [
            'Batal',
            'Hapus'
          ],
          dangerMode: true,
        }).then(function(isConfirm) {
          if (isConfirm) {
            swal({
              title: 'Berhasil',
              text: 'Data berhasil terhapus',
              icon: 'success'
            }).then(function() {
                window.location.href = urlToRedirect;
            });
          } else {
            swal("Batal", "Data tidak terhapus.)", "error");
          }
        });
    });
});
  </script>

  </body>
</html>