|
| 1 | +import { useAuth } from "@/domains/auth/application/AuthContext"; |
| 2 | +import { useTheme } from "@/shared/hooks/useTheme"; |
| 3 | +import { ThemeToggle } from "@/shared/ui/theme-toggle"; |
| 4 | +import { Bell, Mail } from "lucide-react"; |
| 5 | +import { useLocation } from "react-router-dom"; |
| 6 | + |
| 7 | +const routeTitles: Array<{ path: string; title: string; exact?: boolean }> = [ |
| 8 | + { path: "/home", title: "Início", exact: true }, |
| 9 | + { path: "/vagas", title: "Vagas" }, |
| 10 | + { path: "/mentoria", title: "Mentoria" }, |
| 11 | +]; |
| 12 | + |
| 13 | +function getHeaderTitle(pathname: string) { |
| 14 | + const matchedRoute = routeTitles.find((route) => { |
| 15 | + if (pathname === route.path) return true; |
| 16 | + if (route.exact) return false; |
| 17 | + return pathname.startsWith(`${route.path}/`); |
| 18 | + }); |
| 19 | + |
| 20 | + return matchedRoute?.title ?? "Início"; |
| 21 | +} |
| 22 | + |
| 23 | +function getInitials(value: string) { |
| 24 | + const normalized = value.trim(); |
| 25 | + if (!normalized) return "U"; |
| 26 | + |
| 27 | + const [first = "", second = ""] = normalized |
| 28 | + .replace(/@.*/, "") |
| 29 | + .split(/\s|[._-]/) |
| 30 | + .filter(Boolean); |
| 31 | + |
| 32 | + return `${first[0] ?? ""}${second[0] ?? first[1] ?? ""}`.toUpperCase(); |
| 33 | +} |
| 34 | + |
| 35 | +export function AuthenticatedHeader() { |
| 36 | + const { user } = useAuth(); |
| 37 | + const { resolvedTheme, toggleTheme } = useTheme(); |
| 38 | + const location = useLocation(); |
| 39 | + |
| 40 | + const displayName = |
| 41 | + user?.name || user?.displayName || user?.email || "Usuário"; |
| 42 | + const title = getHeaderTitle(location.pathname); |
| 43 | + const initials = getInitials(displayName); |
| 44 | + |
| 45 | + return ( |
| 46 | + <header className="flex h-[103px] shrink-0 items-center justify-between border-b border-border bg-card px-6 text-card-foreground shadow-[0_8px_18px_rgba(0,0,0,0.04)] dark:shadow-[0_8px_24px_rgba(0,0,0,0.22)] md:px-[43px]"> |
| 47 | + <h1 className="truncate text-[32px] font-bold leading-[1.5] text-foreground"> |
| 48 | + {title} |
| 49 | + </h1> |
| 50 | + |
| 51 | + <div className="flex shrink-0 items-center gap-[17px]"> |
| 52 | + <ThemeToggle theme={resolvedTheme} onToggle={toggleTheme} /> |
| 53 | + <button |
| 54 | + type="button" |
| 55 | + className="flex size-6 items-center justify-center text-foreground transition-colors hover:text-primary" |
| 56 | + aria-label="Mensagens" |
| 57 | + > |
| 58 | + <Mail className="size-4" strokeWidth={2.4} /> |
| 59 | + </button> |
| 60 | + <button |
| 61 | + type="button" |
| 62 | + className="flex size-6 items-center justify-center text-foreground transition-colors hover:text-primary" |
| 63 | + aria-label="Notificações" |
| 64 | + > |
| 65 | + <Bell className="size-4" strokeWidth={2.4} /> |
| 66 | + </button> |
| 67 | + <div |
| 68 | + className="flex size-8 items-center justify-center rounded-full bg-[#8fb3a0] text-base font-semibold leading-6 text-primary dark:bg-primary/30 dark:text-primary-foreground" |
| 69 | + aria-label={displayName} |
| 70 | + title={displayName} |
| 71 | + > |
| 72 | + {initials} |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + </header> |
| 76 | + ); |
| 77 | +} |
0 commit comments