import { createContext, useContext } from 'react';
import { FiltersMap, MultiCollectionSupport } from '@wix/bex-core';
import { assertContextValue } from '../createContext';

export const MultiCollectionSupportContext =
  createContext<MultiCollectionSupport<any> | null>(null);

export const MultiCollectionSupportProvider =
  MultiCollectionSupportContext.Provider;
export const MultiCollectionSupportConsumer =
  MultiCollectionSupportContext.Consumer;

export const useMultiCollectionSupportContext = <F extends FiltersMap>() => {
  const value = useContext(MultiCollectionSupportContext);
  assertContextValue('MultiCollectionSupportProvider', value);
  return value as MultiCollectionSupport<F>;
};
