'use client' import type { ComponentType } from 'react' import type { IntegrationSection } from '@/app/components/integrations/routes' import { cn } from '@langgenius/dify-ui/cn' import Link from '@/next/link' import { buildIntegrationPath } from './routes' import { integrationSidebarActiveNavItemClassName, integrationSidebarDisabledNavItemClassName, integrationSidebarInactiveNavItemClassName, integrationSidebarNavItemClassName, } from './sidebar-nav-item-styles' type IconComponent = ComponentType<{ className?: string }> export type IntegrationSidebarNavItemData = { activeIcon?: IconComponent | string className?: string disabled?: boolean icon: IconComponent | string iconClassName?: string label: string section?: IntegrationSection } const renderIcon = (icon: IconComponent | string, className = 'size-4') => { if (typeof icon === 'string') return const Icon = icon return } type IntegrationSidebarNavItemProps = { item: IntegrationSidebarNavItemData onSelect?: (section: IntegrationSection) => void section: IntegrationSection } export function IntegrationSidebarNavItem({ item, onSelect, section, }: IntegrationSidebarNavItemProps) { const isActive = item.section === section const icon = isActive && item.activeIcon ? item.activeIcon : item.icon const className = cn( integrationSidebarNavItemClassName, isActive ? integrationSidebarActiveNavItemClassName : integrationSidebarInactiveNavItemClassName, item.className, ) if (!item.section) { return (
{renderIcon(item.icon, item.iconClassName)} {item.label}
) } const content = ( <> {renderIcon(icon, item.iconClassName)} {item.label} ) if (onSelect) { return ( ) } return ( {content} ) }