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

type TabId = 'docs' | 'compliance' | 'status' | 'rag';

interface AppContextValue {
  activeTab: TabId;
  setActiveTab: (tab: TabId) => void;
}

const AppContext = createContext<AppContextValue | undefined>(undefined);

export const useApp = (): AppContextValue => {
  const context = useContext(AppContext);
  if (!context) {
    throw new Error('useApp must be used within an AppProvider');
  }
  return context;
};

interface AppProviderProps {
  children: ReactNode;
}

export const AppProvider: React.FC<AppProviderProps> = ({ children }) => {
  const [activeTab, setActiveTab] = useState<TabId>('compliance');

  return (
    <AppContext.Provider value={{ activeTab, setActiveTab }}>
      {children}
    </AppContext.Provider>
  );
};