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

import { useMatchSwitches } from './hooks'

type SwitchStore = ReturnType<typeof useMatchSwitches>

type Props = { children: ReactNode }

const Context = createContext({} as SwitchStore)

export const MatchSwitchesStore = ({ children }: Props) => {
  const value = useMatchSwitches()

  return (
    <Context.Provider value={value}>
      {children}
    </Context.Provider>
  )
}

export const useMatchSwitchesStore = () => useContext(Context)
