import AdmVue from '@assets/js/adm-vue';
import initVue from '@assets/js/initVue';

const vm = new AdmVue({
  components: {
    BaseCard: () => import(/* webpackChunkName: "BaseCard" */ '@elements/BaseCard/index.vue'),
    BaseInputFile: () => import(/* webpackChunkName: "BaseInputFile" */ '@elements/BaseInputFile/index.vue'),
    BaseTabs: () => import(/* webpackChunkName: "BaseTabs" */ '@components/BaseTabs/index.vue'),
    AsideContent: () => import(/* webpackChunkName: "AsideContent" */ '@components/AsideContent/index.vue'),
    BaseTextarea: () => import(/* webpackChunkName: "BaseTextarea" */ '@elements/BaseTextarea/index.vue'),
    BaseManual: () => import(/* webpackChunkName: "BaseManual" */ "@elements/BaseManual/index.vue")
  },

  data() {
    return {
      configurations: {
        buy_later_status: '',
        buy_later_title: '',
        buy_later_module: [
          {
            layout_id: 0,
            limit: '24',
            sort_order: 0,
            position: 'content_top',
            entry_type: 0,

            status: 0
          }
        ],
      },
      layoutsApp: [],
      layouts: [],
      disableForm: false,
      loadingBtn: false,
    };
  },

  methods: {
    onAddModule() {
      if (this.configurations.buy_later_status == Type_Status.Tp_Habilitado) {
        const { configurations } = this;
        const buyLaterModule = configurations.buy_later_module;
        

        let sortOrder = 0;
        if (buyLaterModule[buyLaterModule.length - 1]) {
          const { sort_order } = buyLaterModule[buyLaterModule.length - 1];
          sortOrder = Number(sort_order) + 1;
        }

        buyLaterModule.push({
          layout_id: Type_IdLayout.Tp_IdCart,
          limit: '24',
          sort_order: sortOrder,
        });
        
        this.configurations = { ...configurations };
      }
    },
    onRemoveModule(moduleIndex) {
      const { configurations } = this;
      const buyLaterModule = configurations.buy_later_module;
      buyLaterModule.splice(moduleIndex, 1);
      this.configurations = { ...configurations };
    },
    onPositionChange(moduleIndex) {
      const module = this.configurations.buy_later_module[moduleIndex];
      if (
        module.position === Type_ModulePosition.Tp_AppMobile &&
        Object.keys(this.layoutsApp).findIndex(el => el === module.layout_id) === -1
      ) {
        this.configurations.buy_later_module[moduleIndex].layout_id = this.layoutsApp.Tp_Principal || 1;
      }
    },
  },
});

initVue(vm);
