"use client";

import React, { createContext, useContext, useState, ReactNode } from "react";

/**
 * 대시보드 위젯 간 데이터 공유를 위한 Context
 * - 달력에서 날짜 선택 시 할일/긴급지시 위젯에 전달
 */

interface DashboardContextType {
  selectedDate: Date | null;
  setSelectedDate: (date: Date | null) => void;
}

const DashboardContext = createContext<DashboardContextType | undefined>(undefined);

export function DashboardProvider({ children }: { children: ReactNode }) {
  const [selectedDate, setSelectedDate] = useState<Date | null>(null);

  return (
    <DashboardContext.Provider value={{ selectedDate, setSelectedDate }}>
      {children}
    </DashboardContext.Provider>
  );
}

export function useDashboard() {
  const context = useContext(DashboardContext);
  if (context === undefined) {
    throw new Error("useDashboard must be used within a DashboardProvider");
  }
  return context;
}

