import React, { useState, useEffect } from 'react'; import CalendarIcon from './icons/CalendarIcon'; import CardsIcon from './icons/CardsIcon'; import ListIcon from './icons/ListIcon'; import PrevIcon from './icons/PrevIcon'; import NextIcon from './icons/NextIcon'; interface CalendarNavigationProps { activeStartDate: Date; locale: string; selectedYear: number; goToPreviousMonth: () => void; goToCurrentMonth: () => void; goToNextMonth: () => void; handleMonthClick: (month: number) => void; handleYearChange: (event: React.ChangeEvent) => void; formatMonthYear: (date: Date) => string; view: 'calendar' | 'cards' | 'list'; setView: (view: 'calendar' | 'cards' | 'list') => void; showCalendar: boolean; showCards: boolean; showList: boolean; } const CalendarNavigation: React.FC = ({ activeStartDate, locale, selectedYear, goToPreviousMonth, goToCurrentMonth, goToNextMonth, handleMonthClick, handleYearChange, formatMonthYear, view, setView, showCalendar, showCards, showList }) => { const [isPopupActive, setIsPopupActive] = useState(false); const openPopup = () => { setIsPopupActive(true); }; const handleClickOutside = (event: MouseEvent) => { const target = event.target as HTMLElement; if (!target.closest('.fsdpe-calendar-wrapper__date-selector')) { setIsPopupActive(false); } }; const handleMonthClickAndClosePopup = (month: number) => { handleMonthClick(month); setIsPopupActive(false); }; useEffect(() => { document.addEventListener('click', handleClickOutside); return () => { document.removeEventListener('click', handleClickOutside); }; }, []); // Get the current month and year const currentMonth = new Date().getMonth(); // 0-based (Jan = 0, Feb = 1, ...) const currentYear = new Date().getFullYear(); // Check if the current month and year are different from activeStartDate const isNotCurrentMonth = activeStartDate.getMonth() !== currentMonth || activeStartDate.getFullYear() !== currentYear; return (
Month
{selectedYear}
{Array.from({ length: 12 }, (_, i) => ( ))}
View: {showCalendar && ( )} {showCards && ( )} {showList && ( )}

{formatMonthYear(activeStartDate)}

{isNotCurrentMonth && ( Go back to current month )}
); }; export default CalendarNavigation;