// export const applyDrag = (arr, dragResult) => {
//     const { removedIndex, addedIndex, payload } = dragResult
//     if (removedIndex === null && addedIndex === null) return arr

//     const result = [...arr]
//     let itemToAdd = payload

//     if (removedIndex !== null) {
//       itemToAdd = result.splice(removedIndex, 1)[0]
//     }

//     if (addedIndex !== null) {
//       result.splice(addedIndex, 0, itemToAdd)
//     }

//     return result
//   }

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

  var renderArray = {
    elements: []
  };
  widgetType.forEach((value, index) => {
    let type = value.type;
    if (type === "widimage" || type === "image_widget") {
      renderArray.elements.push({
        id: index + 1,
        type: "image_widget",
        name: "image_widget" + (index + 1),
        value: "image",
        nameValues: [
          {
            id: 1,
            name: ""
          }
        ]
      });
    } else if (type === "widsocials" || type === "socials_widget") {
      renderArray.elements.push({
        id: index + 1,
        type: "socials_widget",
        name: "socials_widget" + (index + 1),
        value: "socials",
        nameValues: [
          {
            id: 1,
            name: ""
          }
        ]
      });
    } else if (type === "widlinks" || type === "links_widget") {
      renderArray.elements.push({
        id: index + 1,
        type: "links_widget",
        name: "links_widget" + (index + 1),
        value: "links",
        nameValues: [
          {
            id: 1,
            name: ""
          }
        ]
      });
    } else if (type === "widtext" || type === "text_widget") {
      renderArray.elements.push({
        id: index + 1,
        type: "text_widget",
        name: "text_widget" + (index + 1),
        value: "text",
        nameValues: [
          {
            id: 1,
            name: ""
          }
        ]
      });
    } else if (type === "text_area" || type === "text_area_widget") {
      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 === "single_input" || type === "single_input_widget") {
      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.text.inputType
          },
          {
            id: 3,
            name: "inputValue",
            value: value.text.inputValue
          }
        ]
      });
    } else if (type === "widtime" || type === "time_widget") {
      renderArray.elements.push({
        id: index + 1,
        type: "time_widget",
        name: "time_widget" + (index + 1),
        value: value.text.heading,
        nameValues: [
          {
            id: 1,
            name: ""
          }
        ]
      });
    } else if (type === "widdate" || type === "date_widget") {
      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 === "checkbox" || type === "checkbox_widget") {
      renderArray.elements.push({
        id: index + 1,
        type: "checkbox_widget",
        name: "checkbox_widget" + (index + 1),
        value: value.text.qheading,
        nameValues: []
      });

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

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

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

      value.text.Answers.forEach((value, index) => {
        renderArray.elements[renderArray.elements.length - 1].nameValues.push({
          id: index + 1,
          name: value.text
        });
      });
    } else if (type === "ratting" || type === "ratting_widget") {
      renderArray.elements.push({
        id: index + 1,
        type: "ratting_widget",
        name: "ratting_widget" + (index + 1),
        value: value.text.rattingHeading,
        nameValues: [
          {
            id: 1
          },
          {
            id: 2
          },
          {
            id: 3
          },
          {
            id: 4
          },
          {
            id: 5
          }
        ]
      });
    } else if (type === "boolean" || type === "boolean_widget") {
      renderArray.elements.push({
        id: index + 1,
        type: "boolean_widget",
        name: "boolean_widget" + (index + 1),
        value: value.text.booleanHeading,
        nameValues: [
          {
            id: 1,
            name: value.text.booleanOption.true
          },
          {
            id: 0,
            name: value.text.booleanOption.false
          }
        ]
      });
    } else if (type === "file" || type === "file_upload_widget") {
      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 === "slider" || type === "slider_widget") {
      renderArray.elements.push({
        id: index + 1,
        type: "slider_widget",
        name: "slider_widget" + (index + 1),
        value: "slider" + index,
        nameValues: [
          {
            id: 1,
            name: ""
          }
        ]
      });
    } else if (type === "voice_record_widget") {
      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 === "submit_button_widget") {
      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;
};

export const getEmailTemp = () => {
  var data = [
    {
      type: "parentRowWidget",
      component: {
        name: "parentRowWidget",
        props: {
          NewStyle: {},
          selectedWidget: {},
          index: {},
          widgetDidMove: {},
          isDraging: {},
          hasDragEnded: {},
          selectedDropWidget: {},
          widgetHoverIndex: {},
          dragWidgetType: {}
        },
        computed: {},
        methods: {},
        staticRenderFns: [],
        _compiled: true,
        _scopeId: "data-v-727333fe",
        beforeCreate: [null],
        beforeDestroy: [null],
        __file: "src/components/email/widgets/parentRowWidget.vue",
        _Ctor: {}
      },
      size: 2,
      columns: [
        {
          component: {
            name: "columnPlaceholder",
            props: {
              index: {},
              selectedDropWidget: {},
              widgetType: {},
              dragWidgetType: {},
              placeholderStyle: {}
            },
            methods: {},
            staticRenderFns: [null],
            _compiled: true,
            _scopeId: "data-v-c6b9c56c",
            beforeCreate: [null],
            beforeDestroy: [null],
            __file: "src/components/email/widgets/columnPlaceholder.vue",
            _Ctor: {}
          },
          style: [
            "white",
            {
              padding: 0,
              paddingLeft: 0,
              paddingRight: 0,
              paddingTop: 0,
              paddingBottom: 0
            },
            "50%",
            {
              bgcolor: "ffffff",
              cbgcolor: "#FFF"
            },
            {
              border: "blue solid 0",
              borderRight: "blue solid 0",
              borderLeft: "blue solid 0",
              borderTop: "blue solid 0",
              borderBottom: "blue solid 0"
            }
          ],
          rows: [
            {
              type: "imageWidget",
              component: {
                name: "imageWidget",
                props: {
                  NewStyle: {},
                  selectedWidget: {},
                  index: {},
                  widgetDidMove: {},
                  isDraging: {},
                  hasDragEnded: {},
                  selectedDropWidget: {},
                  widgetHoverIndex: {},
                  widgetType: {},
                  dragWidgetType: {}
                },
                computed: {},
                methods: {},
                staticRenderFns: [],
                _compiled: true,
                _scopeId: "data-v-1190ff4c",
                beforeCreate: [null],
                beforeDestroy: [null],
                __file: "src/components/email/widgets/imageWidget.vue",
                _Ctor: {}
              },
              value: {
                type: "imageWidget",
                ImageUrl: "",
                ImageUrlLink: ""
              },
              style: [
                "white",
                {
                  padding: 10,
                  paddingLeft: 10,
                  paddingRight: 10,
                  paddingTop: 10,
                  paddingBottom: 10
                },
                {
                  newTab: null,
                  linkUrl: null,
                  imgurl:
                    "https://s3.ap-southeast-1.amazonaws.com/vemessage-images/1555421465220-cat1-400x400.png",
                  imgsize: 100,
                  position: "center"
                }
              ]
            }
          ]
        },
        {
          component: {
            name: "columnPlaceholder",
            props: {
              index: {},
              selectedDropWidget: {},
              widgetType: {},
              dragWidgetType: {},
              placeholderStyle: {}
            },
            methods: {},
            staticRenderFns: [null],
            _compiled: true,
            _scopeId: "data-v-c6b9c56c",
            beforeCreate: [null],
            beforeDestroy: [null],
            __file: "src/components/email/widgets/columnPlaceholder.vue",
            _Ctor: {}
          },
          style: [
            "white",
            {
              padding: 0,
              paddingLeft: 0,
              paddingRight: 0,
              paddingTop: 0,
              paddingBottom: 0
            },
            "50%",
            {
              bgcolor: "ffffff",
              cbgcolor: "#FFF"
            },
            {
              border: "blue solid 0",
              borderRight: "blue solid 0",
              borderLeft: "blue solid 0",
              borderTop: "blue solid 0",
              borderBottom: "blue solid 0"
            }
          ],
          rows: [
            {
              type: "textWidget",
              component: {
                name: "textWidget",
                props: {
                  NewStyle: {},
                  selectedWidget: {},
                  index: {},
                  widgetDidMove: {},
                  isDraging: {},
                  hasDragEnded: {},
                  selectedDropWidget: {},
                  widgetHoverIndex: {},
                  widgetType: {},
                  dragWidgetType: {}
                },
                computed: {},
                methods: {},
                staticRenderFns: [],
                _compiled: true,
                _scopeId: "data-v-ba546ed8",
                beforeCreate: [null],
                beforeDestroy: [null],
                __file: "src/components/email/widgets/textWidget.vue",
                _Ctor: {}
              },
              value: {
                text:
                  '<p style="text-align: justify;"><span style="font-size: 14px;">Two of the most popular pets are dogs and cats. The technical term for a cat lover is an ailurophile, and for a dog lover, a cynophile. Other animals commonly kept include rabbits; ferrets; pigs; rodents, such as gerbils, hamsters, chinchillas, rats, and guinea pigs; avian pets, such as parrots, passerines, and fowl; reptile pets, such as turtles, alligators, crocodiles, lizards, and snakes; aquatic pets, such as fish, freshwater and saltwater snails, and frogs</span></p>'
              },
              style: [
                "white",
                {
                  padding: 10,
                  paddingLeft: 10,
                  paddingRight: 10,
                  paddingTop: 10,
                  paddingBottom: 10
                },
                {
                  bgcolor: "transparent",
                  hcolor: "#FFFF",
                  tcolor: "#FFFF"
                }
              ]
            }
          ]
        }
      ],
      style: [
        "white",
        {
          padding: 0,
          paddingLeft: 0,
          paddingRight: 0,
          paddingTop: 0,
          paddingBottom: 0
        },
        {
          bgcolor: "transparent",
          cbgcolor: "#FFF"
        }
      ]
    }
  ];

  return data;
};
