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

  console.log('app account_edit ready')

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

  console.log(user)

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

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

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

  document.querySelector('input[name="first_name_3"]').value = user.data.firstname || '';

  document.querySelector('input[name="last_name_3"]').value = user.data.lastname || '';

  document.querySelector('input[name="phone_3"]').value = user.data.phone || '';

})



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

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

    e.preventDefault();

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



    const token=user.sess_token;

    const firstname = $('input[name="first_name_3"]').val().trim();

    const lastname = $('input[name="last_name_3"]').val().trim();

    const phone = $('input[name="phone_3"]').val().trim();

    const uuid = $('input[name="uuid_3"]').val().trim();

    let req = {

      uuid,

      token,

      firstname,

      lastname,

      phone

    };

    if (phone && firstname) {

       account_edit(req);

    } else {

      app.dialog.alert("All fields are required", "Edit Account Errors");

    }

  });

});