export const webFormSubmission = (widgetType) => {
  let submitArray = [];
  widgetType.forEach((data, index) => {
    let type = data.type;
    if (type === "TextInputMultiLineWidget") {
      submitArray.push({
        id: index + 1,
        type,
        name: type + (index + 1),
        value: data.text.heading,
        nameValues: [
          {
            id: 1,
            value: data.value,
          },
        ],
      });
    } else if (type === "TextInputWidget") {
      submitArray.push({
        id: index + 1,
        type,
        name: type + (index + 1),
        value: data.text.heading,
        nameValues: [
          {
            id: 1,
            value: data.value,
          },
        ],
      });
    } else if (type === "CheckboxWidget") {
      let answers = [];
      data.value.Ans.forEach((elem) => {
        answers.push({
          id: elem,
        });
      });
      submitArray.push({
        id: index + 1,
        type,
        name: type + (index + 1),
        value: data.text.qheading,
        nameValues: answers,
      });
    } else if (type === "DropdownWidget") {
      submitArray.push({
        id: index + 1,
        type,
        name: type + (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 === "GroupsWidget") {
      submitArray.push({
        id: index + 1,
        type,
        name: type + (index + 1),
        value: data.text.qheading,
        valuesMap: {
          spaceId: data.text.spaceId,
        },
        nameValues: [
          {
            value: data.value.Ans,
          },
        ],
      });
    } else if (type === "RadioButtonWidget") {
      submitArray.push({
        id: index + 1,
        type,
        name: type + (index + 1),
        value: data.text.qheading,
        nameValues: [
          {
            id: data.value.Ans,
          },
        ],
      });
    } else if (type === "RattingWidget") {
      submitArray.push({
        id: index + 1,
        type,
        name: type + (index + 1),
        value: data.text.rattingHeading,
        nameValues: [
          {
            id: data.value.Ans,
          },
        ],
      });
    } else if (type === "BooleanWidget") {
      submitArray.push({
        id: index + 1,
        type,
        name: type + (index + 1),
        value: data.text.booleanHeading,
        nameValues: [
          {
            id: data.value.Ans.id,
            value: data.value.Ans.value,
          },
        ],
      });
    } else if (type === "DateWidget") {
      submitArray.push({
        id: index + 1,
        type,
        name: type + (index + 1),
        value: data.text.heading,
        nameValues: [
          {
            id: 1,
            value: data.value,
          },
        ],
      });
    } else if (type === "UploadWidget") {
      submitArray.push({
        id: index + 1,
        type,
        name: type + (index + 1),
        value: "",
        nameValues: [
          {
            id: 1,
            value: "",
          },
        ],
      });
    } else if (type === "SliderWidget") {
      submitArray.push({
        id: index + 1,
        type,
        name: type + (index + 1),
        value: "",
        nameValues: [
          {
            id: null,
          },
        ],
      });
    }
  });
  console.log("submitArray", submitArray);
  return submitArray;
};
