const continueBtn = document.querySelector(".btn");

const nameInput = document.querySelector('input[placeholder="Full Name"]');
const mobileInput = document.querySelector(
  'input[placeholder="Contact Number"]'
);
const addressInput = document.querySelector('input[placeholder="Adress"]');
const cityInput = document.querySelector('input[placeholder="City"]');
const pincodeInput = document.querySelector('input[placeholder="Pincode"]');

continueBtn.disabled = true;
continueBtn.style.opacity = "0.5";

function validateForm() {
  if (
    nameInput.value.trim() &&
    mobileInput.value.trim() &&
    addressInput.value.trim() &&
    cityInput.value.trim() &&
    pincodeInput.value.trim()
  ) {
    continueBtn.disabled = false;
    continueBtn.style.opacity = "1";
  } else {
    continueBtn.disabled = true;
    continueBtn.style.opacity = "0.5";
  }
}

[nameInput, mobileInput, addressInput, cityInput, pincodeInput].forEach(
  (input) => input.addEventListener("input", validateForm)
);

// Continue button click
continueBtn.addEventListener("click", (e) => {
  e.preventDefault();

  const formData = {
    name: nameInput.value.trim(),
    mobile: mobileInput.value.trim(),
    address: addressInput.value.trim(),
    city: cityInput.value.trim(),
    pincode: pincodeInput.value.trim(),
  };

  localStorage.setItem("personalDetails", JSON.stringify(formData));
  window.location.href = "../html/page3.html";
});

// Back button
document.querySelector(".back").addEventListener("click", () => {
  window.location.href = "../html/page1.html";
});

// ================= SOCIAL LOGIN =================

const socialButtons = document.querySelectorAll(".social-btn");
const continueText = document.getElementById("continueText");

socialButtons.forEach((btn) => {
  btn.addEventListener("click", () => {
    const app = btn.dataset.app;

    // Create formData here
    const formData = {
      name: nameInput.value.trim(),
      mobile: mobileInput.value.trim(),
      address: addressInput.value.trim(),
      city: cityInput.value.trim(),
      pincode: pincodeInput.value.trim(),
    };

    localStorage.setItem("personalDetails", JSON.stringify(formData));

    continueBtn.disabled = false;
    continueBtn.style.opacity = "1";

    continueText.innerText = `Continue with ${app}`;
  });
});
