import { createContext, type PropsWithChildren, useContext } from 'react';

type GoalFeaturesConfigContextValue = {
  isApprovalFlowEnabled: boolean;
  isBossCanEditPublishedObjectives: boolean;
};

const GoalFeaturesConfigContext = createContext<
  GoalFeaturesConfigContextValue | undefined
>(undefined);

export const GoalFeaturesConfigProvider = ({
  isApprovalFlowEnabled,
  isBossCanEditPublishedObjectives,
  children,
}: PropsWithChildren<GoalFeaturesConfigContextValue>) => {
  return (
    <GoalFeaturesConfigContext.Provider
      value={{ isApprovalFlowEnabled, isBossCanEditPublishedObjectives }}
    >
      {children}
    </GoalFeaturesConfigContext.Provider>
  );
};

export const useGoalFeaturesConfigContext =
  (): GoalFeaturesConfigContextValue =>
    useContext(GoalFeaturesConfigContext) ?? {
      isApprovalFlowEnabled: false,
      isBossCanEditPublishedObjectives: false,
    };
