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

import { useTournamentPopup } from './hooks'

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

const TournamentPopupContext = createContext({} as Context)

export const TournamentPopupStore = ({ children }: Props) => {
  const value = useTournamentPopup()
  return (
    <TournamentPopupContext.Provider value={value}>
      {children}
    </TournamentPopupContext.Provider>
  )
}

export const useTournamentPopupStore = () => useContext(TournamentPopupContext)
