export const webFormSubmission = (widgetType) => {
  let submitArray = [];
  widgetType.forEach((data, index) => {
    let type = data.type;
    if (type === "text_area" || type === "text_area_widget") {
      submitArray.push({
        id: index + 1,
        type: "text_area_widget",
        name: "text_area_widget" + (index + 1),
        value: data.text.heading,
        nameValues: [
          {
            id: 1,
            value: data.value,
          },
        ],
      });
    } else if (type === "single_input" || type === "single_input_widget") {
      submitArray.push({
        id: index + 1,
        type: "single_input_widget",
        name: "single_input_widget" + (index + 1),
        value: data.text.heading,
        nameValues: [
          {
            id: 1,
            value: data.value,
          },
        ],
      });
    } else if (type === "checkbox" || type === "checkbox_widget") {
      let answers = [];
      console.log("checkbox_widget", data);
      data.value.Ans.forEach((elem) => {
        answers.push({
          id: elem,
        });
      });
      submitArray.push({
        id: index + 1,
        type: "checkbox_widget",
        name: "checkbox_widget" + (index + 1),
        value: data.text.qheading,
        nameValues: answers,
      });

      console.log("checkbox_widget", data);
    } else if (type === "dropdown" || type === "dropdown_widget") {
      console.log("dropdown_widget", data);
      submitArray.push({
        id: index + 1,
        type: "dropdown_widget",
        name: "dropdown_widget" + (index + 1),
        value: data.text.qheading,
        nameValues: [
          {
            value: data.value.Ans,
            id:
              data.value.Ans != null
                ? data.text.Answers.findIndex(
                    (value) => value.value == data.value.Ans
                  ) + 1
                : null,
          },
        ],
      });
    } else if (type === "groups_widget") {
      console.log("groups_widget", data);
      submitArray.push({
        id: index + 1,
        type: "groups_widget",
        name: "groups_widget" + (index + 1),
        value: data.text.qheading,
        valuesMap: {
          spaceId: data.text.spaceId,
        },
        nameValues: [
          {
            value: data.value.Ans,
          },
        ],
      });
    } else if (type === "radiogroup" || type === "radiogroup_widget") {
      submitArray.push({
        id: index + 1,
        type: "radiogroup_widget",
        name: "radiogroup_widget" + (index + 1),
        value: data.text.qheading,
        nameValues: [
          {
            id: data.value.Ans,
          },
        ],
      });
    } else if (type === "ratting" || type === "ratting_widget") {
      submitArray.push({
        id: index + 1,
        type: "ratting_widget",
        name: "ratting_widget" + (index + 1),
        value: data.text.rattingHeading,
        nameValues: [
          {
            id: data.value.Ans,
          },
        ],
      });
    } else if (type === "boolean" || type === "boolean_widget") {
      submitArray.push({
        id: index + 1,
        type: "boolean_widget",
        name: "boolean_widget" + (index + 1),
        value: data.text.booleanHeading,
        nameValues: [
          {
            id: data.value.Ans.id,
            value: data.value.Ans.value,
          },
        ],
      });
    } else if (type === "widtime" || type === "time_widget") {
      submitArray.push({
        id: index + 1,
        type: "time_widget",
        name: "time_widget" + (index + 1),
        value: data.text.heading,
        nameValues: [
          {
            id: 1,
            value: data.value,
          },
        ],
      });
    } else if (type === "widdate" || type === "date_widget") {
      submitArray.push({
        id: index + 1,
        type: "date_widget",
        name: "date_widget" + (index + 1),
        value: data.text.heading,
        nameValues: [
          {
            id: 1,
            value: data.value,
          },
        ],
      });
    } else if (type === "file" || type === "file_upload_widget") {
      submitArray.push({
        id: index + 1,
        type: "file_upload_widget",
        name: "file_upload_widget" + (index + 1),
        value: "file_upload_widget" + index,
        nameValues: [
          {
            id: 1,
            value: "",
          },
        ],
      });
    } else if (type === "slider" || type === "slider_widget") {
      submitArray.push({
        id: index + 1,
        type: "slider_widget",
        name: "slider_widget" + (index + 1),
        value: "slider_widget" + index,
        nameValues: [
          {
            id: null,
          },
        ],
      });
    }
  });
  console.log("submitArray", submitArray);
  return submitArray;
};
