"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const XEUtils = require("xe-utils");
const log = require("./log.js");
const storeMap = {};
const interceptor = {
  mixin(options) {
    XEUtils.each(options, (render, type) => {
      interceptor.add(type, render);
    });
    return interceptor;
  },
  get(type) {
    if (type) {
      return storeMap[type] || [];
    }
    return [];
  },
  add(type, render) {
    if (XEUtils.isFunction(render)) {
      render = {
        tableInterceptorMethod: render
      };
    }
    const callback = render.tableInterceptorMethod;
    if (callback) {
      let eList = storeMap[type];
      if (!eList) {
        eList = storeMap[type] = [];
      }
      if (eList.indexOf(callback) > -1) {
        log.log.warn("vxe.error.coverProp", ["Interceptor", type]);
      }
      eList.push(callback);
    }
    return interceptor;
  },
  delete(type, render) {
    const eList = storeMap[type];
    if (eList) {
      if (XEUtils.isFunction(render)) {
        render = {
          tableInterceptorMethod: render
        };
      }
      const callback = render ? render.tableInterceptorMethod : null;
      if (callback) {
        XEUtils.remove(eList, (fn) => fn === callback);
      } else {
        delete storeMap[type];
      }
    }
  }
};
exports.interceptor = interceptor;
