import React from "react"; // headless ui import { Popover, Transition } from "@headlessui/react"; // ui import { CustomMenu, ToggleSwitch } from "components/ui"; // icons import { CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, } from "@heroicons/react/24/outline"; // helpers import { addMonths, addSevenDaysToDate, formatDate, getCurrentWeekEndDate, getCurrentWeekStartDate, isSameMonth, isSameYear, lastDayOfWeek, startOfWeek, subtract7DaysToDate, subtractMonths, updateDateWithMonth, updateDateWithYear, } from "helpers/calendar.helper"; // constants import { MONTHS_LIST, YEARS_LIST } from "constants/calendar"; type Props = { isMonthlyView: boolean; setIsMonthlyView: React.Dispatch>; currentDate: Date; setCurrentDate: React.Dispatch>; showWeekEnds: boolean; setShowWeekEnds: React.Dispatch>; changeDateRange: (startDate: Date, endDate: Date) => void; }; export const CalendarHeader: React.FC = ({ setIsMonthlyView, isMonthlyView, currentDate, setCurrentDate, showWeekEnds, setShowWeekEnds, changeDateRange, }) => { const updateDate = (date: Date) => { setCurrentDate(date); changeDateRange(startOfWeek(date), lastDayOfWeek(date)); }; return (
{({ open }) => ( <>
{formatDate(currentDate, "Month")}{" "} {formatDate(currentDate, "yyyy")}
{YEARS_LIST.map((year) => ( ))}
{MONTHS_LIST.map((month) => ( ))}
)}
{isMonthlyView ? "Monthly" : "Weekly"}
} > { setIsMonthlyView(true); changeDateRange(startOfWeek(currentDate), lastDayOfWeek(currentDate)); }} className="w-52 text-sm text-brand-secondary" >
Monthly View
{ setIsMonthlyView(false); changeDateRange( getCurrentWeekStartDate(currentDate), getCurrentWeekEndDate(currentDate) ); }} className="w-52 text-sm text-brand-secondary" >
Weekly View

Show weekends

setShowWeekEnds(!showWeekEnds)} />
); }; export default CalendarHeader;