import AdmVue from '@assets/js/adm-vue.js';
import initVue from '@assets/js/initVue.js';
import axiosApi from '@assets/js/axios-api';
import formMixin from '@assets/components/mixins/formMixin';
import {length} from "vee-validate/dist/rules";
import { readonly } from 'vue';

const BASE_URL = document.getElementById('base-urls').dataset.baseUrlLoja;

const vm = new AdmVue({
  components: {
    BaseCard: () => import(/* webpackChunkName: "BaseCard" */ '@elements/BaseCard/index.vue'),
    BaseInput: () => import(/* webpackChunkName: "BaseInput" */ '@elements/BaseInput/index.vue'),
    BaseButton: () => import(/* webpackChunkName: "BaseButton" */ '@elements/BaseButton/index.vue'),
    BaseModal: () => import(/* webpackChunkName: "BaseModal" */ '@components/BaseModal/index.vue'),
    BaseCep: () => import(/* webpackChunkName: "BaseCep" */ '@elements/BaseCep/index.vue'),
  },
  data() {
    return {
      configurations: {
        pickup_module: [],
      },
      loadingBtn: false,
      readonly: '',
    };
  },
  methods: {
    onAddModule() {
      const {configurations} = this;
      const pickupModule = configurations.pickup_module;

      let sortOrder = 0;
      if (pickupModule[pickupModule.length - 1]) {
        const {sort_order} = pickupModule[pickupModule.length - 1];
        sortOrder = Number(sort_order) + 1;
      }
      configurations.pickup_module.push({
        status: Type_Status.Tp_Habilitado,
        sort_order: sortOrder,
        city: '',
        tipo_logradouro: '',
        logradouro: '',
      });
      
      this.readonly = false
      this.configurations = {...configurations};

    },
    onRemoveModule(moduleIndex) {
      const {configurations} = this;
      const pickupModule = configurations.pickup_module;
      pickupModule.splice(moduleIndex, 1);
      this.configurations = {...configurations};
    },

    // Callback dos dados do componente BaseCep
    dataReturn(selectedValues, moduleIndex) {
      this.configurations.pickup_module.map((pickupData) => {
        const pickupAllData = {...pickupData, ...selectedValues};
        this.configurations.pickup_module[moduleIndex] = pickupAllData;
      })
    },
  },
});

initVue(vm);
