            </div> <!-- end p-5 -->
          </div> <!-- end card-body -->
        </div> <!-- end card -->
      </div> <!-- end col -->
    </div> <!-- end row -->
  </div> <!-- end container -->

  <!-- Bootstrap core JavaScript-->
  <script src="<?= base_url('assets/sb-admin2/vendor/jquery/jquery.min.js'); ?>"></script>
  <script src="<?= base_url('assets/sb-admin2/vendor/bootstrap/js/bootstrap.bundle.min.js'); ?>"></script>

  <!-- Core plugin JavaScript-->
  <script src="<?= base_url('assets/sb-admin2/vendor/jquery-easing/jquery.easing.min.js'); ?>"></script>

  <!-- Custom scripts for all pages-->
  <script src="<?= base_url('assets/sb-admin2/js/sb-admin-2.min.js'); ?>"></script>
<script>
function togglePassword() {
  const passwordField = document.getElementById('password');
  const toggleIcon = document.querySelector('.password-toggle i');
  
  if (passwordField.type === 'password') {
    passwordField.type = 'text';
    toggleIcon.classList.remove('fa-eye');
    toggleIcon.classList.add('fa-eye-slash');
  } else {
    passwordField.type = 'password';
    toggleIcon.classList.remove('fa-eye-slash');
    toggleIcon.classList.add('fa-eye');
  }
}

// Validasi form
document.getElementById('registerForm').addEventListener('submit', function(e) {
  const password = document.getElementById('password').value;
  
  if (password.length < 6) {
    e.preventDefault();
    alert('Password harus minimal 6 karakter');
    return false;
  }
  
  // Validasi lainnya bisa ditambahkan di sini
});
</script>

<script>
  // JS untuk toggle input LPK Baru
  document.addEventListener("DOMContentLoaded", function() {
    const lpkSelect = document.getElementById('lpk_id');
    const lpkBaruGroup = document.getElementById('lpk_baru_group');
    lpkSelect.addEventListener('change', function() {
      if (this.value === 'other') {
        lpkBaruGroup.classList.remove('d-none');
      } else {
        lpkBaruGroup.classList.add('d-none');
      }
    });
  });
</script>

<script>
document.addEventListener("DOMContentLoaded", function() {
  const lpkSelect   = document.getElementById("lpk_select");
  const newLpkForm  = document.getElementById("new_lpk_form");
  const cancelBtn   = document.getElementById("cancel_lpk");

  lpkSelect.addEventListener("change", function() {
    if (this.value === "new") {
      newLpkForm.style.display = "block";
    } else {
      newLpkForm.style.display = "none";
    }
  });

  cancelBtn.addEventListener("click", function() {
    lpkSelect.value = "";
    newLpkForm.style.display = "none";
  });
});
</script>

<script>
$(document).ready(function() {
  // Toggle form
  $('#lpk_id').on('change', function() {
    if ($(this).val() === 'new') {
      $('#new-lpk-form').show();
    } else {
      $('#new-lpk-form').hide();
    }
  });

  // Save via Ajax
  $('#save-lpk').on('click', function() {
    var nama   = $('#new_lpk_name').val();
    var alamat = $('#new_lpk_alamat').val();
    var kontak = $('#new_lpk_kontak').val();

    if (!nama) {
      alert('Nama LPK wajib diisi!');
      return;
    }

    $.post("<?= base_url('auth/add_lpk'); ?>", {
      nama_lpk: nama,
      alamat: alamat,
      kontak: kontak
    }, function(res) {
      if (res.success) {
        // Tambah option ke dropdown
        $('#lpk_id').append(
          `<option value="${res.lpk_id}" selected>${res.nama_lpk}</option>`
        );
        $('#new-lpk-form').hide();
        $('#new_lpk_name, #new_lpk_alamat, #new_lpk_kontak').val('');
      } else {
        alert(res.message);
      }
    }, 'json');
  });

  $('#cancel-lpk').on('click', function() {
    $('#new-lpk-form').hide();
    $('#lpk_id').val('');
  });
});
</script>

</body>
</html>
