export const getWebRender = (widgetType) => {
  //console.log('ran web render')

  var renderArray = {
    elements: [],
  };
  widgetType.forEach((value, index) => {
    let type = value.type;
    if (type === "ImageWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "image_widget",
        name: "image_widget" + (index + 1),
        value: "image",
        nameValues: [
          {
            id: 1,
            name: "",
          },
        ],
      });
    } else if (type === "SocialsWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "socials_widget",
        name: "socials_widget" + (index + 1),
        value: "socials",
        nameValues: [
          {
            id: 1,
            name: "",
          },
        ],
      });
    } else if (type === "LinksWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "links_widget",
        name: "links_widget" + (index + 1),
        value: "links",
        nameValues: [
          {
            id: 1,
            name: "",
          },
        ],
      });
    } else if (type === "TextEditorWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "text_widget",
        name: "text_widget" + (index + 1),
        value: "text",
        nameValues: [
          {
            id: 1,
            name: "",
          },
        ],
      });
    } else if (type === "TextInputMultiLineWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "text_area_widget",
        name: "text_area_widget" + (index + 1),
        value: value.text.heading,
        nameValues: [
          {
            id: 1,
            name: "",
          },
        ],
      });
    } else if (type === "TextInputWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "single_input_widget",
        name: "single_input_widget" + (index + 1),
        value: value.text.heading,
        nameValues: [
          {
            id: 1,
            name: "",
          },
          {
            id: 2,
            name: "inputType",
            value: value.style.input.type,
          },
          {
            id: 3,
            name: "inputValue",
            value: value.text.submitValue,
          },
        ],
      });
    } else if (type === "DateWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "date_widget",
        name: "date_widget" + (index + 1),
        value: value.text.heading,
        nameValues: [
          {
            id: 1,
            name: "",
          },
        ],
      });
    } else if (type === "CheckboxWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "checkbox_widget",
        name: "checkbox_widget" + (index + 1),
        value: value.text.heading,
        nameValues: [],
      });

      value.text.options.forEach((value, index) => {
        renderArray.elements[renderArray.elements.length - 1].nameValues.push({
          id: index + 1,
          name: value.text,
        });
      });
    } else if (type === "DropdownWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "dropdown_widget",
        name: "dropdown_widget" + (index + 1),
        value: value.text.heading,
        nameValues: [],
      });

      value.text.options.forEach((value, index) => {
        renderArray.elements[renderArray.elements.length - 1].nameValues.push({
          id: index + 1,
          name: value.text,
          value: value.value,
        });
      });
    } else if (type === "GroupsWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "groups_widget",
        name: "groups_widget" + (index + 1),
        value: value.text.heading,
        valuesMap: {
          spaceId: value.text.spaceId,
        },
        nameValues: [],
      });

      value.text.options.forEach((value, index) => {
        renderArray.elements[renderArray.elements.length - 1].nameValues.push({
          id: index + 1,
          name: value.text,
          value: value.value,
        });
      });
    } else if (type === "RadioButtonWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "radiogroup_widget",
        name: "radiogroup_widget" + (index + 1),
        value: value.text.heading,
        nameValues: [],
      });

      value.text.options.forEach((value, index) => {
        renderArray.elements[renderArray.elements.length - 1].nameValues.push({
          id: index + 1,
          name: value.text,
        });
      });
    } else if (type === "RattingWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "ratting_widget",
        name: "ratting_widget" + (index + 1),
        value: value.text.heading,
        nameValues: [
          {
            id: 1,
          },
          {
            id: 2,
          },
          {
            id: 3,
          },
          {
            id: 4,
          },
          {
            id: 5,
          },
        ],
      });
    } else if (type === "BooleanWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "boolean_widget",
        name: "boolean_widget" + (index + 1),
        value: value.text.heading,
        nameValues: [
          {
            id: 1,
            name: value.text.option.true,
          },
          {
            id: 0,
            name: value.text.option.false,
          },
        ],
      });
    } else if (type === "UploadWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "file_upload_widget",
        name: "file_upload_widget" + (index + 1),
        value: "file" + index,
        nameValues: [
          {
            id: 1,
            name: "",
          },
        ],
      });
    } else if (type === "SliderWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "slider_widget",
        name: "slider_widget" + (index + 1),
        value: "slider" + index,
        nameValues: [
          {
            id: 1,
            name: "",
          },
        ],
      });
    } else if (type === "VoiceWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "voice_record_widget",
        name: "voice_record_widget" + (index + 1),
        value: "voice" + index,
        nameValues: [
          {
            id: 1,
            name: "",
          },
        ],
      });
    } else if (type === "SubmitButtonWidget") {
      renderArray.elements.push({
        id: index + 1,
        type: "submit_button_widget",
        name: "submit_button_widget" + (index + 1),
        value: "submit_button_widget" + index,
        nameValues: [
          {
            id: 1,
            name: "",
          },
        ],
      });
    }
  });
  // console.log(JSON.stringify(renderArray.elements))
  return renderArray.elements;
};
