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

import { usePreferences } from './hooks'

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

const PreferencesPopupContext = createContext({} as Context)

export const PreferencesPopupStore = ({ children }: Props) => {
  const value = usePreferences()
  return (
    <PreferencesPopupContext.Provider value={value}>
      {children}
    </PreferencesPopupContext.Provider>
  )
}

export const usePreferencesStore = () => useContext(PreferencesPopupContext)
