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

  console.log('app account_delete ready')

  let user = JSON.parse(localStorage.getItem('t01_user'));

  console.log(user)

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

  document.querySelector('#token').value = user.token || '';

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

  document.querySelector('#uuid').value = user.uuid || '';

})



$$(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 uuid = $('#uuid').val();

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

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

    console.log(reason)

    let req = {

      reason,uuid,token

    }

    console.log(req)

    if (reason) {

      app.dialog.confirm('Are you sure you want to delete your account?', 'Delete Account', async function () {

        app.preloader.show()

        account_delete(req);

      })

    } else {

      app.dialog.alert("Please enter your reason", "Delete Account Errors");

    }

  });

})