import { useState } from "react";

export const useHandlerFieldTest = ({ questions, indexQuestion }) => {
  const [userResponses, setUserResponses] = useState([]);
  const handleChangeCheckbox = (e) => {
    setUserResponses((prev) => [
      ...prev.filter(
        (item) => item.question_id !== questions[indexQuestion].id
      ),
      {
        question_id: questions[indexQuestion].id,
        response_body: e.target.value,
        answer_id: e.target.id ? e.target.id : questions[indexQuestion].id
      }
    ]);
  };

  // const handleFieldsForm = (e) => {
  //   setValues([
  //     {
  //       user_id: id,
  //       user_questionnaire_uuid: uuid,
  //       question_id: questions[indexQuestion].id,
  //       response_body: e.target.value,
  //     },
  //   ]);
  // };
  const handleChange = (e) => {
    handleChangeCheckbox(e);
  };
  return { handleChange, userResponses };
};
