import _extends from "@babel/runtime/helpers/esm/extends";
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
var _MapFuns = {
  toOption: function toOption(options) {
    var _this = this;
    // include exclude同时存在时只生效include
    if (options !== null && options !== void 0 && options.include) {
      _this = _this.filter(function (v) {
        var _options$include;
        return options === null || options === void 0 ? void 0 : (_options$include = options.include) === null || _options$include === void 0 ? void 0 : _options$include.includes(v.id);
      });
    } else if (options !== null && options !== void 0 && options.exclude) {
      _this = _this.filter(function (v) {
        var _options$exclude;
        return !(options !== null && options !== void 0 && (_options$exclude = options.exclude) !== null && _options$exclude !== void 0 && _options$exclude.includes(v.id));
      });
    }
    return _this.map(function (v) {
      return {
        value: v.id,
        label: v.name
      };
    });
  },
  findById: function findById(id) {
    var _this$filter = this.filter(function (v) {
        return v.id === id;
      }),
      _this$filter2 = _slicedToArray(_this$filter, 1),
      res = _this$filter2[0];
    return res;
  },
  findByName: function findByName(name) {
    var _this$filter3 = this.filter(function (v) {
        return v.name === name;
      }),
      _this$filter4 = _slicedToArray(_this$filter3, 1),
      res = _this$filter4[0];
    return res;
  },
  getName: function getName(id) {
    var _this$filter5 = this.filter(function (v) {
        return v.id === id;
      }),
      _this$filter6 = _slicedToArray(_this$filter5, 1),
      res = _this$filter6[0];
    return res === null || res === void 0 ? void 0 : res.name;
  },
  getId: function getId(name) {
    var _this$filter7 = this.filter(function (v) {
        return v.name === name;
      }),
      _this$filter8 = _slicedToArray(_this$filter7, 1),
      res = _this$filter8[0];
    return res === null || res === void 0 ? void 0 : res.id;
  }
};
var CreateEnumMap = function CreateEnumMap(data) {
  var _data = _toConsumableArray(data);
  var proto = Object.getPrototypeOf(data);
  var _obj = Object.create(proto);
  _extends(_obj, _MapFuns);
  Object.setPrototypeOf(_data, _obj);
  return _data;
};
export default CreateEnumMap;