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 { TopbarV2Props } from './types' import { useBreakpoints } from '../../hooks/useBreakPoints' import { SingleSelect } from '../SingleSelect' import { SelectMenuSize, SelectMenuVariant } from '../Select/types' import { useComponentToken } from '../../context/useComponentToken' import type { ResponsiveTopbarV2Tokens } from './topbarV2.tokens' import { BREAKPOINTS } from '../../breakpoints/breakPoints' import Seperator from '../common/Seperator' const isControlledTopbarV2 = (isVisible: boolean | undefined): boolean => isVisible !== undefined const TopbarV2 = forwardRef( ( { children, isExpanded, isVisible: controlledIsVisible, onVisibilityChange, onToggleExpansion, showToggleButton, panelOnlyMode, ariaControls, defaultIsVisible = true, sidebarTopSlot, topbar, leftAction, rightActions, showBackButton = false, onBackClick, secondarySidebar, merchantInfo, }, ref ) => { const isControlled = isControlledTopbarV2(controlledIsVisible) const [internalVisible] = useState(defaultIsVisible) const isVisible = isControlled ? controlledIsVisible! : internalVisible // Preserve signature parity: these props are accepted for future // controlled-visibility UI but not yet wired to any internal trigger. void onVisibilityChange void onToggleExpansion void showToggleButton void panelOnlyMode void ariaControls const { innerWidth } = useBreakpoints() const isMobile = innerWidth < BREAKPOINTS.lg const tokens = useComponentToken('TOPBARV2') as ResponsiveTopbarV2Tokens const topBarToken = isMobile ? tokens.sm : tokens.lg if (!isVisible) return null if (isMobile) { const renderLeftSection = () => { if (leftAction) return leftAction if (showBackButton) { return ( ) } return ( {secondarySidebar?.items?.length ? ( ({ label: item.label, value: item.value, slot1: item.icon, }) ), }, ]} selected={secondarySidebar.selected} onSelect={secondarySidebar.onSelect} customTrigger={ } /> ) : null} {secondarySidebar?.items?.length && merchantInfo ? ( / ) : null} {merchantInfo ? ( ({ label: m.label, value: m.value, slot1: m.icon, })), }, ]} selected={merchantInfo.selected} onSelect={merchantInfo.onSelect} customTrigger={ m.value === merchantInfo.selected )?.label ?? 'Select Merchant' }`} > {merchantInfo.items.find( (m) => m.value === merchantInfo.selected )?.icon ? ( ) : null} {merchantInfo.items.find( (m) => m.value === merchantInfo.selected )?.label ?? 'Select Merchant'} } /> ) : null} ) } return ( {renderLeftSection()} {rightActions} ) } return ( {!isExpanded && sidebarTopSlot} {!isExpanded && sidebarTopSlot && (topbar || children) && ( )} {topbar || children} ) } ) TopbarV2.displayName = 'TopbarV2' export default TopbarV2