100 lines
3.4 KiB
TypeScript
100 lines
3.4 KiB
TypeScript
'use client'
|
|
|
|
import Image from "next/image";
|
|
import {Button} from "@/components/ui/button";
|
|
import {LogIn, LogOut} from "lucide-react";
|
|
import {cn} from "@/lib/utils";
|
|
import {SITE_TITLE} from "@/config/kfpaConfig";
|
|
import {TopMenuItem} from "@/config/menu.type";
|
|
import {usePathname} from "next/navigation";
|
|
|
|
interface HeaderProps {
|
|
topMenus: TopMenuItem[];
|
|
userName: string;
|
|
isAuthenticated: boolean;
|
|
onNavigate: (path: string) => void;
|
|
onLogin: () => void;
|
|
onLogout: () => void;
|
|
}
|
|
|
|
const Header = ({
|
|
topMenus,
|
|
userName,
|
|
isAuthenticated,
|
|
onNavigate,
|
|
onLogin,
|
|
onLogout,
|
|
}: HeaderProps) => {
|
|
const pathname = usePathname();
|
|
|
|
return (
|
|
<header className="app-header sticky top-0 z-40">
|
|
<div className="grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-4 px-4 h-16">
|
|
<div className="flex min-w-0 items-center gap-4">
|
|
<div className="flex items-center gap-2 cursor-pointer w-37 h-15 justify-center">
|
|
<Image
|
|
src="/head_logo.png"
|
|
alt="logo"
|
|
width={150}
|
|
height={90}
|
|
className="object-contain"
|
|
onClick={() => onNavigate("/safety-inspection")}
|
|
priority
|
|
/>
|
|
</div>
|
|
|
|
<nav className="flex min-w-0 items-center gap-3 ml-5 overflow-hidden">
|
|
{topMenus.map((topMenu) => {
|
|
const active = topMenu.match?.(pathname) ?? pathname === topMenu.path;
|
|
return (
|
|
<button
|
|
key={topMenu.id}
|
|
type="button"
|
|
onClick={() => onNavigate(topMenu.path)}
|
|
className={cn(
|
|
"relative h-8 inline-flex items-center font-bold transition-colors cursor-pointer",
|
|
"content-text-lg bg-transparent px-1",
|
|
active
|
|
? "text-header-primary"
|
|
: "text-header-secondary-hover"
|
|
)}
|
|
>
|
|
{topMenu.label}
|
|
</button>
|
|
);
|
|
})}
|
|
</nav>
|
|
</div>
|
|
<div className="flex items-center justify-center">
|
|
<h1 className="font-bold content-text-2xl text-header-color">{SITE_TITLE}</h1>
|
|
</div>
|
|
<div className="flex min-w-0 items-center justify-end gap-4">
|
|
{isAuthenticated && (
|
|
<span className="content-text-base text-header-color hidden max-w-40 truncate sm:inline font-bold">
|
|
{userName}
|
|
</span>
|
|
)}
|
|
<Button
|
|
className="gap-2 border border-transparent bg-green-600 text-white w-25 shadow-sm hover:bg-green-500 hover:text-white"
|
|
onClick={isAuthenticated ? onLogout : onLogin}
|
|
>
|
|
{isAuthenticated ? (
|
|
<>
|
|
<LogOut className="w-4 h-4" />
|
|
<span className="hidden sm:inline">{"로그아웃"}</span>
|
|
</>
|
|
) : (
|
|
<>
|
|
<LogIn className="w-4 h-4" />
|
|
<span className="hidden sm:inline">{"로그인"}</span>
|
|
</>
|
|
)}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
);
|
|
}
|
|
|
|
export default Header;
|