"use client"; import { useState, useEffect } from "react"; import { cn, getCookiesDecrypt } from "@/lib/utils"; import Image from "next/image"; import { Menu, ChevronDown } from "lucide-react"; import { Button } from "../ui/button"; import Cookies from "js-cookie"; import { Card } from "../ui/card"; import { Input } from "../ui/input"; import { usePathname, useRouter } from "next/navigation"; import { Link } from "@/i18n/routing"; import { DynamicLogoTenant } from "./dynamic-logo-tenant"; import { useTranslations } from "next-intl"; import LocalSwitcher from "../partials/header/locale-switcher"; export default function Navbar() { const t = useTranslations("Navbar"); const [isSidebarOpen, setIsSidebarOpen] = useState(false); const [isDropdownOpen, setDropdownOpen] = useState(false); const [showProfileMenu, setShowProfileMenu] = useState(false); const [isLoggedIn, setIsLoggedIn] = useState(false); const pathname = usePathname(); const router = useRouter(); const NAV_ITEMS = [ { label: t("home"), href: "/" }, { label: t("forYou"), href: "/for-you" }, { label: t("following"), href: "/auth" }, { label: t("publication"), href: "/publikasi" }, { label: t("schedule"), href: "/schedule" }, ]; const PUBLIKASI_SUBMENU = [ { label: "K/L", href: "/in/publication/kl" }, { label: "BUMN", href: "/in/publication/bumn" }, { label: t("localGov"), href: "/in/publication/pemerintah-daerah" }, ]; // 🔍 Fungsi cek login const checkLoginStatus = () => { const roleId = getCookiesDecrypt("urie"); const fullname = Cookies.get("ufne"); return roleId && fullname ? true : false; }; useEffect(() => { setIsLoggedIn(checkLoginStatus()); }, []); const filteredNavItems = isLoggedIn ? NAV_ITEMS.filter((item) => item.label !== t("following")) : NAV_ITEMS; // 🚪 Fungsi logout const handleLogout = () => { Object.keys(Cookies.get()).forEach((cookieName) => { Cookies.remove(cookieName, { path: "/" }); Cookies.remove(cookieName, { path: "", domain: window.location.hostname, }); Cookies.remove(cookieName, { path: "/", domain: window.location.hostname, }); }); setIsLoggedIn(false); setShowProfileMenu(false); window.location.href = "/"; }; const username = Cookies.get("username"); const fullname = Cookies.get("ufne"); return (
setIsSidebarOpen(true)} /> Logo
{/* 🌐 NAV MENU */} {/* 🔹 PROFILE / LOGIN SECTION */} {/* 📱 SIDEBAR MOBILE */} {isSidebarOpen && (

{t("language")}

{/* button language */}
{/*
*/}

{t("features")}

{NAV_ITEMS.map((item) => ( ))}
{t("about")} {t("advertising")} {t("contact")} {!isLoggedIn ? ( <> {t("login")} {t("register")} ) : ( )}

{t("subscribeTitle")}

setIsSidebarOpen(false)} />
)}
); }