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

const vm = new Vue({
  components: {
    BaseListing: () => import(/* webpackChunkName: "BaseListing" */ '@elements/BaseListing/index.vue'),
    BaseContent: () => import(/* webpackChunkName: "BaseContent" */ '@elements/BaseContent/index.vue'),
    BaseButton: () => import(/* webpackChunkName: "Basebutton" */ '@elements/BaseButton/index.vue'),
  },
  data() {
    return {
      orders: {},
      showIcon: false,
    };
  },
  methods: {
    setData({ orders }) {
      this.orders = orders;
      this.transformPrice(this.orders);
    },
    transformPrice(orders) {
      orders.map(item => {
        item.products_slice.map(product => {
          if (product.total_price) {
            const price = parseFloat(product.total_price).toFixed(2);
            const formattedNumber = price.toString().replace('.', ',');
            return (product.price = formattedNumber);
          } else {
            const price = parseFloat(product.price).toFixed(2);
            const formattedNumber = price.toString().replace('.', ',');
            return (product.price = formattedNumber);
          }
        });
      });
    },
    limitText(text, maxLength) {
      if (text.length > maxLength) {
        return text.substring(0, maxLength) + '...';
      }
      return text;
    },
    orderStatus(orders){
        if(orders === "top-border-gray") return 'default';
        if(orders === "top-border-success") return 'success';
        if(orders === "top-border-error") return 'error';  
    },
  },
  mounted() {
  },
});

initVue(vm);
