'use client';

import { createContext, useMemo, useState } from 'react';

type ContextType = {
  selectedDate: Date;
  setSelectedDate: (date: Date) => void;
};

export const DateContext = createContext<ContextType>({} as ContextType);

export function DateContextProvider({ children }: { readonly children: React.ReactNode }) {
  const [selectedDate, setSelectedDate] = useState(new Date());

  const value = useMemo(() => ({ selectedDate, setSelectedDate }), [selectedDate]);

  return <DateContext value={value}>{children}</DateContext>;
}
