import type { ReactNode } from 'react'
import { useContext, createContext } from 'react'

import { useFilters } from './hooks'

export * from './hooks'

type Context = ReturnType<typeof useFilters>

const FiltersContext = createContext({} as Context)

type Props = { children: ReactNode }

export const HeaderFiltersStore = ({ children }: Props) => {
  const filters = useFilters()
  return (
    <FiltersContext.Provider value={filters}>
      {children}
    </FiltersContext.Provider>
  )
}

export const useHeaderFiltersStore = () => useContext(FiltersContext)
