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

export const ToolbarCollectionContext = createContext<ToolbarCollectionState<
  any,
  any
> | null>(null);

export const ToolbarCollectionProvider = ToolbarCollectionContext.Provider;
export const ToolbarCollectionConsumer = ToolbarCollectionContext.Consumer;

export const useToolbarCollectionContext = <T, F extends FiltersMap>() => {
  const value = useContext(ToolbarCollectionContext);
  assertContextValue('ToolbarCollectionProvider', value);
  return value as ToolbarCollectionState<T, F>;
};
