import statuses from "./config";

let modules = {};
modules = {
  props: {
    value: {
      type: [Number, String, Boolean],
    },
    param: {
      type: Array,
      default: () => [],
    },
    statusType: {
      type: String,
      default: () => "common",
    },
    successLabel: String,
    errorLabel: String,
  },
  computed: {
    statusMap() {
      let dataMap = this.dataMap;
      let statusMap = dataMap[this.value] || {};
      return statusMap;
    },
  },
  data() {
    return {
      dataMap: {type: ""}
    };
  },
  created() {
    this.init();
  },
  methods: {
    getLabel(item) {
      if (item.i18nPath) {
        return this.$t2(item.label, item.i18nPath)
      } else {
        return item.label;
      }
    },
    init() {
      let map = {};
      statuses[this.statusType].forEach((item) => {
        map[item.value] = item;
      });

      let param = this.param || [];
      param.forEach((item) => {
        map[item.value] = item;
      });

      if (this.successLabel) {
        map[true].label = this.successLabel;
      }
      if (this.errorLabel) {
        map[false].label = this.errorLabel;
      }

      this.dataMap = this.$baseLodash.cloneDeep(map);
    },
    getShowLabel(){
      let dataMap = this.dataMap;
      let statusMap = dataMap[this.value] || {};
      return this.getLabel(this.statusMap)
    }
  },
};
export default modules;
