import { useContext, useEffect, useState } from 'react' import { Link, useLocation } from 'react-router-dom' import { SubMenuContext } from '../contexts/contexts' import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/shadcn/ui/accordion" export const AccordionMenu = ({ title, to, isActive }) => { return ( {title} ) } export const SubMenu = () => { const { menuItems, activeLink } = useContext(SubMenuContext) const [openItems, setOpenItems] = useState([]) const location = useLocation() useEffect(() => { const newOpenItems = menuItems .map((item, index) => { if (item.subMenus && (item.subMenus.some(subItem => subItem.to === location.pathname) || openItems.includes(`item-${index}`))) { return `item-${index}`; } return null; }) .filter(Boolean); setOpenItems(newOpenItems); }, [location, menuItems]); const handleAccordionChange = (value) => { setOpenItems(value); }; return ( <> {menuItems.map((item, index) => { const isActive = activeLink === item.to || (item.subMenus && item.subMenus.some(subItem => subItem.to === activeLink)) const combinedClassName = ` ${isActive ? `active !text-blue-400` : ''} ${item.className || ''} `.trim(); return ( // 메뉴 Data에 서브메뉴가 있을 시 아코디언 컴포넌트로 출력 item.subMenus && item.subMenus.length > 0 ? ( {Array.isArray(item.title) ? ( <> {item.title[0]} {item.title[1]} ) : ( item.title )}
{/* 아코디언 서브 메뉴 출력 */} {item.subMenus.map((el) => ( ))} {/* 아코디언 서브 메뉴 출력 END */}
) : ( // 서브메뉴가 없을 시 기본 메뉴로 출력 {Array.isArray(item.title) ? ( <> {item.title[0]} {item.title[1]} ) : ( item.title )} )) } ) } ) } const HeaderMenu = () => { return ( <>
{/* 상단 브랜드 로고 -- Page Header -- */}
) } export default HeaderMenu