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

  console.log('app account_delete ready')

  var view = app.views.current

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

  if (!user) {

      app.views.main.router.navigate('/signin/');

      return

  }

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

  document.querySelector('input[name="email_4"]').value = user.email || '';

})



$$(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();

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

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

    console.log(reason)

    const token=user.sess_token;

    const uuid=user.uuid;

    let req = {

      reason,uuid,token

    }

    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");

    }

  });

})