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

import { useUserFavorites } from '../hooks'

export * from '../hooks'

type Context = ReturnType<typeof useUserFavorites>

const UserFavoritesContext = createContext({} as Context)

type Props = { children: ReactNode }

export const UserFavoritesStore = ({ children }: Props) => {
  const userFavoritesStore = useUserFavorites()

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

export const useUserFavoritesStore = () => useContext(UserFavoritesContext)
