import { createContext, useContext, useState } from "react"

export enum FormEnum {
    login,
    register,
    recover,
}
interface SwitchFormContextProps {
    form: FormEnum,
    handleFormSwitch: (form:FormEnum ) => void
}

const SwitchFormContext = createContext<SwitchFormContextProps>({
    form: FormEnum.login,
    handleFormSwitch: () => {}
});

interface SwitchFormProviderProps {
    children: React.ReactNode;
}
export const SwitchFormProvider = ({ children }: SwitchFormProviderProps) => {
    const [form, setForm] = useState<FormEnum>(FormEnum.login);
    function handleFormSwitch(form: FormEnum) {
        setForm(form)
    }
    return (
        <SwitchFormContext.Provider value={{ form, handleFormSwitch }}>
            {children}
        </SwitchFormContext.Provider>
    )
}

export const useSwitchFormContext = () => {
    return useContext<SwitchFormContextProps>(SwitchFormContext);
};