// Mock user credentials
const mockUsers = [
  { username: "gva.server@gmail.com", password: "romanos12:2" },
  { username: "fernanda@vilarkptl.com", password: "Mxfe!200301" },
  { username: "andre@vilarkptl.com", password: "Variousq7!" },
  { username: "monica.estrada@incorp.com.mx", password: "34z90Xwj" },
  { username: "jaquelin.serrano@incorp.com.mx", password: "w36F3YT0" },
];

// Function to handle form submission
function handleLogin(event) {
  event.preventDefault();

  const usernameInput = document.getElementById("username");
  const passwordInput = document.getElementById("password");
  const loginMessage = document.getElementById("loginMessage");

  const enteredUsername = usernameInput.value;
  const enteredPassword = passwordInput.value;

  // Simulating login check
  const user = mockUsers.find(
    (user) =>
      user.username === enteredUsername && user.password === enteredPassword
  );

  if (user) {
    loginMessage.textContent = "Login exitoso. Redirigiendo a Dashboard...";
    // Redirect to the dashboard page after a brief delay (for demo purposes)
    setTimeout(() => {
      window.location.href = "pages/dashboard.html";
    }, 2000);
  } else {
    loginMessage.textContent = "Invalid username or password. Please try again.";
  }
}

// Attach event listener to the form
const loginForm = document.getElementById("loginForm");
loginForm.addEventListener("submit", handleLogin);
