import React from "react";
import { Choice } from "../../../../types/Item";
import ValidationField from "../../../../Components/ValidationField/ValidationField";
import { useFormikContext } from "formik";
import { useTranslation } from "react-i18next";
import { getCharFromNumber } from "../../../../utils/getCharFromNumber";
import CheckboxField from "./CheckboxField";
import TextField from "./TextField";
import File from "./File";
import { FaCirclePlus, FaDeleteLeft } from "react-icons/fa6";
import { FaTrash } from "react-icons/fa";

const ChoiceFields = ({ index, data }: { index: number; data: Choice }) => {
  const formik = useFormikContext<any>();

  const [t] = useTranslation();

  const handleDeleteChoice = () => {
    console.log(index);
    console.log(formik.values.QuestionOptions[index]);

    const updatedQuestionOptions = formik.values.QuestionOptions.filter(
      (_: any, i: any) => i !== index,
    );

    formik.setFieldValue("QuestionOptions", updatedQuestionOptions);
  };
  console.log(formik.values);

  return (
    <div className="ChoiceFields">
      <TextField
        className="textarea_exercise"
        placeholder={"choice"}
        label2={t(`input.choice`) + ` ` + `(${getCharFromNumber(index)})`}
        name={index}
        id={`choice_${index + 1}`}
        type="TextArea"
      />
      <File
        className="file_exercise"
        label={"attachment"}
        name={index}
        type="File"
      />

      <CheckboxField
        className=""
        label="The_correct_answer"
        name={index}
        type="Checkbox"
      />
      <p className="delete_question_options">
        <FaTrash onClick={handleDeleteChoice} size={17} />
      </p>
    </div>
  );
};

export default ChoiceFields;
