diff --git a/src/components/Header.tsx b/src/components/Header.tsx new file mode 100644 index 0000000..c19cdc6 --- /dev/null +++ b/src/components/Header.tsx @@ -0,0 +1,128 @@ +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, GraduationCap } 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 { signin, signup, isSignedIn, signout, user } = useAuth(); + const [open, setOpen] = useState(false); + const [mode, setMode] = useState<"signin" | "signup">("signin"); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [busy, setBusy] = useState(false); + + if (isSignedIn) { + return ( + { signout(); toast.success("Signed out."); }}> + {user?.name || user?.email || "Account"} · Sign Out + + ); + } + + const submit = async (e: React.FormEvent) => { + e.preventDefault(); + setBusy(true); + try { + if (mode === "signup") await signup({ email, password }); + else await signin(email, password); + toast.success(mode === "signup" ? "Account created!" : "Welcome back!"); + setOpen(false); + } catch { toast.error("Authentication failed. Please try again."); } + finally { setBusy(false); } + }; + + return ( + + {trigger} + + + {mode === "signup" ? "Create your account" : "Sign in"} + {mode === "signup" ? "Start learning in minutes." : "Access your courses and progress."} + + + + Email + setEmail(e.target.value)} placeholder="you@example.com" required /> + + + Password + setPassword(e.target.value)} placeholder="••••••••" required /> + + + {busy ? "Please wait…" : mode === "signup" ? "Create Account" : "Sign In"} + + + setMode(mode === "signup" ? "signin" : "signup")}> + {mode === "signup" ? "Already have an account? 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: "Courses", to: "/courses" }, + { label: "Instructors", to: "/instructors" }, + { label: "Pricing", to: "/courses" }, + { label: "Contact", to: "/contact" }, + ]; + + return ( + + + + + + + Luminar Academy + + + {links.map((l) => ( + {l.label} + ))} + + + + Sign In} /> + + Enroll Now + + + + + + + + + {links.map((l) => ( + setOpen(false)}>{l.label} + ))} + + setOpen(false)}>Enroll Now + + Sign In} /> + + + + + + + ); +} \ No newline at end of file