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

import { useMatchPopup } from './hooks'

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

const MatchPopupContext = createContext({} as Context)

export const MatchPopupStore = ({ children }: Props) => {
  const value = useMatchPopup()
  return (
    <MatchPopupContext.Provider value={value}>
      {children}
    </MatchPopupContext.Provider>
  )
}

export const useMatchPopupStore = () => useContext(MatchPopupContext)
