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

interface UIContextType {
  isAddOrgWizardOpen: boolean;
  openAddOrgWizard: () => void;
  closeAddOrgWizard: () => void;
}

export const UIContext = createContext<UIContextType | undefined>(undefined);

export const UIProvider = ({ children }: { children?: ReactNode }) => {
  const [isAddOrgWizardOpen, setIsAddOrgWizardOpen] = useState(false);

  const openAddOrgWizard = useCallback(() => setIsAddOrgWizardOpen(true), []);
  const closeAddOrgWizard = useCallback(() => setIsAddOrgWizardOpen(false), []);

  const value = useMemo(
    () => ({
      isAddOrgWizardOpen,
      openAddOrgWizard,
      closeAddOrgWizard,
    }),
    [isAddOrgWizardOpen, openAddOrgWizard, closeAddOrgWizard]
  );

  return <UIContext.Provider value={value}>{children}</UIContext.Provider>;
};
