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

	<div class="row">
		<div class="col-sm-12">
	  		<div class="card border-bottom-success shadow mb-4">
	            <div class="card-header py-3">
	              <h6 class="m-0 font-weight-bold text-success">Menu : <?= $menu['nama']; ?></h6>
	              <p class="m-0 font-weight-bold">Detail menu sebagai berikut:</p>
	    <a href="" class="btn btn-sm btn-success shadow-sm" data-toggle="modal" data-target="#addDataSubMenu" >
	        <i class="fas fa-fw fa-plus fa-sm text-white-50"></i>
	        <span class="text">Tambah Sub Menu</span>
	    </a>
	            </div>
				<div class="card-body">
					<div class="table-responsive">
				  		<table class="table table-user-management table-striped table-bordered table-sm" id="tabel-data">
						  <thead>
						    <tr>
						      <th scope="col" rowspan="2">#</th>
						      <th scope="col" rowspan="2">Menu</th>
						      <th scope="col" rowspan="2">Submenu</th>
						      <th scope="col" rowspan="2">Link</th>
						      <th scope="col" colspan="3">Role</th>
						      <th scope="col" rowspan="2">Action</th>
						    </tr>
						    <tr>
						      <th scope="col">Administrator</th>
						      <th scope="col">Petugas</th>
						      <th scope="col">User</th>
						    </tr>
						  </thead>
						  <tbody>
						  	<form action="<?= base_url('menu/ubah_stts'); ?>" method="POST">
						  		<input type="hidden" name="id_menu" value="<?= $menu['id_menu']; ?>">
						  	<?php 
						  	$i = 1;
						  	foreach($sub_menu as $row) : ?>
						  		<tr>
						  			<td><?= $i++; ?></td>
						  			<td><?= $row['nama'] ?></td>
						  			<td><?= $row['nm_sub_menu'] ?></td>
						  			<td><?= $row['link'] ?></td>
						  			<td>
							  			<?php if($row['is_admin'] == 1) { ?>
							  				<div class="form-check">
											  <label class="form-check-label">
											    <input type="checkbox" class="form-check-input" name="is_admin[]" value="<?= $row['id_sub_menu'] ?>" checked>
											    <span class="badge badge-success">Aktif</span>
											  </label>
											</div>
										<?php } else if($row['is_admin'] == 0) { ?>
							  				<div class="form-check">
											  <label class="form-check-label">
											    <input type="checkbox" class="form-check-input" name="is_admin[]" value="<?= $row['id_sub_menu'] ?>">
											    <span class="badge badge-danger">Non-Aktif</span>
											  </label>
											</div>
										<?php } ?>
						  			</td>
						  			<td>
							  			<?php if($row['is_petugas'] == 1) { ?>
							  				<div class="form-check">
											  <label class="form-check-label">
											    <input type="checkbox" class="form-check-input" name="is_petugas[]" value="<?= $row['id_sub_menu'] ?>" checked>
											    <span class="badge badge-success">Aktif</span>
											  </label>
											</div>
										<?php } else if($row['is_petugas'] == 0) { ?>
							  				<div class="form-check">
											  <label class="form-check-label">
											    <input type="checkbox" class="form-check-input" name="is_petugas[]" value="<?= $row['id_sub_menu'] ?>">
											    <span class="badge badge-danger">Non-Aktif</span>
											  </label>
											</div>
										<?php } ?>
						  			</td>
						  			<td>
							  			<?php if($row['is_user'] == 1) { ?>
							  				<div class="form-check">
											  <label class="form-check-label">
											    <input type="checkbox" class="form-check-input" name="is_user[]" value="<?= $row['id_sub_menu'] ?>" checked>
											    <span class="badge badge-success">Aktif</span>
											  </label>
											</div>
										<?php } else if($row['is_user'] == 0) { ?>
							  				<div class="form-check">
											  <label class="form-check-label">
											    <input type="checkbox" class="form-check-input" name="is_user[]" value="<?= $row['id_sub_menu'] ?>">
											    <span class="badge badge-danger">Non-Aktif</span>
											  </label>
											</div>
										<?php } ?>
						  			</td>
						  			<td>

						  				<a href="" class="badge badge-primary ubahSubMenu" data-toggle="modal" data-target="#ubahSubMenu"
						  					data-id_menu="<?= $row['id_menu'] ?>"
						  					data-id_sub_menu="<?= $row['id_sub_menu'] ?>"
						  					data-nm_sub_menu="<?= $row['nm_sub_menu'] ?>"
						  					data-link="<?= $row['link'] ?>"
						  					data-is_active="<?= $row['is_active'] ?>"
						  					>
							      			<span class="icon text-white-50">
											  	<i class="fas fa-fw fa-edit"></i>
											</span>
											<span class="text">Edit</span>
										</a>

						  				<a href="" class="badge badge-danger hapusSubMenu" data-toggle="modal" data-target="#hapusSubMenu"
						  					data-id_menu="<?= $row['id_menu'] ?>"
						  					data-id_sub_menu="<?= $row['id_sub_menu'] ?>"
						  					>
							      			<span class="icon text-white-50">
											  	<i class="fas fa-fw fa-trash"></i>
											</span>
											<span class="text">Hapus</span>
										</a>
						  			</td>
						  		</tr>
						  	<?php endforeach; ?>
							  	<tr>
							  		<td colspan="4" class="text-right">Klik Untuk Simpan</td>
							  		<td colspan="3" class="text-left"><button type="submit" class="btn btn-sm btn-primary"><i class="fas fa-fw fa-save"></i> Simpan</button></td>
							  		<td></td>
							  	</tr>
						  	</form>
						  </tbody>
						</table>
					</div>
				</div>
			</div>
	  	</div>
	</div>




<!-- Modal -->
<div class="modal fade" id="addDataSubMenu" tabindex="-1" role="dialog" aria-labelledby="addDataSubMenuLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="addDataSubMenuLabel">Tambah Sub Menu</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form action="<?= base_url('menu/tambah_sub_menu'); ?>" method="post">
	      <div class="modal-body">
	        	
                <input type="hidden" class="form-control" id="id_menu" name="id_menu" value="<?= $menu['id_menu']; ?>" required>
                <div class="form-group row">
                  <label for="nm_sub_menu" class="col-sm-2 col-form-label">Submenu</label>
                    <div class="col-sm-10">
                    <input type="text" class="form-control" id="nm_sub_menu" name="nm_sub_menu" value="" placeholder="masukkan submenu" required>
                  </div>
                </div>
                <div class="form-group row">
                  <label for="link" class="col-sm-2 col-form-label">Link</label>
                    <div class="col-sm-10">
                    <input type="text" class="form-control" id="link" name="link" value="" placeholder="masukkan link submenu" required>
                  </div>
                </div>
                <div class="form-group row">
                  <label for="is_aktif" class="col-sm-2 col-form-label">Status</label>
                    <div class="col-sm-10">
                    	<select name="is_aktif" id="is_aktif" class="form-control">
                    		<option value="">Pilih Status</option>
                    		<option value="1" selected="">Aktif</option>
                    		<option value="0">Non-Aktif</option>
                    	</select>
                  </div>
                </div>

	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
	        <button type="submit" class="btn btn-success">Tambah</button>
	      </div>
      </form>
    </div>
  </div>
</div>

<!-- Modal -->
<div class="modal fade" id="ubahSubMenu" tabindex="-1" role="dialog" aria-labelledby="ubahSubMenuLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="ubahSubMenuLabel">Ubah Sub Menu</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form action="<?= base_url('menu/ubah_sub_menu'); ?>" method="post">
	      <div class="modal-body">
	        
                <div class="form-group row">
                  <label for="name" class="col-sm-2 col-form-label">Menu</label>
                    <div class="col-sm-10">
                    <input type="hidden" class="form-control" id="id_menu_edit" name="id_menu" required>
                    <input type="hidden" class="form-control" id="id_sub_menu_edit" name="id_sub_menu" required>
                    <input type="text" class="form-control" id="nm_sub_menu_edit" name="nm_sub_menu" required>
                  </div>
                </div>
                <div class="form-group row">
                  <label for="link" class="col-sm-2 col-form-label">Link</label>
                    <div class="col-sm-10">
                    <input type="text" class="form-control" id="link_edit" name="link" value="" placeholder="masukkan link submenu" required>
                  </div>
                </div>
                <div class="form-group row">
                  <label for="is_aktif" class="col-sm-2 col-form-label">Status</label>
                    <div class="col-sm-10">
                    	<select name="is_aktif" id="is_aktif_edit" class="form-control">
                    		<option value="">Pilih Status</option>
                    		<option value="1">Aktif</option>
                    		<option value="0">Non-Aktif</option>
                    	</select>
                  </div>
                </div>


	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
	        <button type="submit" class="btn btn-success">Ubah</button>
	      </div>
      </form>
    </div>
  </div>
</div>

<!-- Modal -->
<div class="modal fade" id="hapusSubMenu" tabindex="-1" role="dialog" aria-labelledby="hapusSubMenuLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="hapusSubMenuLabel">Hapus Sub Menu</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form action="<?= base_url('menu/hapus_sub_menu'); ?>" method="post">
	      <div class="modal-body">
	        	<input type="hidden" class="form-control" id="id_menu_hapus" name="id_menu" required>
	        	<input type="hidden" class="form-control" id="id_sub_menu_hapus" name="id_sub_menu" required>
                <h4>Konfirmasi Hapus!</h4>
                <p>Apakah ingin menghapus data?</p>

	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
	        <button type="submit" class="btn btn-danger">Ya</button>
	      </div>
      </form>
    </div>
  </div>
</div>


<script src="<?= base_url(); ?>assets/vendor/jquery/jquery.min.js"></script>
<script>
	$('.ubahSubMenu').on('click',function(){
	    var id_menu = $(this).data('id_menu');
	    var id_sub_menu = $(this).data('id_sub_menu');
	    var nm_sub_menu = $(this).data('nm_sub_menu');
	    var link = $(this).data('link');
	    var is_active = $(this).data('is_active');

	    $('#id_menu_edit').val(id_menu);
	    $('#id_sub_menu_edit').val(id_sub_menu);
	    $('#nm_sub_menu_edit').val(nm_sub_menu);
	    $('#link_edit').val(link);
		  $("#is_aktif_edit option[value='" + is_active + "']").prop("selected", true).trigger('change');
    });

	$('.hapusSubMenu').on('click',function(){
	    var id_menu = $(this).data('id_menu');
	    var id = $(this).data('id_sub_menu');

	    $('#id_menu_hapus').val(id_menu);
	    $('#id_sub_menu_hapus').val(id);
    });
	
</script>