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

interface DashboardContextType {
  period: string;
  setPeriod: (period: string) => void;
  useDummyData: boolean;
  setUseDummyData: (use: boolean) => void;
}

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

export function DashboardProvider({ children }: { children: ReactNode }) {
  const [period, setPeriod] = useState('30');
  const [useDummyData, setUseDummyData] = useState(false); // Default to real data

  return (
    <DashboardContext.Provider value={{ period, setPeriod, useDummyData, setUseDummyData }}>
      {children}
    </DashboardContext.Provider>
  );
}

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