import { Dispatch, ReactNode, SetStateAction, createContext, useState } from 'react'
import { User } from '../../types'

export interface UserContextInterface {
  user: User
  setUser: Dispatch<SetStateAction<User>>
}

const defaulState = {
  user: {
    firstName: '',
    email: '',
    lastName: '',
    password: '',
    phone: '',
    birthday: '',
    profilePicture: ''
  },
  setUser: (user: User) => {}
} as UserContextInterface

export const UserContext = createContext<UserContextInterface>(defaulState)

type UserProvideProps = {
  children: ReactNode
}

export default function UserProvider({ children }: UserProvideProps) {
  const [user, setUser] = useState<User>({
    firstName: '',
    email: '',
    lastName: '',
    password: '',
    phone: '',
    birthday: '',
    profilePicture: ''
  })
  return <UserContext.Provider value={{ user, setUser }}>{children}</UserContext.Provider>
}
