import { createContext, useContext } from "react"

const FilterTypeContext = createContext([])

export function useFilterTypes() {
  return useContext(FilterTypeContext)
}

const byType = type => filterType => filterType.type === type

export function useFilterType(type) {
  const filterTypes = useFilterTypes()
  return filterTypes.find(byType(type)).filter
}

export default FilterTypeContext
