import { useContext } from 'react'
import { AuthContext } from '../components/AuthProvider'
import type { AuthContextType } from '../types'

export function useAuth(): AuthContextType {
  const context = useContext(AuthContext)
  
  if (!context) {
    throw new Error('useAuth must be used within an AuthProvider')
  }
  
  return context
}

export function useUser() {
  const { state } = useAuth()
  return state.user
}

export function useSession() {
  const { state } = useAuth()
  return state.session
}

export function useAuthState() {
  const { state } = useAuth()
  return state
}

export function useAuthLoading() {
  const { state } = useAuth()
  return state.isLoading
}

export function useAuthError() {
  const { state } = useAuth()
  return state.error
}

export function useIsAuthenticated() {
  const { state } = useAuth()
  return state.isAuthenticated
}