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

import { useAuth } from './hooks/useAuth'

type Auth = ReturnType<typeof useAuth>

const AuthContext = createContext({} as Auth)

type Props = {
  children: ReactNode,
}

export const AuthStore = ({ children }: Props) => {
  const auth = useAuth()

  return <AuthContext.Provider value={auth}>{children}</AuthContext.Provider>
}

export const useAuthStore = () => useContext(AuthContext)
