import React, { memo, useMemo } from 'react'; import { View, StyleSheet, Text, useColorScheme } from 'react-native'; import { useCalendarContext } from '../../calendar-context'; import type { HeaderProps, NavigationProps } from './types'; import PrevButton from './prev-button'; import NextButton from './next-button'; import ViewToggle from './time-view-toggle'; import Selectors from './selectors'; import { isEqual } from 'lodash'; import { getYearRange } from '../../utils'; import { COLORS } from '../../theme'; const createDefaultStyles = (isRTL: boolean) => StyleSheet.create({ headerContainer: { paddingVertical: 3, }, container: { padding: 5, gap: 20, flexDirection: isRTL ? 'row-reverse' : 'row', alignItems: 'center', justifyContent: 'space-between', }, navigation: { flexDirection: isRTL ? 'row-reverse' : 'row', }, }); const NavigationButtons = ({ styles, classNames, isRTL }: NavigationProps) => { const style = useMemo(() => createDefaultStyles(isRTL), [isRTL]); return ( ); }; const Header: React.FC = () => { const { styles = {}, classNames = {}, isRTL, navigationPosition = 'center', yearPickerOnly, currentYear, minDate, maxDate, calendarView, showViewToggleHeader, } = useCalendarContext(); const colorScheme = useColorScheme(); const theme = (colorScheme ?? 'light') as 'light' | 'dark'; const style = useMemo(() => createDefaultStyles(isRTL), [isRTL]); // Show navigation/selectors based on mode const shouldShowNavigation = yearPickerOnly ? calendarView === 'year' : !(showViewToggleHeader && calendarView === 'time'); return ( {showViewToggleHeader && } {/* Year-only mode: show navigation with year range */} {yearPickerOnly && calendarView === 'year' && ( {(() => { const years = getYearRange(currentYear, minDate, maxDate); if (years.length === 0) return ''; return `${years[0]} - ${years[years.length - 1]}`; })()} )} {/* Normal mode: show full navigation/selectors */} {!yearPickerOnly && shouldShowNavigation && ( {navigationPosition === 'left' ? ( <> ) : navigationPosition === 'right' ? ( <> ) : ( <> )} )} ); }; const customComparator = ( prev: Readonly, next: Readonly ) => { const areEqual = prev.PrevIcon === next.PrevIcon && prev.NextIcon === next.NextIcon && prev.navigationPosition === next.navigationPosition && prev.isRTL === next.isRTL && isEqual(prev.styles, next.styles) && isEqual(prev.classNames, next.classNames); return areEqual; }; export default memo(Header, customComparator);