"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getAllowedPostCssPlugins = getAllowedPostCssPlugins;
exports.postcssPluginGetter = postcssPluginGetter;

var _filterPluginsAllowedForSpecficFile = require("./filterPluginsAllowedForSpecficFile");

function getAllowedPostCssPlugins(filename, enabledPlugins, enabledCustomPlugins) {
  const neededPostCssPlugins = (0, _filterPluginsAllowedForSpecficFile.filterPluginsAllowedForSpecificFile)(enabledPlugins, filename);
  const neededCustomPlugins = (0, _filterPluginsAllowedForSpecficFile.filterCustomPluginsAllowedForSpecificFile)(enabledCustomPlugins, filename);
  return {
    plugins: [...neededPostCssPlugins, ...neededCustomPlugins]
  };
}

function postcssPluginGetter(options) {
  const pluginsOptions = options.css.plugins;
  const {
    customPlugins = []
  } = options.css;
  const enabledPlugins = (0, _filterPluginsAllowedForSpecficFile.getEnabledPlugins)(pluginsOptions);
  const enabledCustomPlugins = customPlugins.filter(conf => conf.enable);
  return filename => {
    const allowedPostCssPlugins = getAllowedPostCssPlugins(filename, enabledPlugins, enabledCustomPlugins);
    return allowedPostCssPlugins;
  };
}