'use client' import type { MainNavItem, MainNavProps } from './types' import { cn } from '@langgenius/dify-ui/cn' import { useSuspenseQuery } from '@tanstack/react-query' import { useAtomValue } from 'jotai' import { useMemo, useRef } from 'react' import { useTranslation } from 'react-i18next' import Badge from '@/app/components/base/badge' import { DifyLogo } from '@/app/components/base/logo/dify-logo' import EnvNav from '@/app/components/header/env-nav' import StepByStepTourMount from '@/app/components/step-by-step-tour/mount' import { useProviderContextSelector } from '@/context/provider-context' import { isCurrentWorkspaceDatasetOperatorAtom } from '@/context/workspace-state' import { userProfileQueryOptions } from '@/features/account-profile/client' import { isAgentV2Enabled } from '@/features/agent-v2/feature-flag' import { useCanManageAgents } from '@/features/agent-v2/permissions' import { useCanViewSkills } from '@/features/skills/permissions' import { systemFeaturesQueryOptions } from '@/features/system-features/client' import dynamic from '@/next/dynamic' import Link from '@/next/link' import { usePathname } from '@/next/navigation' import AccountSection from './components/account-section' import HelpMenu from './components/help-menu' import MainNavLink from './components/nav-link' import { MainNavSearchButton } from './components/search-button' import { WorkspaceCard } from './components/workspace-card' import { isMainNavRouteVisible, MAIN_NAV_ROUTES } from './routes' const WebAppsSection = dynamic(() => import('./components/web-apps-section'), { ssr: false }) export function MainNav({ className }: MainNavProps) { const { t } = useTranslation() const pathname = usePathname() const isCurrentWorkspaceDatasetOperator = useAtomValue(isCurrentWorkspaceDatasetOperatorAtom) const { data: systemFeatures } = useSuspenseQuery(systemFeaturesQueryOptions()) const { data: currentEnv } = useSuspenseQuery({ ...userProfileQueryOptions(), select: (data) => data.meta.currentEnv, }) const agentV2Enabled = isAgentV2Enabled() const canManageAgents = useCanManageAgents() const canViewSkills = useCanViewSkills() const enableSkill = useProviderContextSelector((state) => state.enableSkill) const showEnvTag = currentEnv === 'TESTING' || currentEnv === 'DEVELOPMENT' const helpMenuTriggerRef = useRef(null) const navItems = useMemo( () => MAIN_NAV_ROUTES.filter((route) => isMainNavRouteVisible(route, { agentV2Enabled, canManageAgents, canViewSkills, isCurrentWorkspaceDatasetOperator, marketplaceEnabled: systemFeatures.enable_marketplace, skillEnabled: enableSkill, }), ).map((route) => ({ href: route.href, label: 'label' in route ? route.label : t(($) => $[route.labelKey], { ns: 'common' }), active: route.active, icon: route.icon, activeIcon: route.activeIcon, })), [ agentV2Enabled, canManageAgents, canViewSkills, enableSkill, isCurrentWorkspaceDatasetOperator, systemFeatures.enable_marketplace, t, ], ) const renderLogo = () => { const appTitle = systemFeatures.branding.enabled && systemFeatures.branding.application_title ? systemFeatures.branding.application_title : 'Dify' return ( {systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo ? ( ) : ( )} ) } return ( ) }