import React, { memo } from 'react'; import { View, TouchableOpacity, Text, Image, type ImageSourcePropType } from 'react-native'; import { MONTHS, toPersian } from '../utils'; import type { THeader } from './types'; import { DEFAULT_PROPS } from '../props'; const Header = memo( ({ mode, containerStyle, changeModeTo, yearMonthTextStyle, iconContainerStyle, backIcon, backIconStyle, year, month, nextIcon, nextIconStyle, decreaseYear, increaseYear, decreaseMonth, increaseMonth, minYear, maxYear, minMonth, maxMonth, yearMonthBoxStyle, isShowMonthLabel, }: THeader) => { const renderIcon = (icon: ImageSourcePropType | undefined, isBack = false) => { if (mode === 'year') { return null; } const disabled = () => { if (mode === 'month') { return isBack ? year <= minYear : year >= maxYear; } return isBack ? year === minYear && month <= minMonth : year === maxYear && month >= maxMonth; }; const onBackIconPress = () => { if (mode === 'month') { return decreaseYear(); } decreaseMonth(); }; const onNextIconPress = () => { if (mode === 'month') { return increaseYear(); } increaseMonth(); }; return ( ); }; const renderTitle = () => { if (mode === 'calendar') { return ( {`${isShowMonthLabel ? MONTHS[month] : toPersian(String(month))}، ${toPersian(String(year))}`} ); } return {toPersian(String(year))}; }; const onYearMonthPress = () => { if (mode === 'calendar') { return changeModeTo('month'); } return changeModeTo(mode === 'year' ? 'month' : 'year'); }; return ( {renderIcon(backIcon, true)} {renderTitle()} {renderIcon(nextIcon)} ); }, ); export default Header;