/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React from 'react'; import { Link, useLocation } from 'react-router-dom'; import { Dropdown } from '@/components/ui'; import { useTranslation } from 'react-i18next'; import SkeletonWrapper from '../components/SkeletonWrapper'; import { isNavigationPathActive } from '../../console/consoleRoutes'; const Navigation = ({ mainNavLinks, isMobile, isLoading, userState }) => { const location = useLocation(); const { t } = useTranslation(); const renderNavLinks = () => { const baseClasses = 'ui-header-nav-item flex-shrink-0 flex items-center gap-1.5 font-medium relative'; const defaultClasses = 'text-gray-600 dark:text-neutral-300'; const hoverClasses = 'hover:text-brand-deep dark:hover:text-brand-from'; const activeClasses = 'text-brand-deep dark:text-brand-from'; const spacingClasses = isMobile ? 'px-2 py-1 text-sm' : 'px-4 py-2'; // Match on full path segments so /market doesn't light up on /market-detail const isPathActive = (matchPath) => isNavigationPathActive(location.pathname, matchPath); return mainNavLinks.map((link) => { const linkContent = {link.text}; // Calculate target path for main link(未登录默认引导到企业登录) let targetPath = link.to; if (link.requireAuth && !userState.user) { targetPath = '/org/login'; } if (link.itemKey === 'console' && !userState.user) { targetPath = '/org/login'; } // Check if active let isActive = false; if (link.activePrefix) { isActive = isPathActive(link.activePrefix); } else if (link.items && link.items.length > 0) { isActive = link.items.some((subItem) => isPathActive(subItem.to)); } else if (!link.isExternal && targetPath) { isActive = isPathActive(link.activePrefix || targetPath); } const finalClasses = `${baseClasses} ${spacingClasses} ${isActive ? `nav-item-active ${activeClasses}` : `${defaultClasses} ${hoverClasses}`}`; if (link.items && link.items.length > 0) { return ( {link.items.map((subItem) => ( {subItem.text} ))} } >
{linkContent} {/* Dropdown arrow */}
); } if (link.isExternal && targetPath !== '/org/login') { return ( {linkContent} {/* External link icon */} ); } return ( {linkContent} ); }); }; return ( ); }; export default Navigation;