"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 PoldaLogo from "./polda-logo"; import { DynamicLogoPolda } from "./dynamic-logo-polda"; 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"); let prefixPath = poldaName ? `/polda/${poldaName}` : satkerName ? `/satker/${satkerName}` : "/"; let menu = ""; const onLogout = () => { Object.keys(Cookies.get()).forEach((cookieName) => { Cookies.remove(cookieName); }); window.location.href = "/"; }; // 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]); return (
Media Hub Logo {/* Nav Menu */}
{t("content")} router.push(prefixPath + "/image/filter")} className="flex place-items-start gap-1 px-3 py-1 w-36">

{t("image")}

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

{t("video")}

) : ( <>

{t("video")}

)}
router.push(prefixPath + "/document/filter")} className="flex place-items-start gap-1 py-1 px-3">

{t("text")}

router.push(prefixPath + "/audio/filter")} className="flex place-items-start gap-1 py-1 px-3 ">

{t("audio")}{" "}

{t("schedule")} {t("index")}
{/* Mobile Menu Toggle */} {/* Desktop Navigation */}
{roleId == undefined ? ( "" ) : (

Raw Data

)} {/* {t("live")} */} {/* Languange */}
{/* Dark Mode */}
{/* setOnSearch(e.target.value)} onKeyPress={() => router.push(`/all/filter?title=${onSearch}`)} type="text" placeholder={t("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")} setIsMessageActive(false)} > {t("update")}({notificationsUpdate?.length}) {detail !== undefined ? (
{"Image"}
{detail?.fullname}

({detail?.fullname})

) : ( "" )}
{[ { name: t("profileSetting"), icon: "heroicons:user", href: "/profile", }, { name: t("contentManagement"), 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")} setIsMessageActive(false)} > {t("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")}

{t("categoryReg")}

{t("selectOne")}

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

{t("image")}

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

{t("video")}

) : ( <>

{t("video")}

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

{t("text")}

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

{t("audio")}{" "}

{t("schedule")} {t("index")}
{roleId == undefined ? ( "" ) : (

Raw Data

)} {/*
Live
*/}
{/* Tombol Utama Bahasa */} {/* Dropdown Menu {isOpen && (
)} */}
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})`}

{t("profile")} {t("contentManagement")}
) : ( <> {t("logIn")}

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")} setIsMessageActive(false)} > {t("update")}({notificationsUpdate?.length}) {detail !== undefined ? (
{"Image"}
{detail?.fullname}

({detail?.fullname})

) : ( "" )}
{[ { name: t("profileSetting"), icon: "heroicons:user", href: "/profile", }, { name: t("contentManagement"), 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")} setIsMessageActive(false)} > {t("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")}

{t("categoryReg")}

{t("selectOne")}

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