"use client"; import React, { FC } from "react"; import { Avatar, Dropdown, Sidebar, Tooltip } from "flowbite-react"; import { useEffect, useState } from "react"; import classNames from "classnames"; import { HiAdjustments, HiCog } from "react-icons/hi"; import { css } from "@emotion/css"; import { FaAngleUp, FaChevronDown, FaChevronUp } from "react-icons/fa"; import { SidebarLinkBetter } from "../ui/link-better"; import { detectCase } from "@/lib/utils/detectCase"; import { useLocal } from "@/lib/utils/use-local"; import { get_user } from "@/lib/utils/get_user"; import { siteurl } from "@/lib/utils/siteurl"; import { ScrollArea } from "../ui/scroll-area"; interface TreeMenuItem { title: string; href?: string; children?: TreeMenuItem[]; icon?: any; } interface TreeMenuProps { data: TreeMenuItem[]; minimaze: () => void; mini: boolean; } const SidebarTree: React.FC = ({ data, minimaze, mini }) => { const [currentPage, setCurrentPage] = useState(""); const local = useLocal({ data: data, ready: false as boolean, }); useEffect(() => { if (typeof location === "object") { const newPage = window.location.pathname; setCurrentPage(newPage); } const run = async () => { local.ready = false; local.render(); setTimeout(() => { local.ready = true; local.render(); }, 1000); }; if (typeof window === "object") { run(); } }, []); const isChildActive = (items: TreeMenuItem[]): boolean => { return items.some((item) => { if (item.href && currentPage.startsWith(item.href)) return true; if (item.children) return isChildActive(item.children); // Rekursif return false; }); }; const renderTree = (items: TreeMenuItem[], depth: number = 0) => { return items.map((item, index) => { const hasChildren = item.children && item.children.length > 0; let isActive = item.href && detectCase(currentPage, item.href); let isParentActive = hasChildren && isChildActive(item.children!); const [isOpen, setIsOpen] = useState(isParentActive); useEffect(() => { if (isParentActive) { setIsOpen(true); } }, [isParentActive]); const itemStyle = { paddingLeft: !hasChildren && !depth ? "13px" : !mini ? `${depth * 16}px` : "0px", }; return ( {hasChildren ? (
  • {false && (
    )}
    { if (mini) { minimaze(); } setIsOpen(!isOpen); }} style={itemStyle} >
    {!depth ? (
    {item.icon}
    ) : ( <> )} {!mini ? ( <>
    {item.title}
    {isOpen ? : }
    ) : ( <> )}
    {false && (
    )}
    {renderTree(item.children!, depth + 1)}
  • ) : (
  • {false && (
    )} { if (item?.href) setCurrentPage(item.href); }} className={classNames( "relative flex-row flex items-center cursor-pointer items-center w-full rounded-full rounded-r-none text-base text-gray-900 flex flex-row py-2.5 px-4", isActive ? " py-2.5 px-4 text-base rounded-full rounded-r-none group " : " font-normal", mini ? "transition-all duration-200" : "", isActive ? !depth ? " bg-layer font-normal vertical-rounded-tab" : " bg-layer text-primary font-bold vertical-rounded-tab" : "text-white", !depth && !hasChildren ? "px-2" : "", css` & > span { white-space: wrap !important; } `, mini ? "px-0 py-2" : "" )} style={itemStyle} // Terapkan gaya berdasarkan depth >
    {!depth ? (
    {item.icon}
    ) : ( <> )} {!mini ? ( <>
    {item.title}
    ) : ( <> )}
    {false && (
    )}
  • )}
    ); }); }; return (
    div { border-radius: 0px; background: transparent; padding-top: 0; padding-right: 0; } ` )} >
    {renderTree(data)}
    {!mini && "Notifications"}
    {!mini && "Sign Out"}
    {!mini && (
    {get_user("employee.name") ? get_user("employee.name") : "-"}
    )}
    ); }; const BottomMenu: FC = function () { return (
    Settings page
    ); }; const LanguageDropdown: FC = function () { return ( Current language } > ); }; export default SidebarTree;