import {OrderUpdateOperation} from "$utils/control/order/const/operation";
import {FlatListReload} from "$components/flat-list/const";
import {OrderPayStatus} from "$utils/control/order/const/order";

import orderControl from "$utils/control/order";

export default <LibMixins>{

    data(){
      return {
          flatListRefName:'flat'
      }
    },

    methods:{

        updateOrder(data:Record<string, any>){
            if (data.type === OrderUpdateOperation.delete) {
                return this.$refs[this.flatListRefName] && this.$refs[this.flatListRefName].flat_delete(data.id);
            } else if (data.type === OrderUpdateOperation.update) {
                return this.$refs[this.flatListRefName] && this.$refs[this.flatListRefName].flat_update(data.id,this.setUpdateOrderStatus(data.item,data.status));
            } else if (data.type === OrderUpdateOperation.add) {
                return this.$refs[this.flatListRefName] && this.$refs[this.flatListRefName].flat_unshift(data.id,this.setUpdateOrderStatus(data.item,data.status));
            }else if (data.type === OrderUpdateOperation.reload) {
                return this.$refs[this.flatListRefName] && this.$refs[this.flatListRefName].reload(FlatListReload.start);
            }
        },

        setUpdateOrderStatus(item,status:OrderPayStatus){
            item = JSON.parse(JSON.stringify(item));
            item.buttonGroup = orderControl.getButtonGroup(status,this.orderStatus);
            item.statusName = orderControl.getStatusName(status,this.orderStatus);

            return item;
        }

    }

}