import { forwardRef, useState } from 'react' import { ArrowLeft, ChevronDown } from 'lucide-react' import Block from '../Primitives/Block/Block' import PrimitiveButton from '../Primitives/PrimitiveButton/PrimitiveButton' import Text from '../Text/Text' import type { TopbarProps } from './types' import { useBreakpoints } from '../../hooks/useBreakPoints' import { SingleSelect } from '../SingleSelect' import { SelectMenuSize, SelectMenuVariant } from '../Select/types' import { useComponentToken } from '../../context/useComponentToken' import type { ResponsiveTopbarTokens } from './topbar.tokens' import { BREAKPOINTS } from '../../breakpoints/breakPoints' import Seperator from '../common/Seperator' import { FOUNDATION_THEME } from '../../tokens' /** * Helper to check if Topbar is in controlled mode */ const isControlledTopbar = (isVisible: boolean | undefined): boolean => { return isVisible !== undefined } const Topbar = forwardRef( ( { children, isExpanded, isVisible: controlledIsVisible, // @ts-expect-error - onVisibilityChange is part of the controlled API but not used internally // eslint-disable-next-line @typescript-eslint/no-unused-vars onVisibilityChange, defaultIsVisible = true, sidebarTopSlot, topbar, leftAction, rightActions, showBackButton = false, onBackClick, leftPanel, merchantInfo, }, ref ) => { const isControlled = isControlledTopbar(controlledIsVisible) const [internalVisible] = useState(defaultIsVisible) const isVisible = isControlled ? controlledIsVisible! : internalVisible const { innerWidth } = useBreakpoints() const isMobile = innerWidth < BREAKPOINTS.lg const tokens = useComponentToken('TOPBAR') as ResponsiveTopbarTokens const topBarToken = isMobile ? tokens.sm : tokens.lg if (!isVisible) { return null } if (isMobile) { const renderLeftSection = () => { if (leftAction) { return leftAction } if (showBackButton) { return ( ) } return ( {leftPanel && leftPanel.items && leftPanel.items.length > 0 && ( ({ label: tenant.label, value: tenant.value || tenant.label, slot1: tenant.icon, }) ), }, ]} selected={leftPanel.selected} onSelect={leftPanel.onSelect} customTrigger={ } /> )} {leftPanel && leftPanel.items && leftPanel.items.length > 0 && merchantInfo && ( / )} {merchantInfo && ( ({ label: merchant.label, value: merchant.value, slot1: merchant.icon, }) ), }, ]} selected={merchantInfo.selected} onSelect={merchantInfo.onSelect} customTrigger={ merchant.value === merchantInfo.selected )?.label || 'Select Merchant' }`} > {merchantInfo.items.find( (merchant) => merchant.value === merchantInfo.selected )?.icon && ( )} {merchantInfo.items.find( (merchant) => merchant.value === merchantInfo.selected )?.label || 'Select Merchant'} } /> )} ) } return ( {renderLeftSection()} {rightActions} ) } return ( {!isExpanded && sidebarTopSlot} {!isExpanded && ( )} {topbar || children} ) } ) Topbar.displayName = 'Topbar' export default Topbar