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'),
      BaseTabs: () => import(/* webpackChunkName: "BaseTabs" */ '@components/BaseTabs/index.vue'),
    },
    data() {
      return {
        configurations: {
          special_module: []
        },
        layouts: [],
        special_action: [],
        disableForm: false,
        loadingBtn: false,
      };
    },
    methods:{
      onAddModule(){
        const { configurations } = this;
        const specialModule = configurations.special_module;

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

        this.configurations.special_module.push({
          limit: '24',
          sort_order: sortOrder,
          status: 1,
          
        });
        
        this.configurations = {...configurations};

      },
      onRemoveModule(moduleIndex){
        const { configurations } = this;
        const specialModule = configurations.special_module;
        specialModule.splice(moduleIndex, 1);
        this.configurations = {...configurations};
      },
      onPositionChange(moduleIndex) {
        
        const module = this.configurations.special_module[moduleIndex];

        if(module.position === Type_ModulePosition.Tp_ColumnLeft){
          this.configurations.special_module[moduleIndex].entry_type = 0;
        }
        else{
          this.configurations.special_module[moduleIndex].limit = '24';
        }

      },
      onTypeChange(type, moduleIndex){
        if(type == 0) this.configurations.special_module[moduleIndex].limit = '24';

      },
      convertToArray(value) {
        if(Array.isArray(value)) {
          return value
        }
  
        return Object.values(value)
      }
    },
    mounted(){
      if (this.configurations.special_module){ 
        this.configurations.special_module = this.convertToArray(this.configurations.special_module).map(item => ({
          ...item, 
          limit: item.limit || '24',
        }));
      }
    }
});

initVue(vm);