import { validate as uuidValidate } from 'uuid';
import Vuex from 'vuex';
import Vue from 'vue';
import {v4 as uuidv4, validate} from "uuid";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    jsonBannersMounted: {
      habilita_banner: DATA.banner_extensions.banner_homepage.habilita_banner,
      tipo_banner: DATA.banner_extensions.banner_homepage.tipo_banner,
      banner_rotativo: DATA.banner_extensions.banner_homepage.banner_rotativo,
      banner_time: DATA.banner_extensions.banner_homepage.banner_time,
      banner_largura: DATA.banner_extensions.banner_homepage.banner_largura,
      banner_altura: DATA.banner_extensions.banner_homepage.banner_altura,
      banner_responsive_largura: DATA.banner_extensions.banner_homepage.banner_responsive_largura,
      banner_responsive_altura: DATA.banner_extensions.banner_homepage.banner_responsive_altura,
      tipo_configuracao:   DATA.banner_extensions.banner_homepage.tipo_configuracao,
      hide_responsive: DATA.banner_extensions.banner_homepage.hide_responsive,
      tipo_posicionamento: DATA.banner_extensions.banner_homepage.tipo_posicionamento,
      banner_group: DATA.banner_extensions.banner_homepage.banner_group,
      banner_image: DATA.banner_extensions.banner_homepage.banner_image,
      banner_product: DATA.banner_extensions.banner_homepage.banner_product,
      banner_dinamico: DATA.banner_extensions.banner_homepage.banner_dinamico,
      excluded: [],
      banner: DATA.banners,
    },
    nameSecundarySub: '',
    language: {},
    objectStructureSecundaryBannerWithAllSubModules: { banner: [], carousels: [], mosaics: [] },
    arrayCloneForManipulationBannerModuleData: [],
    firstBannerLayoutInformation: [],
    firstElementOfBannerModule: [],
    setCarrosselLayoutName: [],
    clearArrayOfCarousels: [],
    BannerTypeImageLayout: '',
    typeImage: '',
    newBannersClientData: [],
    supportBanner: [],
    bannerProduct: [],
    carouselsData: [],
    CarouselData: [],
    filesInUse: [
      {
        ext: '',
        file: '',
        filename: '',
        height: '',
        linkdireto: '',
        selected: '',
        size: '',
        thumbnail: '',
        width: '',
      },
    ],
    bannersData: [],
    bannerImageSupportModule: {
      analyze: '',
      analyze_id: '',
      quantity: '',
      banner_group_order: '',
      banner_image_description: [{ title: '' }],
      banner_order: {
        type: Number,
      },
      date_end: '',
      date_initial: '',
      image: '',
      image_responsive: '',
      link: '',
      new: '',
      target: '',
      thumb: '',
      thumb_responsive: '',
    },
    setNewDynamicBanner: {
      banner_dinamico_analyze_id: '',
      banner_dinamico_model: '',
      banner_dinamico_ordem: '',
      banner_dinamico_quantidade: '',
      banner_dinamico_tipolista: '',
      banner_group_order: '',
      new: '',
    },
    mosaicSelectedIndex: 0,
    setBannerLayoutName: [],
    bannerImageAllData: [],
    bannerImageAllDataClone: [],
    setMosaicLayoutName: [],
    allBannerSettings: [],
    moduleObjectData: [],
    saveBannerName: [],
    mosaicsData: [],
    MosaicData: [],
    banners: [],
    styleModuleName: {
      type: String,
    },
    analyze_id_banner_image: {
      type: String,
    },
    bannerProductId: {
      type: String,
    },
    styleOfBanner: {
      type: String,
    },
    screenNameSecundaryBanner: {
      type: String,
    },
    bannerId: 0, // DATA.banners[0].banner_id <<< Estava dando problemas no carregamento vazio
    moduleType: {
      type: String,
    },
    product_id: {
      type: String,
    },
    disableModules: {
      type: Boolean,
    },
    imageResponsive: '',
    imageLarge: '',
    bannerImageUUID: '',
    tabIsActived: 'HomePageBanner',
    screenName: 'HomePage',
    BannerTypeImage: '',
    enableAndDisable: {
      type: Boolean,
    },
    bannerType: '',
    bannerIsActiveProperty: '',
    id_edition: '',
    objectForEdition: {},
    flagSecundaryBanner: '',
    setHint: false,
    imageThumb: [],
    mosaicNumber: 0,
    widthBanner: '',
    setBannerSettingsImagesUse: '',
    bannersSecundaries: [],
    setNameScreen: '',
    banner_image_indexform: [],
    productSelectedWithSearch: {},
    banner_analyzeId: '',
    defineFlagMethod: '',
    UUIDv4_analyzeIdState: '',
    flagCreateNewProduct: '',
    flagprimaryDynamic: '',
    StatusSecindaryBanner: '1',
    setUpdateBanner: 0,
    productSelectedObjectReference: {
      analyze: '',
      analyze_id: '',
      quantity: '',
      banner_group_order: '',
      banner_model: '',
      banner_order: 0,
      banner_product_description: { 1: { title: ''} },
      date_end: '',
      date_initial: '',
      image: '',
      new: '',
      product_id: '',
      thumb: '',
    },
    dynamicBannerHomePageData: {},
  },

  actions: {
    setBanners(banners) {
      banners.commit('setBanners', banners);
    },

    setStatus(status) {
      banners.commit('setBanners', status);
    },

    setHintBanner(hint) {
      hint.commit('setHintBanner', hint);
    },

    setBannerHomePageProducts(banner_home_page) {
      banner_home_page.commit('setBannerProducts', banner_home_page);
    },
    saveSettingsInBannerHomePage(){

    },
  },

  mutations: {

    setDynamicBannerHomePageData(state, dataDynamicBannerHomePageData) {
      state.dynamicBannerHomePageData = dataDynamicBannerHomePageData;
    },

    setProductSelectedObjectReference(state, productSelected) {
      state.productSelectedObjectReference = productSelected;
    },

    setAllProductsFound(state, productsFound) {
      state.productSelectedWithSearch = productsFound;
    },

    defineFlagCreateNewProduct(state, flagCreateNewProductParam) {
      state.flagCreateNewProduct = flagCreateNewProductParam;
    },

    defineUUIDv4WithAnalyzeId(state, UUIDv4_analyzeId) {
      state.UUIDv4_analyzeIdState = UUIDv4_analyzeId;
    },

    setFlagMethodEditCreate(state, defineFlagMethod) {
      state.defineFlagMethod = defineFlagMethod;
    },

    setBannerImageData(state, bannerImage) {
      state.banner_image_indexform.push(bannerImage);
    },

    setAnalyzeIdbannerImage(state, bannerId) {
      state.banner_analyzeId = bannerId;
    },

    setHintBanner(state, hint) {
      state.setHint = true;
    },

    setThumbImage(state, imageThumb) {
      state.imageThumb.push(imageThumb);
    },

    setWidthBanner(state, bannerWidthImage) {
      state.widthBanner = bannerWidthImage;
    },

    flagSecundaryBanner(state, createFlag) {
      state.flagSecundaryBanner = createFlag;
    },

    saveBannerSelectedForEdition(state, bannersOld) {
      state.objectForEdition = bannersOld;
    },

    setBannerSecundary(state, bannerSecundary) {

      state.bannersSecundaries.push(bannerSecundary);
    },

    setActiveBanner(state, activeLayout) {
      DATA.banners.map(bannerData => {
        if (bannerData.banner_id === state.bannerId) {
          state.enableAndDisable = activeLayout;
        }
      });
    },

    enableAndDisableBannerWithSwitchButton(state, isActiveBannerOption) {
      state.bannerIsActiveProperty = isActiveBannerOption;
    },

    setThumbImageResponsive(state, imageResponsive) {
      state.imageResponsive = imageResponsive;
    },

    setThumbImageLarge(state, imageLarge) {
      state.imageLarge = imageLarge;
    },

    setUUIDbannerImage(state, bannerImageUUID) {
      state.bannerImageUUID = bannerImageUUID;
    },

    setBannerType(state, bannersType) {
      state.bannerType = bannersType;
    },

    setBannerImageAllData(state, bannerImageData) {
      state.bannerImageAllData = bannerImageData;
    },

    setBannerImageAllDataClone(state, bannerImageDataClone) {
      state.bannerImageAllDataClone.push(bannerImageDataClone);
    },

    setImageDataList(state, dataImage) {
      state.filesInUse = dataImage;
    },

    setSupportBanner(state, support) {
      state.supportBanner.push(support);
    },

    setBannerStructureModule(state, bannerDataModule) {
      state.objectStructureSecundaryBannerWithAllSubModules.banner.push(bannerDataModule);
    },

    setCarouselsStructureModule(state, bannerDataModule) {
      state.objectStructureSecundaryBannerWithAllSubModules.carousels.push(bannerDataModule);
    },

    setMosaicsStructureModule(state, bannerDataModule) {
      state.objectStructureSecundaryBannerWithAllSubModules.mosaics.push(bannerDataModule);
    },

    setBanners(state) {

      if(DATA.banners){
        DATA.banners.map(bannerData => {
          let BannerUUID = bannerData.UUID ? bannerData.UUID : uuidv4();
          bannerData.UUID = BannerUUID;
          state.banners.push({
            banner_id: bannerData.banner_id,
            isEdit: false,
            banner_image: bannerData.banner_image,
            UUID: BannerUUID,
            name: bannerData.name,
            status: bannerData.status,
          });
        });
      }else{
        DATA.banners = [];
        state.banners = [];
      }
      state.jsonBannersMounted.banner = state.banners;
    },

    setModel(state, modelSelected) {
      state.setNewDynamicBanner.banner_dinamico_model = modelSelected;
    },

    setOrder(state, orderData) {
      state.setNewDynamicBanner.banner_dinamico_ordem = orderData;
    },

    setAmount(state, setAmount) {
      state.setNewDynamicBanner.banner_dinamico_quantidade = setAmount;
    },

    setTypeList(state, typeList) {
      state.setNewDynamicBanner.banner_dinamico_tipolista = typeList;
    },

    setOrderData(state, orderData) {
      state.setNewDynamicBanner.banner_group_order = orderData;
    },

    setNewTag(state, newTagBanner) {
      state.setNewDynamicBanner.banner_group_order = newTagBanner;
    },

    setBannerProducts() {
      DATA.banner_home_page.banner_product.map((observerBannerProduct, index) => {
        state.bannerProduct.push(observerBannerProduct);
      });
    },

    setAnalyzeIdIntoBannerImage(state, analyze_id_banner_image) {
      state.analyze_id_banner_image = analyze_id_banner_image;
    },

    insertNewBannerData(state, new_banner_data) {
      new_banner_data.map(newBannerCallBack => {
        state.banners.unshift(newBannerCallBack);
      });
    },

    setBannersLayouts(state, layoutNamesInLayoutTable) {
      state.setBannerLayoutName.push(layoutNamesInLayoutTable);
    },

    setCarrosselLayouts(state, layoutNamesInLayoutTable) {
      state.setCarrosselLayoutName.push(layoutNamesInLayoutTable);
    },

    setMosaicLayouts(state, layoutNamesInLayoutTable) {
      state.setMosaicLayoutName.push(layoutNamesInLayoutTable);
    },

    setbannersData(state, moduleName) {

      state.bannersData = moduleName;
    },

    insetNewBannerIndexIntoArrayModule(state, setingsNewBanner) {
      state.arrayCloneForManipulationBannerModuleData.push(setingsNewBanner);
    },

    setCarouselsData(state, moduleName) {
      state.carouselsData = moduleName;
    },

    setMosaicsData(state, moduleName) {
      state.mosaicsData = moduleName;
    },

    setbannersModule(state, moduleName) {

      state.bannersModule.push(moduleName);
    },

    firstElementOfBanner() {
      state.firstElementOfBannerModule.push(Object.values(DATA.banners.banners[0]));
    },

    setFirstModuleOfBanner(state, banner_id) {
      state.firstBannerLayoutInformation.push(banner_id);
    },

    setBannerProductId(state, productId) {
      state.product_id = productId;
    },

    setBannerId(state, bannerId) {
      state.bannerId = bannerId;
    },

    setTabActive(state, tabName) {
      state.tabIsActived = tabName;
    },

    setModuleType(state, moduleName) {
      state.moduleType = moduleName;
    },

    setTypeImage(state, typeImage) {
      state.typeImage = typeImage;
    },

    openUpdateSettings(state, screenName) {
      state.screenName = screenName;
    },

    setBannerSettingsImagesUse(state, bannerSettingName) {
      state.setBannerSettingsImagesUse = bannerSettingName;
    },

    setScreenName(state, screenName) {
      state.screenName = screenName;
    },

    styleOfBannerHomePage(state, nameOfStyle) {
      state.styleOfBanner = nameOfStyle;
    },

    setBannerTitle(state, title) {
      state.bannerImageSupportModule.banner_image_description.map(titleCallBack => (titleCallBack.title = title));
    },

    setBannerCreateAndUpdateDisplay(state, setNameScreen) {
      state.setNameScreen = setNameScreen;
    },

    setLinkLink(state, link) {
      state.bannerImageSupportModule.link = link;
    },

    setInitialDate(state, initialDate) {
      state.bannerImageSupportModule.date_initial = initialDate;
    },

    setFinalDate(state, finalDate) {
      state.bannerImageSupportModule.date_end = finalDate;
    },

  },
});
