$(document).on('page:init', '.page[data-name="account_delete"]', async function (e) {

  console.log('app account_delete ready')

  let user=get_localstorage('member');

  let dt=user.data;

  // Example of how to fill in the form fields with the provided data

  document.querySelector('#email_4').value = dt.email || '';

  document.querySelector('#id').value = dt.id || '';

  document.querySelector('#no_telp').value = dt.no_telp || '';

})



$$(document).on('page:init', '.page[data-name="account_delete"]', function(e) {

  $$(document).off("click", "#account_delete_button").on("click", "#account_delete_button", function(e) {

    e.preventDefault();

    const id = $('#id').val();

    const reason = $('#reason_4').val().trim();

    const email= $('#email_4').val().trim();

    const no_telp= $('#no_telp').val().trim();

    console.log(reason)

    let req = {

      reason,id,email,no_telp

    }

    if (!reason) {

      app.dialog.alert("Reason are required", "Error");

      return

    }    

    if (!email) {

      app.dialog.alert("Email are required", "Error");

      return

    }    

   account_delete(req);

  });

})