"use client"; import { useEffect, useState } from "react"; import { Button } from "@heroui/button"; import { BreadcrumbItem, Breadcrumbs } from "@heroui/react"; import { usePathname, useRouter } from "next/navigation"; import { Image } from "@heroui/react"; import { BurgerButtonIcon, FormLayoutIcon } from "../icons"; import { ArticleIcon, DashboardIcon, MagazineIcon, MasterCategoryIcon, MasterRoleIcon, MasterUsersIcon, MenuBurgerIcon, StaticPageIcon, } from "../icons/sidebar-icon"; import { useSidebar } from "../layout/sidebar/sidebar-context"; export const Breadcrumb = () => { const [currentPage, setCurrentPage] = useState(""); const router = useRouter(); const pathname = usePathname(); const pathnameSplit = pathname.split("/"); const { isOpen, toggleSidebar } = useSidebar(); pathnameSplit.shift(); let pathnameTransformed = pathnameSplit.map((item) => { let words = item.split("-"); let capitalizedWords = words.map( (word) => word.charAt(0).toUpperCase() + word.slice(1) ); return capitalizedWords.join(" "); }); useEffect(() => { setCurrentPage(pathnameSplit[pathnameSplit.length - 1]); }, [pathnameSplit]); const handleAction = (key: any) => { const keyIndex = pathnameSplit.indexOf(key); const combinedPath = pathnameSplit.slice(0, keyIndex + 1).join("/"); router.push("/" + combinedPath); }; return (

{pathnameTransformed[pathnameTransformed.length - 1]}

handleAction(key)} > {pathnameTransformed?.map( (item, index) => item !== "Admin" && ( {item} ) )}
{!isOpen && ( )}
{pathname.includes("dashboard") && } {pathname.includes("article") && } {pathname.includes("master-category") && ( )} {pathname.includes("magazine") && } {pathname.includes("static-page") && } {pathname.includes("master-user") && } {pathname.includes("master-role") && } {/* */}
); };