let userForm = document.querySelector("[type=app-form]");

userForm.addEventListener("submit", function(e) {
    e.preventDefault();
   
    let formData = new FormData(userForm);
    let data = [...formData.values()];
   
    fetch(`${location.origin}/apps/proxy/userinfo?shop=${Shopify.shop}`, {
        method: "POST",
        headers: {"Content-Type": "application/json"},
        body: JSON.stringify(data),
    })
    .then(response => {
        // Check if response is successful
        if (!response.ok) {
            throw new Error(`HTTP error! Status: ${response.status}`);
        }
        // Parse response as JSON
        return response.json();
    })
    .then(data => {
        // Handle JSON data
        console.log('data : ',data);
    })
    .catch(error => {
        // Handle errors
        console.error('Error Message :', error);
    });
});


// userForm.addEventListener("submit", function(e) {
//     e.preventDefault();
   
//     let formData = new FormData(userForm);
//     let data = [...formData.values()];
//     console.log('form App js 3 : ',data);
//     fetch(`${location.origin}/apps/proxy-1/userinfo?shop=${Shopify.shop}`, {
//         method: "POST",
//         headers: {"Content-Type": "application/json"},
//         body: JSON.stringify(data),
//     })
//     .then(response => response.json())
//     .then(data => console.log(data))
//     .catch(error => console.log(error))
// });