"use client";

import { createContext, useContext, type ReactNode } from "react";
import { useCalendar, type UseCalendarReturn } from "@/hooks/useCalendar";

const CalendarContext = createContext<UseCalendarReturn | null>(null);

export function CalendarProvider({ children }: { children: ReactNode }) {
  const calendar = useCalendar();
  return (
    <CalendarContext.Provider value={calendar}>
      {children}
    </CalendarContext.Provider>
  );
}

export function useCalendarContext(): UseCalendarReturn {
  const ctx = useContext(CalendarContext);
  if (!ctx) throw new Error("useCalendarContext must be used within CalendarProvider");
  return ctx;
}
