import { SidebarMenuTask } from "@/types/globals"; import { Tooltip } from "@heroui/react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import React, { useEffect, useState } from "react"; import { ChevronLeftIcon, ChevronRightIcon, FormCustomIcon, FormHorizontalIcon, FormLayoutIcon, FormValidationIcon, FormVerticalIcon, } from "../../icons"; import { AddvertiseIcon, ArticleIcon, CommentIcon, DashboardIcon, HomeIcon, InfoCircleIcon, MagazineIcon, MasterCategoryIcon, MasterRoleIcon, MasterUserLevelIcon, MasterUsersIcon, MinusCircleIcon, StaticPageIcon, SuggestionsIcon, TableIcon, } from "../../icons/sidebar-icon"; import { ThemeSwitch } from "../../theme-switch"; import { SidebarCollapseItems } from "./sidebar-collapse-items"; import { SidebarCollapseSubItems } from "./sidebar-collapse-sub-items"; import { useSidebar } from "./sidebar-context"; import { SidebarMenu } from "./sidebar-menu"; import Image from "next/image"; import Cookies from "js-cookie"; import { SettingsIcon, UserProfileIcon } from "@/components/icons/globals"; import { getCookiesDecrypt, getUnixTimestamp } from "@/utils/global"; interface SubMenuItems { id: number; name: string; modulePathUrl: string; isSubActive: boolean; } interface MenuItems { id: number; name: string; modulePathUrl: string; isSubActive: boolean; childMenu?: SubMenuItems[]; icon?: string; } interface SidebarProps { sidebarData: boolean; updateSidebarData: (newData: boolean) => void; } const sidebarLevel3 = [ { id: 1, name: "Dashboard", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/dashboard", isGroup: true, parentId: -1, icon: "dashboard", position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 2, name: "Dashboard", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/dashboard", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 3, name: "Apps", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/basic", isGroup: true, parentId: -1, icon: "table", position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 4, name: "Artikel", moduleId: 652, moduleName: "Dashboard", modulePathUrl: `/admin/article?timestamp=${getUnixTimestamp()}`, parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 30, name: "Kategori", moduleId: 654, moduleName: "Master", modulePathUrl: `/admin/master-category?timestamp=${getUnixTimestamp()}`, parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, ]; const sidebarLevel2 = [ { id: 1, name: "Dashboard", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/dashboard", isGroup: true, parentId: -1, icon: "dashboard", position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 2, name: "Dashboard", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/dashboard", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 3, name: "Apps", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/basic", isGroup: true, parentId: -1, icon: "table", position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 4, name: "Artikel", moduleId: 652, moduleName: "Dashboard", modulePathUrl: `/admin/article?timestamp=${getUnixTimestamp()}`, parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 30, name: "Kategori", moduleId: 654, moduleName: "Master", modulePathUrl: `/admin/master-category?timestamp=${getUnixTimestamp()}`, parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 6, name: "Majalah", moduleId: 652, moduleName: "Apps", modulePathUrl: "/admin/magazine", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 33, name: "Advertise", moduleId: 652, moduleName: "Apps", modulePathUrl: "/admin/advertise", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 34, name: "Kritik & Saran", moduleId: 652, moduleName: "Apps", modulePathUrl: "/admin/feedbacks", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 35, name: "Komentar", moduleId: 652, moduleName: "Apps", modulePathUrl: "/admin/comment", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 5, name: "Master", moduleId: 652, moduleName: "Dashboard", isGroup: true, modulePathUrl: "/admin/basic", parentId: -1, icon: "table", position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 11, name: "Master Static Page", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/static-page", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 8, name: "Master User", moduleId: 654, moduleName: "Form Vertical", modulePathUrl: "/admin/master-user", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 23, name: "Master User Level", moduleId: 656, moduleName: "Form Validation", modulePathUrl: "/admin/user-level", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, ]; const sidebarLevel1 = [ { id: 1, name: "Dashboard", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/dashboard", isGroup: true, parentId: -1, icon: "dashboard", position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 2, name: "Dashboard", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/dashboard", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 3, name: "Apps", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/basic", isGroup: true, parentId: -1, icon: "table", position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 4, name: "Artikel", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/article", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 30, name: "Kategori", moduleId: 654, moduleName: "Master", modulePathUrl: "/admin/master-category", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 6, name: "Majalah", moduleId: 652, moduleName: "Apps", modulePathUrl: "/admin/magazine", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 33, name: "Advertise", moduleId: 652, moduleName: "Apps", modulePathUrl: "/admin/advertise", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 34, name: "Kritik & Saran", moduleId: 652, moduleName: "Apps", modulePathUrl: "/admin/feedbacks", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 35, name: "Komentar", moduleId: 652, moduleName: "Apps", modulePathUrl: "/admin/comment", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, // { // id: 4, // name: "E-Magazine", // moduleId: 652, // moduleName: "Dashboard", // modulePathUrl: "/admin/e-magazine", // parentId: -1, // icon: , // position: 1, // statusId: 1, // childMenu: [], // statusName: "Active", // childModule: null, // }, { id: 5, name: "Master", moduleId: 652, moduleName: "Dashboard", isGroup: true, modulePathUrl: "/admin/basic", parentId: -1, icon: "table", position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, // { // id: 6, // name: "Master Menu", // moduleId: 652, // moduleName: "Form Custom", // modulePathUrl: "/admin/master-menu", // parentId: -1, // icon: , // position: 1, // statusId: 1, // childMenu: [], // statusName: "Active", // childModule: null, // }, // { // id: 7, // name: "Master Module", // moduleId: 653, // moduleName: "Form Horizontal", // modulePathUrl: "/admin/master-module", // parentId: -1, // icon: , // position: 1, // statusId: 1, // childMenu: [], // statusName: "Active", // childModule: null, // }, { id: 11, name: "Master Static Page", moduleId: 652, moduleName: "Dashboard", modulePathUrl: "/admin/static-page", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 8, name: "Master User", moduleId: 654, moduleName: "Form Vertical", modulePathUrl: "/admin/master-user", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 10, name: "Master User Role", moduleId: 656, moduleName: "Form Validation", modulePathUrl: "/admin/master-role", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, { id: 23, name: "Master User Level", moduleId: 656, moduleName: "Form Validation", modulePathUrl: "/admin/user-level", parentId: -1, icon: , position: 1, statusId: 1, childMenu: [], statusName: "Active", childModule: null, }, ]; const SidebarMobile: React.FC = ({ updateSidebarData }) => { const pathname = usePathname(); const router = useRouter(); const [sidebarMenu, setSidebarMenu] = useState(); const { isOpen, toggleSidebar } = useSidebar(); const token = Cookies.get("access_token"); const username = getCookiesDecrypt("username"); const isAuthenticated = Cookies.get("is_authenticated"); const roles = getCookiesDecrypt("ulie"); const rolesId = getCookiesDecrypt("urie"); useEffect(() => { if (!token) { onLogout(); } }, [token]); const onLogout = () => { Object.keys(Cookies.get()).forEach((cookieName) => { Cookies.remove(cookieName); }); router.push("/auth"); }; useEffect(() => { updateSidebarData(isOpen); }, [isOpen]); return (
{!isOpen && (
)}
{/* {isOpen && ACME} */} {isOpen && ( )}
{rolesId === "1" ? sidebarLevel1?.map((list: any, index: number) => list.isGroup ? (

{isOpen ? list.name : "..."}

) : list.childMenu?.length < 1 ? ( isOpen ? (
{list.icon} {isOpen && list.name}
) : (
{list.icon} {isOpen && list.name}
) ) : ( ( )), ]} /> ) ) : rolesId === "2" ? sidebarLevel2?.map((list: any, index: number) => list.isGroup ? (

{isOpen ? list.name : "..."}

) : list.childMenu?.length < 1 ? ( isOpen ? (
{list.icon} {isOpen && list.name}
) : (
{list.icon} {isOpen && list.name}
) ) : ( ( )), ]} /> ) ) : sidebarLevel3?.map((list: any, index: number) => list.isGroup ? (

{isOpen ? list.name : "..."}

) : list.childMenu?.length < 1 ? ( isOpen ? (
{list.icon} {isOpen && list.name}
) : (
{list.icon} {isOpen && list.name}
) ) : ( ( )), ]} /> ) )}
{isOpen && "Theme"}
{isOpen ? (
{isOpen && "Settings"}
) : (
{isOpen && "Settings"}
)} {isOpen ? ( ) : ( )}
); }; export default SidebarMobile;