"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Eye, EyeOff, Loader2 } from "lucide-react"; interface LoginDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onLoginSuccess: () => void; } // Login Dialog component export function LoginDialog({ open, onOpenChange, onLoginSuccess }: LoginDialogProps) { const [isSignup, setIsSignup] = useState(false); const [loginData, setLoginData] = useState({ email: "", password: "", }); const [signupData, setSignupData] = useState({ fullName: "", email: "", phone: "", }); const [showPassword, setShowPassword] = useState(false); const [rememberMe, setRememberMe] = useState(false); const [loginLoading, setLoginLoading] = useState(false); const [signupLoading, setSignupLoading] = useState(false); const [error, setError] = useState(null); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setLoginLoading(true); setError(null); try { // Simulate login API call await new Promise((resolve) => setTimeout(resolve, 1000)); // After successful login, close dialog and call success callback setShowPassword(false); setLoginLoading(false); onOpenChange(false); onLoginSuccess(); } catch (err) { setError("Login failed. Please try again."); setLoginLoading(false); } }; const handleSignup = async (e: React.FormEvent) => { e.preventDefault(); setSignupLoading(true); setError(null); try { // Simulate signup API call await new Promise((resolve) => setTimeout(resolve, 1000)); // After successful signup, automatically log in and proceed setSignupLoading(false); onOpenChange(false); onLoginSuccess(); } catch (err) { setError("Signup failed. Please try again."); setSignupLoading(false); } }; const handleSwitchToSignup = () => { setIsSignup(true); setError(null); setLoginData({ email: "", password: "" }); }; const handleSwitchToLogin = () => { setIsSignup(false); setError(null); setSignupData({ fullName: "", email: "", phone: "" }); }; return ( {isSignup ? "Create an account" : "Welcome back"} {isSignup ? "Sign up to complete your booking" : "Please log in to complete your booking"} {/* Signup Form */} {isSignup ? (
{error && (

{error}

)} {/* Full Name Field */}
setSignupData({ ...signupData, fullName: e.target.value })} className="h-12 bg-white border-gray-300" required />
{/* Email Field */}
setSignupData({ ...signupData, email: e.target.value })} className="h-12 bg-white border-gray-300" required />
{/* Phone Field */}
setSignupData({ ...signupData, phone: e.target.value })} className="h-12 bg-white border-gray-300" required />
{/* Submit Button */} {/* Switch to Login */}

Already have an account?{" "}

) : ( /* Login Form */
{error && (

{error}

)} {/* Email Field */}
setLoginData({ ...loginData, email: e.target.value })} className="h-12 bg-white border-gray-300" required />
{/* Password Field */}
setLoginData({ ...loginData, password: e.target.value })} className="h-12 bg-white border-gray-300 pr-12" required />
{/* Submit Button */} {/* Remember Me & Forgot Password */}
{/* Sign Up Prompt */}

New to Attune Heart Therapy?{" "}

)}
); }