import React, { useContext } from 'react';
import { ProviderContext, ProviderProps } from './types';

const Context = React.createContext<ProviderContext | Record<string, any>>({});
Context.displayName = 'ProviderContext';

export const Provider: React.FC<ProviderProps> = (props) => {
  const { mapBoxAPIToken, children } = props;
  const context = { mapBoxAPIToken };
  return <Context.Provider value={context}>{children}</Context.Provider>;
};

export function useProvider() {
  return useContext(Context);
}
