import { useContext } from 'react';
import { ToolbarCollectionContext } from '../components/ToolbarCollectionContext';
import type { Filter } from '@wix/bex-core';

export interface FilterToolbarState {
  getPendingFilter<A>(filter: A): A | Filter<any>;
}

const fallbackState: FilterToolbarState = {
  getPendingFilter: (filter) => filter,
};

export function useFilterToolbarState(): FilterToolbarState {
  const value = useContext(ToolbarCollectionContext);

  if (value == null) {
    return fallbackState;
  }

  return value;
}
