"use client"; import { MenuIcon, SearchIcon, LogOut, User, Shield } from "lucide-react"; import Link from "next/link"; import { useState, useEffect, useRef } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, DialogClose, } from "@/components/ui/dialog"; import Image from "next/image"; import { authClient } from "@/lib/auth-session/auth-client"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; import { Button } from "@/components/ui/button"; import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu"; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger, } from "@/components/ui/sheet"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, } from "@/components/ui/input-group"; import { ModeToggle } from "../ui/mode-toggle"; import { cn } from "@/lib/utils"; type User = { id: string; name: string; email: string; image?: string | null; role?: string; } | null; type NavbarProps = { user?: User; isAdmin?: boolean; }; const Navbar = ({ user, isAdmin: userIsAdmin }: NavbarProps) => { const [isScrolled, setIsScrolled] = useState(false); const router = useRouter(); useEffect(() => { let ticking = false; const handleScroll = () => { if (!ticking) { window.requestAnimationFrame(() => { setIsScrolled(window.scrollY > 50); ticking = false; }); ticking = true; } }; window.addEventListener("scroll", handleScroll, { passive: true }); return () => window.removeEventListener("scroll", handleScroll); }, []); const [showLogoutDialog, setShowLogoutDialog] = useState(false); const [showRequiredDialog, setShowRequiredDialog] = useState(false); const [searchValue, setSearchValue] = useState(""); const [showSuggestions, setShowSuggestions] = useState(false); const inputRef = useRef(null); const handleSignOut = async () => { setShowLogoutDialog(false); try { await authClient.signOut(); toast.success("Signed out successfully"); router.push("/sign-in"); router.refresh(); } catch { toast.error("Failed to sign out"); } }; // Handle search submit const handleSearch = (e?: React.FormEvent) => { if (e) e.preventDefault(); if (searchValue.trim()) { router.push(`/search?query=${encodeURIComponent(searchValue.trim())}`); } }; const getInitials = (name: string) => { return name .split(" ") .map((n) => n[0]) .join("") .toUpperCase() .slice(0, 2); }; const Services = [ { title: "Preventive Care", description: "Cleanings, exams, and routine check-ups to keep smiles healthy", href: "/services/preventive-care", }, { title: "Cosmetic Dentistry", description: "Teeth whitening, veneers, and smile makeovers", href: "/services/cosmetic-dentistry", }, { title: "Orthodontics", description: "Braces and clear aligners for children and adults", href: "/services/orthodontics", }, { title: "Pediatric Dentistry", description: "Gentle, kid-friendly dental care for your little ones", href: "/services/pediatric-dentistry", }, { title: "Emergency Care", description: "Same-day treatment for tooth pain, injuries, and urgent issues", href: "/services/emergency-care", }, { title: "Patient Resources", description: "New patient forms, insurance info, and financing options", href: "/patient-resources", }, ]; // Filtered suggestions based on searchValue const suggestions = searchValue.trim().length > 0 ? Services.filter( (s) => s.title.toLowerCase().includes(searchValue.toLowerCase()) || s.description.toLowerCase().includes(searchValue.toLowerCase()) ) : []; const aboutItems = [ { title: "Our Story", description: "Learn about Dental U Care's mission and values", href: "/#about", }, { title: "Our Team", description: "Meet our expert dental professionals", href: "/#team", }, { title: "Features", description: "Discover our online booking system features", href: "/#features", }, { title: "Pricing", description: "Transparent pricing for all dental services", href: "/#pricing", }, ]; return (
Log out Are you sure you want to log out? Sign in required You need to sign in to book an appointment. Would you like to sign in now?
); }; export { Navbar };