import { useMemo } from "react"; import dayjs from "@calcom/dayjs"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Button, ButtonGroup } from "@calcom/ui"; import { useTroubleshooterStore } from "../store"; export function TroubleshooterHeader({ extraDays, isMobile }: { extraDays: number; isMobile: boolean }) { const { t, i18n } = useLocale(); const selectedDateString = useTroubleshooterStore((state) => state.selectedDate); const setSelectedDate = useTroubleshooterStore((state) => state.setSelectedDate); const addToSelectedDate = useTroubleshooterStore((state) => state.addToSelectedDate); const selectedDate = selectedDateString ? dayjs(selectedDateString) : dayjs(); const today = dayjs(); const selectedDateMin3DaysDifference = useMemo(() => { const diff = today.diff(selectedDate, "days"); return diff > 3 || diff < -3; }, [today, selectedDate]); if (isMobile) return null; const endDate = selectedDate.add(extraDays - 1, "days"); const isSameMonth = () => { return selectedDate.format("MMM") === endDate.format("MMM"); }; const isSameYear = () => { return selectedDate.format("YYYY") === endDate.format("YYYY"); }; const formattedMonth = new Intl.DateTimeFormat(i18n.language, { month: "short" }); const FormattedSelectedDateRange = () => { return (

{formattedMonth.format(selectedDate.toDate())} {selectedDate.format("D")} {!isSameYear() && , {selectedDate.format("YYYY")} }-{" "} {!isSameMonth() && formattedMonth.format(endDate.toDate())} {endDate.format("D")},{" "} {isSameYear() ? selectedDate.format("YYYY") : endDate.format("YYYY")}

); }; return (
)}
); }