"use client"; import colors from "@/con/colors"; import navbarListMenu from "@/con/navbar-list-menu"; import stateNav from "@/state/state-nav"; import { ActionIcon, Box, Burger, Group, Image, Paper, ScrollArea, Stack, Text, Tooltip } from "@mantine/core"; import { IconSquareArrowRight } from "@tabler/icons-react"; import { motion } from "framer-motion"; import { usePathname, useRouter } from "next/navigation"; import { useSnapshot } from "valtio"; import { MenuItem } from "../../../../types/menu-item"; import { NavbarMainMenu } from "./NavbarMainMenu"; export function Navbar() { const { item, isSearch, mobileOpen } = useSnapshot(stateNav); const router = useRouter(); return ( {/* Desktop navbar (muncul mulai 992px ke atas) */} {/* Mobile navbar (muncul di bawah 992px, termasuk iPad Mini) */} { router.push("/darmasaba"); stateNav.mobileOpen = false; }} > Village Logo (stateNav.mobileOpen = !stateNav.mobileOpen)} size="sm" /> {mobileOpen && ( )} {(item || isSearch) && } ); } function NavbarMobile({ listNavbar }: { listNavbar: MenuItem[] }) { const router = useRouter(); const pathname = usePathname(); // 👈 untuk cek path aktif // fungsi bantu: cek apakah path sekarang sama dengan menu / sub-menu const isActive = (href?: string) => href && pathname.startsWith(href); return ( {listNavbar.map((item, k) => { const active = isActive(item.href); return ( { if (item.href) { router.push(item.href); stateNav.mobileOpen = false; } }} style={{ cursor: item.href ? "pointer" : "default", transition: "background 0.15s ease", borderLeft: active ? `4px solid ${colors['blue-button']}` : "4px solid transparent", }} > {item.name} {item.href && ( )} {/* Submenu */} {item.children && ( {item.children.map((child, j) => { const childActive = isActive(child.href); return ( { if (child.href) { router.push(child.href); stateNav.mobileOpen = false; } }} style={{ cursor: child.href ? "pointer" : "default", opacity: child.href ? 1 : 0.8, borderRadius: "0.5rem", backgroundColor: childActive ? colors["blue-button-2"] : "transparent", borderLeft: childActive ? `3px solid ${colors['blue-button']}` : "3px solid transparent", transition: "background 0.15s ease", }} > {child.name} ); })} )} ); })} ); }