import Vue from 'vue';
import initVue from '@assets/js/initVue';

const vm = new Vue({
  components: {
    BaseContent: () => import(/* webpackChunkName: "BaseContent" */ '@elements/BaseContent/index.vue'),
    BaseInput: () => import(/* webpackChunkName: "BaseInput" */ '@elements/BaseInput/index.vue'),
    BaseModal: () => import(/* webpackChunkName: "BaseModal" */ '@components/BaseModal/index.vue'),
    BaseButton: () => import(/* webpackChunkName: "BaseButton" */ '@elements/BaseButton/index.vue'),
  },
  data() {
    return {
      addresses: [],
      language: {},
      loading: true,
      success: '',
      insert: '',
      default: {},
      showModal: false,
      deleteLink: '',
    }
  },
  methods: {
    setData({ configurations }) {
      const { addresses, language, insert, success } = configurations;

      Object.keys(addresses).forEach((item, index) => {
        if(addresses[item].default == true){
          this.addresses.unshift(addresses[item])
        }else{
          this.addresses.push(addresses[item]);
        }
      });

      this.language = language;
      this.success = success;
      this.insert = insert;
    },
    addNewAddress() {
      this.addresses.push(this.address);
    },
    onClose(){
      this.showModal = false;
    },
    openModal(addressDelete){
      this.showModal = true;
      this.deleteLink = addressDelete
    },
    deleteAddress(){
      window.location.href = this.deleteLink;
    }
  },
  mounted(){
    if(this.success){
      notificationMsg(this.success, 'success');
    }

    this.loading = false;

  }
});

initVue(vm);
