"use client"; import { useEffect, useState } from "react"; import { usePathname, useRouter } from "next/navigation"; import { ArticleIcon, DashboardIcon, MagazineIcon, MasterCategoryIcon, MasterRoleIcon, MasterUsersIcon, StaticPageIcon, } from "../icons/sidebar-icon"; import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbSeparator, } from "../ui/breadcrumb"; import React from "react"; export const Breadcrumbs = () => { const [currentPage, setCurrentPage] = useState(""); const router = useRouter(); const pathname = usePathname(); const pathnameSplit = pathname.split("/"); pathnameSplit.shift(); const pathnameTransformed = pathnameSplit.map((item) => { const words = item.split("-"); const capitalizedWords = words.map( (word) => word.charAt(0).toUpperCase() + word.slice(1) ); return capitalizedWords.join(" "); }); console.log("pathname : ", pathnameTransformed); 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]}

{pathnameTransformed ?.filter((item) => item !== "Admin") .map((item, index, array) => ( handleAction(pathnameSplit[index])} className={ pathnameSplit[index] === currentPage ? "font-semibold" : "" } > {item} {index < array.length - 1 && } ))}
{/*
{!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") && } {/* */}
); };