"use client"; import React, { useEffect, useState } from "react"; import ThemeSwitcher from "@/components/partials/header/theme-switcher"; import { FiFile, FiImage, FiMusic, FiYoutube } from "react-icons/fi"; import { useParams, usePathname } from "next/navigation"; import { generateLocalizedPath } from "@/utils/globals"; import { Link } from "@/i18n/routing"; import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, navigationMenuTriggerStyle, } from "@/components/ui/navigation-menu"; import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "../ui/dropdown-menu"; import Image from "next/image"; import { Icon } from "../ui/icon"; import { getCookiesDecrypt } from "@/lib/utils"; import Cookies from "js-cookie"; import { getInfoProfile } from "@/service/auth"; import { useTranslations } from "next-intl"; import { useRouter } from "@/i18n/routing"; import { Button } from "@/components/ui/button"; import LocalSwitcher from "../partials/header/locale-switcher"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { getUserNotifications, listRole } from "@/service/landing/landing"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { DynamicLogoPolda } from "./dynamic-logo-polda"; import { DynamicLogoSatker } from "./dynamic-logo-satker"; import { ChevronDown, ChevronUp } from "lucide-react"; type Detail = { id: number; userId: any; firstName: string; username: string; fullname: string; memberIdentity: any; email: string; address: string; phoneNumber: any; message: string; }; const Navbar = () => { const [menuOpen, setMenuOpen] = useState(false); const [inboxOpen, setInboxOpen] = useState(false); const router = useRouter(); const params = useParams(); const locale = params?.locale; const poldaName = params?.polda_name; const satkerName = params?.satker_name; const [language, setLanguage] = useState<"id" | "en">("id"); const [isOpen, setIsOpen] = useState(false); const fullname = getCookiesDecrypt("ufne"); const levelName = getCookiesDecrypt("ulnae"); const roleId = getCookiesDecrypt("urie"); const [detail, setDetail] = useState(); const t = useTranslations("LandingPage"); const [search, setSearch] = useState(""); const [onSearch, setOnSearch] = useState(""); const [debouncedSearch, setDebouncedSearch] = useState(""); const pathname = usePathname(); const [role, setRole] = useState(); const [menuActive, setMenuActive] = useState(); const [category, setCategory] = useState(); const [notifications, setNotifications] = useState([]); const [isMessageActive, setIsMessageActive] = useState(true); const [notificationsUpdate, setNotificationsUpdate] = useState([]); const [selectedTab, setSelectedTab] = useState("image"); const isHidden = pathname?.includes("polda") || pathname?.includes("satker"); let prefixPath = poldaName ? `/polda/${poldaName}` : satkerName ? `/satker/${satkerName}` : ""; let menu = ""; const onLogout = () => { Object.keys(Cookies.get()).forEach((cookieName) => { Cookies.remove(cookieName); }); window.location.href = "/"; }; // useEffect(() => { // if (!roleId) { // router.replace("/"); // Kalau roleId-nya belum tersedia, redirect juga (opsional) // return; // } // const token = Cookies.get(roleId); // if (!token) { // router.replace("/"); // Redirect ke halaman home jika tidak ada token // } // }, []); // const profilePicture = Cookies.get("profile_picture"); const fullName = getCookiesDecrypt("ufne"); const roleName = getCookiesDecrypt("urne"); const handleLanguageChange = (lang: "id" | "en") => { setLanguage(lang); setIsOpen(false); }; useEffect(() => { async function initState() { setMenuActive(menu); const res = await listRole(); setRole(res?.data?.data); } async function getNotif() { if (roleId != undefined) { const response = await getUserNotifications(0, 2); setNotifications(response?.data?.data?.content); console.log("respon:", response); } } async function getNotifUpdate() { if (roleId != undefined) { const response = await getUserNotifications(0, 3); setNotificationsUpdate(response?.data?.data?.content); console.log("Notiffff:", response); } } initState(); getNotif(); getNotifUpdate(); }, []); const test = () => { console.log(notifications); }; useEffect(() => { async function initState() { const response = await getInfoProfile(); if (!response?.error) { const details = response?.data?.data; setInboxOpen(details); setDetail(details); console.log("data", details); } } initState(); console.log("POldaaa : ", poldaName); console.log("Satkkeeer : ", satkerName); }, []); const handleChange = (e: any) => { setSearch(e.target.value); }; // const handleKeypress = (e: any) => { // if (e.which == 13) { // handleSearch(); // } // }; useEffect(() => { const handler = setTimeout(() => { if (onSearch.trim()) { setDebouncedSearch(onSearch); router.push(`/all/filter?title=${encodeURIComponent(onSearch)}`); } }, 3000); return () => clearTimeout(handler); }, [onSearch]); const [open, setOpen] = useState(false); return (
Media Hub Logo {/* Nav Menu */}
{/* Popover Utama */} router.push(prefixPath + "/image/filter")} className="flex items-center text-slate-600 dark:text-white hover:text-[#bb3523]" > {t("image", { defaultValue: "Image" })} router.push(prefixPath + "/video/filter")} className="flex items-center text-slate-600 dark:text-white hover:text-[#bb3523]" > {t("video", { defaultValue: "Video" })} router.push(prefixPath + "/document/filter")} className="flex items-center text-slate-600 dark:text-white hover:text-[#bb3523]" > {t("text", { defaultValue: "Text" })} router.push(prefixPath + "/audio/filter")} className="flex items-center text-slate-600 dark:text-white hover:text-[#bb3523]" > {t("audio", { defaultValue: "Audio" })} {/* Link Schedule */} {t("schedule", { defaultValue: "Schedule" })} {/* Link Index */} {t("index", { defaultValue: "Index" })}
{/* Desktop Navigation */}
{roleId == undefined ? ( "" ) : (

Raw Data

)} {/* {t("live", { defaultValue: "Live" })} */} {/* Languange */}
{/* Dark Mode */}
{/* setOnSearch(e.target.value)} onKeyPress={() => router.push(`/all/filter?title=${onSearch}`)} type="text" placeholder={t("search", { defaultValue: "Search" })} className="pl-8 pr-4 py-1 w-28 text-[13px] border rounded-full focus:outline-none dark:text-white" /> */} setOnSearch(e.target.value)} type="text" placeholder="Search..." className="pl-8 pr-4 py-1 w-28 text-[13px] border rounded-full focus:outline-none dark:text-white" />
{/*
{fullName ? ( <> avatar-profile

{fullName}

{`(${roleName})`}

Profile Kelola Konten Keluar
) : ( <> Masuk Daftar {" "} )}
*/} {roleId === "5" || roleId === "6" || roleId === "7" || roleId === "8" ? ( <> {/* Inbox */} test()}> {" "} setIsMessageActive(true)} > {t("inbox", { defaultValue: "Inbox" })} setIsMessageActive(false)} > {t("update", { defaultValue: "Update" })}( {notificationsUpdate?.length}) {detail !== undefined ? (
{"Image"}
{detail?.fullname}

({detail?.fullname})

) : ( "" )}
{[ { name: t("profileSetting", { defaultValue: "Profile Setting", }), icon: "heroicons:user", href: "/profile", }, { name: t("contentManagement", { defaultValue: "Content Management", }), icon: "stash:save-ribbon-duotone", href: "/content-management/galery", }, ].map((item, index) => ( {item.name} ))}
) : roleId === "2" || roleId === "3" || roleId === "4" || roleId === "9" || roleId === "10" || roleId === "11" || roleId === "12" || roleId === "13" ? ( <> {/* Inbox */} test()} > {" "} setIsMessageActive(true)} > {t("inbox", { defaultValue: "Inbox" })} setIsMessageActive(false)} > {t("update", { defaultValue: "Update" })}( {notificationsUpdate?.length}) {/* // Dropdown menu for roleId === 3 */} {detail !== undefined ? (
{"Image"}
{detail?.fullname}

({detail?.fullname})

) : ( "" )}
{[ { name: "Profile & Settings", icon: "heroicons:user", href: "/profile", }, { name: "Dashboard", icon: "material-symbols:dashboard", href: "/dashboard", }, ].map((item, index) => ( {item.name} ))}
) : ( // Masuk and Daftar buttons for roleId === null
{t("logIn", { defaultValue: "Log In" })}

{t("categoryReg", { defaultValue: "Category Reg" })}

{t("selectOne", { defaultValue: "Select One" })}

{role?.map((row: any) => (
setCategory(event.target.value)} />
))}
{t("next", { defaultValue: "Next" })}{" "}
)}
{/* Mobile Menu */} {menuOpen && (
{t("content", { defaultValue: "Content" })} router.push(prefixPath + "/image/filter")} className="flex place-items-start gap-1.5 p-2 w-36" >

{t("image", { defaultValue: "Image" })}

router.push(prefixPath + "/video/filter")} className="flex items-start gap-1.5 p-2 " > {pathname?.split("/")[1] == "in" ? ( <>

{t("video", { defaultValue: "Video" })}

) : ( <>

{t("video", { defaultValue: "Video" })}

)}
router.push(prefixPath + "/document/filter") } className="flex place-items-start gap-1.5 p-2" >

{t("text", { defaultValue: "Text" })}

router.push(prefixPath + "/audio/filter")} className="flex place-items-start gap-1.5 p-2 " >

{t("audio", { defaultValue: "Audio" })}{" "}

{t("schedule", { defaultValue: "Schedule" })} {t("index", { defaultValue: "Index" })}
{roleId == undefined ? ( "" ) : (

Raw Data

)} {/*
Live
*/} {/* Languange */}
{/* Tombol Utama Bahasa */} {/* Dropdown Menu {isOpen && (
)} */}
setOnSearch(e.target.value)} type="text" placeholder="Search..." className="pl-8 pr-4 py-1 text-[13px] border rounded-full focus:outline-none dark:text-white w-full " />{" "}
{/* {fullName ? ( <> avatar-profile

{fullName}

{`(${roleName})`}

{t("profile", { defaultValue: "Profile" })} {t("contentManagement", { defaultValue: "Content Management" })}
) : ( <> {t("logIn", { defaultValue: "Log In" })}

Kategori Registrasi

Silahkan pilih salah satu

{role?.map((row: any) => (
setCategory(event.target.value)} />
))}
Selanjutnya{" "}
)} */} {roleId === "5" || roleId === "6" || roleId === "7" || roleId === "8" ? ( <> {/* Inbox */} test()}> {" "} setIsMessageActive(true)} > {t("inbox", { defaultValue: "Inbox" })} setIsMessageActive(false)} > {t("update", { defaultValue: "Update" })}( {notificationsUpdate?.length}) {detail !== undefined ? (
{"Image"}
{detail?.fullname}

({detail?.fullname})

) : ( "" )}
{[ { name: t("profileSetting", { defaultValue: "Profile Setting", }), icon: "heroicons:user", href: "/profile", }, { name: t("contentManagement", { defaultValue: "Content Management", }), icon: "stash:save-ribbon-duotone", href: "/content-management/galery", }, ].map((item, index) => ( {item.name} ))}
) : roleId === "2" || roleId === "3" || roleId === "4" || roleId === "9" || roleId === "10" || roleId === "11" || roleId === "12" || roleId === "13" ? ( <> {/* Inbox */} test()}> {" "} setIsMessageActive(true)} > {t("inbox", { defaultValue: "Inbox" })} setIsMessageActive(false)} > {t("update", { defaultValue: "Update" })}( {notificationsUpdate?.length}) {/* // Dropdown menu for roleId === 3 */} {detail !== undefined ? (
{"Image"}
{detail?.fullname}

({detail?.fullname})

) : ( "" )}
{[ { name: "Profile & Settings", icon: "heroicons:user", href: "/profile", }, { name: "Dashboard", icon: "material-symbols:dashboard", href: "/dashboard", }, ].map((item, index) => ( {item.name} ))}
) : ( // Masuk and Daftar buttons for roleId === null
{t("logIn", { defaultValue: "Log In" })}

{t("categoryReg", { defaultValue: "Category Reg" })}

{t("selectOne", { defaultValue: "Select One" })}

{role?.map((row: any) => (
setCategory(event.target.value) } />
))}
{t("next", { defaultValue: "Next" })}{" "}
)}
)}
); }; export default Navbar;