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'),
    BaseButton: () => import(/* webpackChunkName: "BaseButton" */ '@elements/BaseButton/index.vue'),
    BaseTabs: () => import(/* webpackChunkName: "BaseTabs" */ '@components/BaseTabs/index.vue'),
    BaseInput: () => import(/* webpackChunkName: "BaseTabs" */ '@elements/BaseInput/index.vue'),
    BaseSelect: () => import(/* webpackChunkName: "BaseTabs" */ '@elements/BaseSelect/index.vue'),
  },
  data() {
    return {
      configurations: {
        bestseller_title: '',
        bestseller_subtitle: '',
        bestseller_module: [],
      },
      disableForm: false,
      loadingBtn: false,
    };
  },
  methods: {
    onAddModule() {
      const { configurations } = this;
      const bestsellerModule = configurations.bestseller_module;

      let sortOrder = 0;
      if (bestsellerModule[bestsellerModule.length - 1]) { 
        const { sort_order } = bestsellerModule[bestsellerModule.length - 1];
        sortOrder = Number(sort_order) + 1;
      }
     
      this.configurations.bestseller_module.push({
        limit: '24',
        sort_order: sortOrder,
      });

      this.configurations = { ...configurations };
    },
    onRemoveModule(moduleIndex) {
      const { configurations } = this;
      const bestsellerModule = configurations.bestseller_module;
      bestsellerModule.splice(moduleIndex, 1);
      this.configurations = { ...configurations };
    },
    onPositionChange(moduleIndex) {
      const module = this.configurations.bestseller_module[moduleIndex];
      if (module.position === Type_ModulePosition.Tp_AppMobile && Object.keys(this.layoutsApp).findIndex((el) => el === module.layout_id) === -1) {
        this.configurations.bestseller_module[moduleIndex].layout_id = this.layoutsApp.Tp_Principal || 1;
      }
      if(module.entry_type == 0 || module.position == Type_ModulePosition.Tp_ColumnLeft) module.limit = '24', module.entry_type = 0;
    },
    onTypeChange(type, moduleIndex){
      if(type == 0) this.configurations.bestseller_module[moduleIndex].limit = '24';

    },
  },
  mounted() {
  },
});

initVue(vm);
