diff --git a/src/components/Header.tsx b/src/components/Header.tsx new file mode 100644 index 0000000..51cb807 --- /dev/null +++ b/src/components/Header.tsx @@ -0,0 +1,133 @@ +import { useState, useEffect } from "react"; +import { Link } from "react-router-dom"; +import { Button } from "@/components/ui/button"; +import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet"; +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogTrigger } from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Menu, Dumbbell } from "lucide-react"; +import { ThemeToggle } from "@/components/ThemeToggle"; +import { useAuth } from "@/hooks/use-tygarun"; +import { toast } from "sonner"; + +function AuthDialog({ trigger }: { trigger: React.ReactNode }) { + const { user, isSignedIn, signup, signin, signout } = useAuth(); + const [openAuth, setOpenAuth] = useState(false); + const [mode, setMode] = useState<"signin" | "signup">("signup"); + const [name, setName] = useState(""); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [busy, setBusy] = useState(false); + + if (isSignedIn) { + return ( + { signout(); toast.success("Signed out"); }}> + Sign Out{user?.email ? ` (\${user.email})` : ""} + + ); + } + + const submit = async (e: React.FormEvent) => { + e.preventDefault(); + setBusy(true); + try { + if (mode === "signup") await signup({ name, email, password }); + else await signin(email, password); + toast.success(mode === "signup" ? "Welcome to the crew!" : "Welcome back!"); + setOpenAuth(false); + setName(""); setEmail(""); setPassword(""); + } catch { + toast.error("Authentication failed. Please try again."); + } finally { + setBusy(false); + } + }; + + return ( + + {trigger} + + + {mode === "signup" ? "Join the Gym" : "Member Login"} + {mode === "signup" ? "Create your member account to book classes and manage your membership." : "Sign in to your member account."} + + + {mode === "signup" && ( + + Name + setName(e.target.value)} required className="bg-slate-900 border-slate-700" /> + + )} + + Email + setEmail(e.target.value)} required className="bg-slate-900 border-slate-700" /> + + + Password + setPassword(e.target.value)} required className="bg-slate-900 border-slate-700" /> + + + {busy ? "Please wait…" : mode === "signup" ? "Create Account" : "Sign In"} + + + setMode(mode === "signup" ? "signin" : "signup")}> + {mode === "signup" ? "Already a member? Sign in" : "New here? Create an account"} + + + + ); +} + +export default function Header() { + const [open, setOpen] = useState(false); + const [scrolled, setScrolled] = useState(false); + + useEffect(() => { + const fn = () => setScrolled(window.scrollY > 20); + window.addEventListener("scroll", fn); + return () => window.removeEventListener("scroll", fn); + }, []); + + const links = [ + { label: "Classes", to: "/classes" }, + { label: "Trainers", to: "/trainers" }, + { label: "Pricing", to: "/pricing" }, + { label: "Contact", to: "/contact" }, + ]; + + return ( + + + + + + + Apex Fitness + + + {links.map((l) => ( + {l.label} + ))} + + + + Join Now} /> + + + + + + + + {links.map((l) => ( + setOpen(false)}>{l.label} + ))} + Join Now} /> + + + + + + + ); +} \ No newline at end of file