import { getMonoid as getMonoidArray, map } from "fp-ts-esm/Array";
import { pipe } from "fp-ts-esm/function";
import { fold, struct } from "fp-ts-esm/Monoid";
import { getMonoid as getMonoidRecord } from "fp-ts-esm/Record";
import { last } from "fp-ts-esm/Semigroup";
import lodash from "lodash";
const recordMergeM = () => getMonoidRecord(last());
const nodeViewRenderersMergeM = () => getMonoidRecord(last());
const rcvPropM = struct({
  config: recordMergeM(),
  typeMappers: getMonoidArray(),
  nodeViewDecorators: getMonoidArray(),
  // @ts-ignore $TSFixMe
  nodeViewRenderers: nodeViewRenderersMergeM()
});
const extractChildRCVPluginProps = ({
  config = {},
  typeMappers = [],
  nodeViewRenderers,
  nodeViewDecorators
}) => ({
  config,
  typeMappers,
  nodeViewRenderers,
  nodeViewDecorators
});
const toRCVPluginProps = () => (plugin) => {
  const pluginProps = {
    config: { [plugin.type]: plugin.config },
    typeMappers: [],
    nodeViewRenderers: {},
    nodeViewDecorators: []
  };
  if (plugin.nodeViewRenderers) {
    pluginProps.nodeViewRenderers = plugin.nodeViewRenderers;
  } else if (plugin.typeMapper) {
    pluginProps.typeMappers = [plugin.typeMapper];
  }
  pluginProps.nodeViewDecorators = plugin.nodeViewDecorators ? plugin.nodeViewDecorators : [];
  return pluginProps;
};
const mergeWithChildProps = (childPluginProps) => (pluginProps) => lodash.merge({}, pluginProps, childPluginProps);
function pluginsStrategy({
  plugins = [],
  viewerProps
}) {
  return pipe(
    plugins,
    map(toRCVPluginProps()),
    fold(rcvPropM),
    mergeWithChildProps(extractChildRCVPluginProps(viewerProps))
  );
}
export {
  pluginsStrategy
};
//# sourceMappingURL=plugins-strategy.js.map
