import { Login} from "../Components/Form/Login/Login.jsx"
import { SignUp } from "../Components/Form/SignUp/SignUp";
import { toast } from "react-toastify";
import { Auth } from "./Auth/Auth.jsx";
export const AuthPage = () => {
  const handleLogin = async (phoneNumber) => {
    try {
      const response = await fetch(`http://192.168.1.59:3000/users?phoneNumber=${phoneNumber}`);
      const users = await response.json();

      if (users.length > 0) {
        const user = users[0];
        localStorage.setItem("user", JSON.stringify(user));
        window.location.replace("/select-seat");
      } else {
        toast.warn("User not found. Please register or check the number.");
      }
    } catch (error) {
      console.error("Login error:", error);
      toast.error("Failed to login. Please try again.");
    }
  };

  return (
    <Auth
      LoginComponent={Login}
      SignUpComponent={SignUp}
      onLoginSubmit={handleLogin}
    />
  );
};
