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

import { useNetwork } from './hooks'

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

const NoNetworkPopupContext = createContext({} as Context)

export const NoNetworkPopupStore = ({ children }: Props) => {
  const value = useNetwork()
  return (
    <NoNetworkPopupContext.Provider value={value}>
      {children}
    </NoNetworkPopupContext.Provider>
  )
}

export const useNoNetworkPopupStore = () => useContext(NoNetworkPopupContext)
