"use client"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { useState } from "react"; import { useAuth } from "@/context/AuthContext"; type Tab = "otp" | "password" | "social" | "booking"; export function LoginPageClient() { const router = useRouter(); const searchParams = useSearchParams(); const nextPath = searchParams.get("next") || "/profile"; const { requestOtp, verifyOtp, loginPassword, loginGoogle, loginBookingRef } = useAuth(); const [tab, setTab] = useState("otp"); const [email, setEmail] = useState(""); const [otp, setOtp] = useState(""); const [otpStep, setOtpStep] = useState<1 | 2>(1); const [password, setPassword] = useState(""); const [bookingRef, setBookingRef] = useState(""); const [message, setMessage] = useState(null); const [loading, setLoading] = useState(false); async function handleSendOtp(e: React.FormEvent) { e.preventDefault(); setLoading(true); setMessage(null); const r = await requestOtp(email); setLoading(false); setMessage(r.message); if (r.ok) setOtpStep(2); } async function handleVerifyOtp(e: React.FormEvent) { e.preventDefault(); setLoading(true); setMessage(null); const r = await verifyOtp(email, otp); setLoading(false); setMessage(r.message); if (r.ok) router.push(nextPath); } async function handlePassword(e: React.FormEvent) { e.preventDefault(); setLoading(true); setMessage(null); const r = await loginPassword(email, password); setLoading(false); setMessage(r.message); if (r.ok) router.push(nextPath); } async function handleGoogle() { setMessage(null); await loginGoogle(); } async function handleBookingRef(e: React.FormEvent) { e.preventDefault(); setMessage(null); setLoading(true); const r = await loginBookingRef(bookingRef); setLoading(false); setMessage(r.message); if (r.ok) router.push(nextPath); } const tabs: { id: Tab; label: string }[] = [ { id: "otp", label: "Email & OTP" }, { id: "password", label: "Password" }, { id: "social", label: "Social" }, { id: "booking", label: "Booking ID" }, ]; return (

Guest access

Sign in with email (OTP or password), social accounts, or your reservation reference to order room service, laundry, and manage your stay profile.

{tabs.map((t) => ( ))}
{tab === "otp" && (
{otpStep === 1 ? (
) : (

Code sent to {email}

Use the code sent to your email (hotel guest OTP).

)}
)} {tab === "password" && (

Use your Yaltopia homes account password

)} {tab === "social" && (
)} {tab === "booking" && (

Enter the booking code from your confirmation email. You must have used the same email at booking so your account links for the full guest portal.

)} {message ? (

{message}

) : null}

Guest hub — room service & laundry

); }