import React from "react"; // import { message } from "@whalecloud/fdx";

import { getPlugin, getPlugins } from "../index";

var PluginComponent = function PluginComponent(props) {
  return props.children;
};

var PluginsComponent = function PluginsComponent(props) {
  return props.children;
};

export var renderPlugin = function renderPlugin(name) {
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  var _options$wrapper = options.wrapper,
      wrapper = _options$wrapper === void 0 ? true : _options$wrapper,
      _options$fn = options.fn,
      fn = _options$fn === void 0 ? "render" : _options$fn;
  var plugin = getPlugin(name); // message.warning(`${plugin}, No such plugin "${name}"`);

  if (!plugin) {
    return null;
  }

  var content = plugin[fn](params);

  if (content) {
    return wrapper ? /*#__PURE__*/React.createElement(PluginComponent, {
      key: plugin.name,
      name: name,
      params: params,
      fn: fn
    }, content) : /*#__PURE__*/React.cloneElement(content, {
      key: plugin.name
    });
  }

  return null;
};
export var renderPlugins = function renderPlugins(type) {
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  var _options$wrapper2 = options.wrapper,
      wrapper = _options$wrapper2 === void 0 ? true : _options$wrapper2,
      _options$fn2 = options.fn,
      fn = _options$fn2 === void 0 ? "render" : _options$fn2,
      _options$filter = options.filter,
      filter = _options$filter === void 0 ? function (v) {
    return v;
  } : _options$filter;
  var content = getPlugins(type).filter(filter).map(function (plugin) {
    return renderPlugin(plugin.name, params, {
      wrapper: wrapper,
      fn: fn
    });
  });
  return wrapper ? /*#__PURE__*/React.createElement(PluginsComponent, {
    type: type,
    params: params,
    fn: fn
  }, content) : content;
};
//# sourceMappingURL=index.js.map