import React, { useState } from "react";
import { makeStyles } from "@mui/styles";

/** function used in Form to store values and handle changing
 *
 * @param {Object} initialFValues initial values of form
 * @param validate
 */
export function useForm(initialFValues, validate) {
  const [values, setValues] = useState(initialFValues);
  const [errors, setErrors] = useState({});

  const handleInputChange = (e) => {
    const { name, value } = e.target;
    let errorCpy = errors;
    errorCpy[name] = "";

    setErrors(errorCpy);
    setValues({
      ...values,
      [name]: value,
    });
  };

  return {
    values,
    setValues,
    errors,
    setErrors,
    handleInputChange,
  };
}
