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

import { useExtendedSearch } from './hooks'

type Context = ReturnType<typeof useExtendedSearch>
type Props = { children: ReactNode }

const SearchContext = createContext({} as Context)

export const ExtendedSearchStore = ({ children }: Props) => {
  const value = useExtendedSearch()
  return <SearchContext.Provider value={value}>{children}</SearchContext.Provider>
}

export const useExtendedSearchStore = () => useContext(SearchContext)
